CXF not honoring the Keep Alive connections

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CXF not honoring the Keep Alive connections

mvraju
This post was updated on .
Hi,
I am using CXF 3.1.10 version to create / consume the REST APIs and noticing an issue with the SSL Keep Alive connections. I've tried using the Async implementation and ran into few issues which I've shared in another post. When we are using the CXF Client libraries for some reason JDK's HTTP URL openConnection is creating a new connection object for every request. I am seeing server is responding with Keep Alive and the corresponding time out configurations. Is there any configuration / setup that I am missing to keep the connections in the JDK default implementation?

Please advise.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
Can someone please shed some light on this? It is currently blocking me moving further.

Thanks In Advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

Dennis Kieselhorst-2
Hi,

please share your current configuration with us.

Details about the possibilities are documented here: http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html

Regards
Dennis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
This post was updated on .
Thanks for the response Dennis, below is my configurations -

Both REST client & service uses the below CXF libraries of version 3.1.10 with all the logging interceptors -

1. cxf-rt-frontend-jaxrs
2. cxf-rt-rs-service-description
3. cxf-rt-rs-client

I also just created a sample test scenario by making use of Javax.net package and I do see JDK is honoring the Keep Alive connections. I am not really sure if there is something am missing from the CXF libraries.

I have also enabled the http-conduits Keep-Alive connection in my configuration file and loading the pfx certs through the System properties.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
This post was updated on .
Here is my CXF RS Client Configuration -

<http:conduit name="*.http-conduit">
                <http:client ConnectionTimeout="${rs.service.connection.timeout}" ReceiveTimeout="${rs.service.connection.read.timeout}" Connection="Keep-Alive"/>
        </http:conduit>

<cxf:rsClient id="rsClient"
                address="${rs.service.url}"
                inheritHeaders="true">
                <cxf:providers>
                        <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"></bean>
                </cxf:providers>
                <cxf:properties>
                        <entry key="fullStackTraceEnabled" value="true"></entry>
                </cxf:properties>
                <cxf:features>
                        <ref bean="logFeature" />
                </cxf:features>
        </cxf:rsClient>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

Dennis Kieselhorst-2
In reply to this post by mvraju

> I also just created a sample test scenario by making use of Javax.net
> package and I do see JDK is honoring the Keep Alive connections. I am not
> really sure if there is something am missing from the CXF libraries.

For the client config Keep-Alive is active by default and the connection factory is cached in org.apache.cxf.transport.https.HttpsURLConnectionFactory so this should be fine.

Which kind of server are you using?

I would enable logging on the client side to debug http traffic (or use tools like Wireshark) to see what's going on with the connections.

Cheers
Dennis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
This post was updated on .
Tomcat Server Dennis. I did configure the KeepAliveTimeout configurations in the server connector, keepAlive system properties for JRE. It did not work. Tried with a simple webclient call and noticed, CXF is creating new connections for every request and below is the code snippet -

JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
bean.setAddress("https://<url>");
bean.setProperties(Collections.singletonMap(
                                org.apache.cxf.message.Message.MTOM_ENABLED, (Object) "true"));
WebClient client = bean.createWebClient();
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
conduit.getClient().setReceiveTimeout(45000);
conduit.getClient().setConnectionTimeout(45000);
conduit.getClient().setConnection(ConnectionType.KEEP_ALIVE);
Response response = client.get();
System.out.println(response.getStatus());

I did a netstat in the server with the above code and noticed new TCP connections are getting created for every request. Looks like something I'm missing in the above code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
A simple http test call is perfectly working fine by reusing the connections.

I'm trying to debug the CXF code and tried with different other options but getting hopelessly lost at present. Any help on this would be greatly appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
Can someone please provide some inputs on this issue? Any configurations that I'm missing here to tell CXF wrappers to make use of the keep alive connections. Same code is working when I integrate with the simple URL HttpConnection JDK API.  Appreciate any inputs on this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

Daniel  Kulp
Administrator

> On Jun 28, 2017, at 7:25 PM, mvraju <[hidden email]> wrote:
>
> Can someone please provide some inputs on this issue? Any configurations that
> I'm missing here to tell CXF wrappers to make use of the keep alive
> connections. Same code is working when I integrate with the simple URL
> HttpConnection JDK API.  Appreciate any inputs on this.

Is your test code actually consuming the data from the response or just printing the status code?    If you don’t consume the data (and close the stream), the underlying connection cannot be reused.   That’s usually the primary reason for this type of behavior.

--
Daniel Kulp
[hidden email] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: CXF not honoring the Keep Alive connections

mvraju
Hi Daniel,
In the test code I just tried with capturing the response code. But with the actual implementation, I am also consuming the response. One thing I noticed while I am debugging the with the HttpsURLConnectionFactory class it is looking for flags like useHttpsURLConnectionDefaultSslSocketFactory or any sslFactory instance on the tls parameters. After setting the default flag in the HttpConduit tlsClientParameters configuration I can see the TCP connections are getting reused.

Thanks
Loading...