Code example illustrating a Java net SocketTimeoutException and its timeout handling

To ensure future socket usage, I recommend using a instead of initially, as it guarantees an open and connected socket. Next, handle any exceptions within the . Alternatively, you could handle the wait within the , but in that case, setting a socket timeout may be redundant since you are already using a separate thread for blocking mode. Additionally, I suggest making some adjustments to your code for better exception handling.


Question:

As stated in the WildFly Developer Guide (https://docs.wildfly.org/14/Developer_Guide.html), I utilized the following code to configure the timeout of my
WebService client
:
“””.

((BindingProvider) port).getRequestContext().put("javax.xml.ws.client.connectionTimeout", timeoutInMs);
((BindingProvider) port).getRequestContext().put("javax.xml.ws.client.receiveTimeout", timeoutInMs);

The solution was effective when my WebService client ran on a WildFly8 using jdk8. However, after migrating it to WildFly14/jdk11, this approach no longer functions. I experimented with various Map-keys, such as:

BindingProviderProperties.REQUEST_TIMEOUT
BindingProviderProperties.CONNECT_TIMEOUT
"com.sun.xml.ws.connect.timeout"
"com.sun.xml.ws.request.timeout"
"com.sun.xml.internal.ws.request.timeout"
"com.sun.xml.internal.ws.connect.timeout"

Additionally, the job could not be accomplished by setting the system properties “sun.net.client.defaultConnectTimeout” and “sun.net.client.defaultReadTimeout”.

After 1 minute, I consistently encounter ‘java.net.
sockettimeoutexception
‘. I am on the verge of abandoning my attempts.

Does anybody have any idea?

Regards, Robert



Solution:

I found a working solution:

Soap: Set TimeOut using WSDL2Java

In the given example, the code that is functional is:

final Client cl = ClientProxy.getClient(port);
final HTTPConduit httpConduit = (HTTPConduit) cl.getConduit();
final HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(timeoutInMs);
httpClientPolicy.setReceiveTimeout(timeoutInMs);
httpConduit.setClient(httpClientPolicy);

I found all the necessary libraries within the modules of my WildFly14 installation.

system/layers/base/org/apache/cxf/impl/main/
system/layers/base/org/apache/cxf/main/
system/layers/base/javax/xml/ws/api/main/
system/layers/base/org/jboss/ws/tools/common/main/

Frequently Asked Questions