CXF java.net.SocketTimeoutException: Read timed out

This exception happens, when invoking the client and it takes 50-60 seconds after that  we get java.net.SocketTimeoutException: Read timed out, following are the stacktrace

Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage
(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:171)
... 26 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)

This article explains about how to fix this exception in CXF way

Note

For running this client you need to refer the classes created on CXF Web Service Tutorial. This client is created for above service.

Required Libraries

You need to download following libraries in order to Generate CXF Client

  1. JDK 6
  2. Eclipse 3.7
  3. CXF-2.7.3
  4. Tomcat 7 (Deploying Web Service)

Following jar must be in classpath

  1. commons-logging-1.1.1.jar
  2. cxf-2.7.3.jar
  3. httpasyncclient-4.0-beta3.jar
  4. httpclient-4.2.1.jar
  5. httpcore-4.2.2.jar
  6. httpcore-nio-4.2.2.jar
  7. neethi-3.0.2.jar
  8. spring-aop-3.0.7.RELEASE.jar
  9. spring-asm-3.0.7.RELEASE.jar
  10. spring-beans-3.0.7.RELEASE.jar
  11. spring-context-3.0.7.RELEASE.jar
  12. spring-core-3.0.7.RELEASE.jar
  13. spring-expression-3.0.7.RELEASE.jar
  14. spring-web-3.0.7.RELEASE.jar
  15. wsdl4j-1.6.2.jar
  16. xmlschema-core-2.0.3.jar

Fix java.net.SocketTimeoutException: Read timed out exception

You can use HTTPConduit and HTTPClientPolicy and need to set ConnectionTimeout and ReceiveTimeout when invoking the service, please see the below code

Note

Here we are using CXF's JaxWsProxyFactoryBean, if you need to set timeout in JAX-WS way, you can set request timeout on request context property. See the code below
java.util.Map requestContext =((javax.xml.ws.BindingProvider) port).getRequestContext();
requestContext.put(com.sun.xml.internal.ws.request.timeout, new Long(600000));

1 2 Next





Your email address will not be published. Required fields are marked *