changing client timeout for a particular request in Apache CXF - java

I have to set a different timeout in Apache cxf request based on some condition in my request
my current code looks like this
<http-conf:client ReceiveTimeout="120000" AcceptEncoding="gzip, deflate"/>
Now is there any way to change this receive timeout for a particular request based on some condition.

Current we don't provide this kind of setting in CXF.
If you still want to do that, you can get the HttpConduit from the CXF client proxy and set the HTTPClientPolicy directly to the HttpConduit.
// Get the HttpConduit
HttpConduit httpConduit = (HttpConduit) ClientProxy.getClient(greeter).getConduit();
// Set your custom HTTPClientPolicy directly to the httpConduit
httpConduit.setHTTPClientPolicy(httpClientPolicy);
In this way, you can update the timeout before sending the request to the server.

Related

Jersey Client Request Takes Too Long To Reach Server

In a JavaFx client application, jersey client 2 is used to send request to the server to fetch data. I control both server and client applications.
The time it takes from when client execute .get() to when server receive the request is not less than 8seconds. That is alot of time considering the request has just 2 path variable.
Spring framework is used for a dependency injection, and i have this in configuration file
#Bean
public WebTarget webTarget(){
ClientConfig config = new ClientConfig();
config.register(new JacksonJsonProvider());
final Client client = ClientBuilder.newClient(config);
client.register(new LoggingFilter());
return client.target(getBaseUri());
}
Then anywhere in service layer request to server needs to be made, a Webtarge is Autowired and additional request specific info is added like path and request variables.
What should i do to make request time(from start of request to server receiving request -- in localhost) minimal?
Update
When the same request with is made using Postman, request-response time is 2secs.

Set timeout for web service request in apache cxf

I am working on the integration testcases, as part of that different testcase i have set http timeout for a request means i would like to issue the http request to server but timeout should happen from client side before it receives the request. Since i am using CXF, i have changed as according the solution provided in official site,
How to configure the HTTPConduit for the SOAP Client?
I already a question exists,
changing client timeout for a particular request in Apache CXF
My problem,
I have java classes generated from cxf codegen plugin, where a interface is generated which has all the soap web service operations.
URL wsdl = getClass().getResource("wsdl/CustomerService_1.wsdl");
QName serviceName = new QName("srv.retail.app:ws:customer:1", "CustomerService_1");
QName portName =
new QName("srv.retail.app:ws:customer:1", "CustomerService_1PortTypeSoap11");
CustomerService_1 service = new CustomerService_1(wsdl, serviceName);
CustomerService1PortType customerServicePortType = service.getPort(portName, CustomerService1PortType.class);
Client client = ClientProxy.getClient(customerServicePortType);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(36000);
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(300);
http.setClient(httpClientPolicy);
Tried different ways those are not working, will be great if you give inputs on this.

Does OkHttp3 support HTTP2 via a HTTP forward proxy?

I am using OkHttp3 in my Android app to make HTTP/1.x requests to my backend servers via a forward proxy, like so:
List<Protocol> protos = new ArrayList<>();
protos.add(Protocol.HTTP_2);
protos.add(Protocol.HTTP_1_1);
InetSocketAddress proxyAddr = new InetSocketAddress("proxy.example.com", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddr);
OkHttpClient cli = new OkHttpClient.Builder()
.proxy(proxy)
.protocols(protos)
.build();
String url = "http://www.example.com/";
Request req = new Request.Builder().url(url).build();
Response res = cli.newCall(req).execute();
I would like to upgrade to HTTP2. However, it seems to me that OkHttp3 can make HTTP2 requests only if we are not going via a HTTP proxy. So, the above code wouldn't work.
In other words, OkHttp3 supports the first 3 cases below but not the fourth. HTTP/2 below means h2 (HTTP/2 over TLS) not h2c (HTTP/2 over clear text).
a) client <-- HTTP/1.x --> upstream server
b) client <-- HTTP/1.x --> forward proxy <-- HTTP/x --> upstream server
c) client <-- HTTP/2 --> upstream server
d) client <-- HTTP/2 --> forward proxy <-- HTTP/x --> upstream server
Does anyone confirm or deny my understanding? Thanks.
OkHttp will do HTTP/2 over an HTTP proxy. You’ll need HTTPS on the server since OkHttp doesn’t implement plaintext HTTP/2.
Jesse, I tried retrieving https://www.google.com/ with Proxy.Type.HTTP via nghttp2's forward proxy nghttpx, which supports HTTP2 over TLS. Unfortunately, TLS handshaking did not happen and the forward proxy reported the following error.
... tls: handshake libssl error: error:1407609B:SSL routines:SSL23_GET_CLIENT_HELLO:https proxy request
From what I gather, this error means that okhttp3's proxy code is not doing TLS handshaking with the forward proxy.
This makes me think that HTTP2 over TLS via a forward proxy is kind of pointless, because the forward proxy won't be able to add any value to encrypted requests - the forward proxy is just a pass-through pipe. In fact, I think TLS via any forward proxy is pointless. End-to-end HTTP2 over TLS does make sense, but via a forward proxy doesn't.

Apache CXF timeout not working on peak traffic

I have some trouble trying to find root cause on why soap call timeout is being ignored at times. I also can't replicate it locally.
It only happens on production server during peak hours/heavy load. Timeout is working off-peak hours.
Below is how timeout out is being setup on code
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(serviceClass);
factory.setAddress(address);
Object object = factory.create();
Client client = ClientProxy.getClient(object);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setReceiveTimeout(10000);
httpClientPolicy.setConnectionTimeout(25000);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
Apache cxf 2.2.5 is the library being used.
Updating library might not be an option as this is an old project and updating might break or bring more problems as is.
Any ideas?

Moving from a web service from HTTP to HTTPS

I have a web service on one server and a Java client on another. Currently all calls are being made over HTTP but I would like the service to be more secure with HTTPS and basic authentication, I only want my client to be able to make calls. My web server receiving the requests is Apache httpd.
I've set up directives in the apache conf as follows:
<Location /mypath>
Order Deny,Allow
Deny from all
Allow from all
AuthType Basic
AuthName "My Web Service Login"
AuthBasicProvider file
AuthUserFile "/usr1/apache/passwd/passwords"
Require user myuser
</Location>
The passwords file has only one entry, for myuser
<IfModule ssl_module>
ServerName www.myserver.com
SSLEngine on
SSLCACertificateFile "/usr1/apache/conf/ssl/myCAList.pem"
SSLCertificateFile "/usr1/apache/conf/ssl/myserver.crt"
SSLCertificateKeyFile "/usr1/apache/conf/ssl/myserver.pem"
SSLVerifyClient require
</IfModule>
I think I have the server set up correctly (posted just in case). However, I can't test this for another hour when I can safely restart apache.
What I need help with is I'm unsure of how to configure the client. Here is a simple example call (using httpclient 4.5.1) :
HttpClient client = HttpClient.createDefault();
HttpGet httpGet = new HttpGet(URI);
HttpResponse httpRes = client.execute(httpGet);
I know I need to specify https instead of http on the URI, but how do I
1) Send the username and password for the basic authentication
2) Make sure my client server trusts the certificate of the web service server
3) What certificates and such that I need on the client server for the SSL connection
Thank you!

Categories

Resources