CXF Read timed out

This exception happens, when invoking the client and it takes 50-60 seconds after that  we get 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
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(
at org.apache.cxf.endpoint.ClientImpl.invoke(
at org.apache.cxf.endpoint.ClientImpl.invoke(
at org.apache.cxf.frontend.ClientProxy.invokeSync(
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(
... 26 more
Caused by: Read timed out
at Method)

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


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. OpenJDK 8 / Corretto
  2. Eclipse 4.15
  3. CXF-3.3.6
  4. Tomcat 9

Following jar must be in classpath

  1. cxf-core-3.3.6.jar
  2. cxf-rt-bindings-soap-3.3.6.jar
  3. cxf-rt-databinding-jaxb-3.3.6.jar
  4. cxf-rt-features-logging-3.3.6.jar
  5. cxf-rt-frontend-jaxws-3.3.6.jar
  6. cxf-rt-frontend-simple-3.3.6.jar
  7. cxf-rt-transports-http-3.3.6.jar
  8. cxf-rt-wsdl-3.3.6.jar
  9. httpasyncclient-4.1.4.jar
  10. httpclient-4.5.12.jar
  11. httpcore-4.4.13.jar
  12. httpcore-nio-4.4.13.jar
  13. neethi-3.1.1.jar
  14. slf4j-api-1.7.29.jar
  15. slf4j-jdk14-1.7.29.jar
  16. spring-aop-5.1.14.RELEASE.jar
  17. spring-beans-5.1.14.RELEASE.jar
  18. spring-context-5.1.14.RELEASE.jar
  19. spring-core-5.1.14.RELEASE.jar
  20. spring-expression-5.1.14.RELEASE.jar
  21. spring-jcl-5.1.14.RELEASE.jar
  22. spring-web-5.1.14.RELEASE.jar
  23. stax2-api-3.1.4.jar
  24. woodstox-core-5.0.3.jar
  25. wsdl4j-1.6.3.jar
  26. xmlschema-core-2.2.5.jar

Fix 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


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 =(( port).getRequestContext();
requestContext.put(, new Long(600000));

Run Client

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import com.student.ChangeStudentDetails;
import com.student.Student;

// How to handle Read timed out exception

public final class StudentClient {

public static void main(String args[]) throws Exception {

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
long timeout = 10000L;

factory.getInInterceptors().add(new LoggingInInterceptor());
().add(new LoggingOutInterceptor());
      ChangeStudentDetails ChangeStudentService =
(ChangeStudentDetails) factory.create();
      Client client = ClientProxy.getClient
if (client != null) {
HTTPConduit conduit = (HTTPConduit) client.getConduit();
          HTTPClientPolicy policy =
new HTTPClientPolicy();
Student student = new Student();
      Student changeName = ChangeStudentService.changeName
(Server said:  + changeName.getName());

Server said: Hello Rockey

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