CXF java.net.SocketTimeoutException: Read timed out

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
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
- OpenJDK 8 / Corretto
- Eclipse 4.15
- CXF-3.3.6
- Tomcat 9
Following jar must be in classpath
- cxf-core-3.3.6.jar
- cxf-rt-bindings-soap-3.3.6.jar
- cxf-rt-databinding-jaxb-3.3.6.jar
- cxf-rt-features-logging-3.3.6.jar
- cxf-rt-frontend-jaxws-3.3.6.jar
- cxf-rt-frontend-simple-3.3.6.jar
- cxf-rt-transports-http-3.3.6.jar
- cxf-rt-wsdl-3.3.6.jar
- httpasyncclient-4.1.4.jar
- httpclient-4.5.12.jar
- httpcore-4.4.13.jar
- httpcore-nio-4.4.13.jar
- neethi-3.1.1.jar
- slf4j-api-1.7.29.jar
- slf4j-jdk14-1.7.29.jar
- spring-aop-5.1.14.RELEASE.jar
- spring-beans-5.1.14.RELEASE.jar
- spring-context-5.1.14.RELEASE.jar
- spring-core-5.1.14.RELEASE.jar
- spring-expression-5.1.14.RELEASE.jar
- spring-jcl-5.1.14.RELEASE.jar
- spring-web-5.1.14.RELEASE.jar
- stax2-api-3.1.4.jar
- woodstox-core-5.0.3.jar
- wsdl4j-1.6.3.jar
- xmlschema-core-2.2.5.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
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));
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 java.net.SocketTimeoutException: Read timed out exception
public final class StudentClient <
public static void main ( String args []) throws Exception <
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean () ;
long timeout = 10000L ;
java.net.SocketTimeoutException: Read timed out under Tomcat
Server is trying to read data from the request, but its taking longer than the timeout value for the data to arrive from the client. Timeout here would typically be Tomcat connector → connectionTimeout attribute.
Client has a read timeout set, and server is taking longer than that to respond.
One of the threads I went through, said this can happen with high concurrency and if the keepalive is enabled.
For #1, the initial value I had set was 20 sec, I have bumped this up to 60sec, will test, and see if there are any changes.
Meanwhile, if any of you guys can provide you expert opinion on this, that’l be really helpful. Or for that matter any other reason you can think of which might cause this issue.
Java.Net.SocketTimeoutException: Read Timed Out Under Tomcat

Today’s tutorial will discuss potential reasons and solutions for the java.net.SocketTimeoutException: Read timed out under Tomcat in Java.
java.net.SocketTimeoutException: Read timed out
Please enable JavaScript
java.net.SocketTimeoutException: Read timed out occurs when the server attempts to read data from the request; however, it is taking far longer than the allowed amount of time for the data to arrive from the client. The timeout option can have a developer’s default value pre-set for client and server activities.
Causes of java.net.SocketTimeoutException: Read timed out
- The server is trying to read data from the request; however, it is taking significantly more than the specified amount of time for the data to arrive from the client. Timeout in this context is often represented by the tomcat connector -> connectionTimeout attribute .
- When there is a lot of concurrent activity, this error can occur if the keepalive feature is turned on.
- It occurs if no data arrives before the timeout expires.
- When the server has slow performance.
Solution to java.net.SocketTimeoutException: Read timed out
The modification of the .xml context file and the CONNECTOR definition, which controls the connectivity of the workstation browser to the Tomcat server, is one approach that might be taken to resolve this issue inside the context of the Tomcat web application.
To be more concise, adjust the value of the connectionTimeout property. Raising this value will prevent the error condition from occurring.
For example, we have the following .xml file containing the below data:
To disable the upload timeout and cancel the read-write connection timeout setting, we can add disableUploadTimeout= «false» .
We can also increase the connection lifespan by including the keepAliveTimeout= «200000» parameter.
I have been working as a Flutter app developer for a year now. Firebase and SQLite have been crucial in the development of my android apps. I have experience with C#, Windows Form Based C#, C, Java, PHP on WampServer, and HTML/CSS on MYSQL, and I have authored articles on their theory and issue solving. I’m a senior in an undergraduate program for a bachelor’s degree in Information Technology.
Jsoup SocketTimeoutException Read timed out Connect timed out fix
Jsoup SocketTimeoutException read timed out, connect timed out example shows how to fix SocketTimeoutException while using Jsoup in Java. The example also shows how to set the timeout in Jsoup.
How to fix Jsoup java.net.SocketTimeoutException: Read timed out exception?
You may encounter “java.net.SocketTimeoutException: Read timed out” exception while using the Jsoup. Here is the program which gave me the exception.
Fix:
The problem is the default Jsoup timeout which is 3 seconds. If you encounter the exception “java.net.SocketTimeoutException: Read timed out”, it means that time our program took to read the requested webpage was exceeded the default timeout time (3 seconds).
You need to increase the timeout Jsoup uses to fix the problem using timeout method of Connection class.
This method sets the connect and read timeout both. Please note that the timeout is in milliseconds.
How to fix Jsoup java.net.SocketTimeoutException: Connect timed out exception?
Another exception Jsoup may throw is “java.net.SocketTimeoutException: Connect timed out”. This exception means the time taken by our program to connect to the requested URL exceeded the timeout Jsoup uses.
Here is how to fix/resolve the “Connect time out” exception.
1) Make sure you are connected to the internet. Try to open the same URL in the browser and see if it opens the page.
2) Specify Jsoup connection time out before getting the document as given below.