Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apache cxf could not send message and read time out

What might be the cause of:

org.apache.cxf.interceptor.Fault: Could not send Message.

Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking https://xxx.xxx.xxx.xxx:8443/services/test: Read timed out

It usually occurs after I send a soap request to the ws. I'm using apache cxf. I'm completely sure that the ws is up and running because before the time out occur the client will send 2 more request. The timeout happens in the third soap request.

like image 490
irumi Avatar asked Jan 31 '13 10:01

irumi


3 Answers

I have encountered this error as well for my webservice client. The solution that worked for me is to configure the http client in the CXF config file (cxf.xml).

As documented in Apache CXF document:

1.Add the http-conduit namespace and xsd:

<beans ...
       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration
       ...
       xsi:schemaLocation="...
           http://cxf.apache.org/transports/http/configuration
           http://cxf.apache.org/schemas/configuration/http-conf.xsd
       ...">

2.Add the http-conduit tag/element and set the ReceiveTimeout/ConnectionTimeout to 300000 ms:

<http-conf:conduit name="*.http-conduit">
      <http-conf:client 
                      ConnectionTimeout="300000"
                      ReceiveTimeout="300000"/>       
</http-conf:conduit>
like image 58
Carlos Jaime C. De Leon Avatar answered Nov 18 '22 06:11

Carlos Jaime C. De Leon


The error message means that your web service client was trying to receive data from a remote web service over the network, but no data was received for a specific period of time, so the web service client stopped waiting for the data to be received.

One of the possible causes might be that the timeout property is too low. Defaults to cxf default values of 30000 and 60000 ms respectively. These can be changed depending how you are creating your client.

If you are creating a client using java code you can use:

//1 minute for connection
((BindingProvider) wsPort).getRequestContext().put("com.sun.xml.ws.connect.timeout", 1 * 60 * 1000); 

//3 minutes for request
((BindingProvider) wsPort).getRequestContext().put("com.sun.xml.ws.request.timeout", 3 * 60 * 1000); 

If you are using Spring, you can use a map like this:

<util:map id="jaxwsProperties">
    <entry key="com.sun.xml.internal.ws.request.timeout">
        <value type="java.lang.Integer">120000</value>
    </entry>
    <entry key="com.sun.xml.internal.ws.connect.timeout">
        <value type="java.lang.Integer">60000</value>
    </entry>
</util:map>

Then set that map into your <jaxws:client.../> configuration.

like image 14
Paulius Matulionis Avatar answered Nov 18 '22 06:11

Paulius Matulionis


Another approche to config timeouts (programmatically):

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
Object serviceClass = factory.create();
defineTimeouts(serviceClass);

static void defineTimeouts(Object serviceClass) {
    Client cxfClient = ClientProxy.getClient(serviceClass);
    HTTPConduit httpConduit = (HTTPConduit) cxfClient.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
    httpClientPolicy.setConnectionTimeout(DEFAULT_CLIENT_CONNECTION_TIMEOUT);
    httpClientPolicy.setReceiveTimeout(DEFAULT_CLIENT_RECEIVE_TIMEOUT);
    httpConduit.setClient(httpClientPolicy);
}
like image 4
Bob Rivers Avatar answered Nov 18 '22 06:11

Bob Rivers