0

I have a SOAP client generated with apache-cxf(v3.3.2). The client runs inside a Spring Boot application using embedded Tomcat.

How can I specify the keep-alive timeout for this SOAP client?

What I found so far:

The socket used for establishing the connection closes after 5s. This timeout is a hardcoded default in the underlying sun.net.www.http.HttpClient. It is not controlled by the tomcat connection-timeout or com.sun.xml.internal.ws.request.timeout properties. The HttpClient.keepAliveTimeout variable is set only if the Server responds with a Keep-Alive header (e.g. Keep-Alive: timeout=60, max=100 ): see line 752.

The server doesn't provide this header.

According to this answer this is the expected behaviour, but is it really:

The client cannot specify the timeout, it is the server configuration that determines the maximum timeout value. The extra Keep-Alive header can inform the client how long the server is willing to keep the connection open ...

Eugene
  • 1
  • 3

1 Answers1

1

Try setting it directly via HTTPClientPolicy. I use this in my CXF client.

        Client client = ClientProxy.getClient(port);

        HTTPConduit http = (HTTPConduit) client.getConduit();

        // Set connection timeout
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
        httpClientPolicy.setConnectionTimeout(30000);
        httpClientPolicy.setAllowChunking(false);
        httpClientPolicy.setReceiveTimeout(30000);

        http.setClient(httpClientPolicy);
robrides
  • 51
  • 4