How to Set the Timeout for a Jax-Ws Webservice Client

How do I set the timeout for a JAX-WS webservice client?

I know this is old and answered elsewhere but hopefully this closes this down. I'm not sure why you would want to download the WSDL dynamically but the system properties:

sun.net.client.defaultConnectTimeout (default: -1 (forever))
sun.net.client.defaultReadTimeout (default: -1 (forever))

should apply to all reads and connects using HttpURLConnection which JAX-WS uses. This should solve your problem if you are getting the WSDL from a remote location - but a file on your local disk is probably better!

Next, if you want to set timeouts for specific services, once you've created your proxy you need to cast it to a BindingProvider (which you know already), get the request context and set your properties. The online JAX-WS documentation is wrong, these are the correct property names (well, they work for me).

MyInterface myInterface = new MyInterfaceService().getMyInterfaceSOAP();
Map<String, Object> requestContext = ((BindingProvider)myInterface).getRequestContext();
requestContext.put(BindingProviderProperties.REQUEST_TIMEOUT, 3000); // Timeout in millis
requestContext.put(BindingProviderProperties.CONNECT_TIMEOUT, 1000); // Timeout in millis
myInterface.callMyRemoteMethodWith(myParameter);

Of course, this is a horrible way to do things, I would create a nice factory for producing these binding providers that can be injected with the timeouts you want.

Java SOAP/JAX-WS: How to set timeouts?

Using the JDK JAX-WS implementation you probably should set the internal properties

 ((BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", timeout);
((BindingProvider) port).getRequestContext().put("com.sun.xml.internal.ws.request.timeout", timeout);

Please upvote my JIRA issue to standardize this in an upcoming version of JAX-WS
https://java.net/jira/browse/JAX_WS-1166

default timeout for JAX-WS client

Default value is 30 seconds for connection timeout and 60 seconds for receive timeout.

See: http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport(includingSSLsupport)-Theclientelement

Cannot set custom timeout on JAX-WS Eclipse generated client

this is the way i set endpoint, basic-auth and timeout. this code only differs from yours in the way you get the instance of the "service".

import com.sun.xml.ws.developer.JAXWSProperties;
import java.net.URL;
import javax.xml.ws.BindingProvider;

public void foo(Object service) {
if (service instanceof BindingProvider) {
BindingProvider bp = (BindingProvider)service;
Map<String, Object> ctx = bp.getRequestContext();
ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, new URL("http://localhost/url-to-endpoint"));
ctx.put(JAXWSProperties.CONNECT_TIMEOUT, 10000);
ctx.put(JAXWSProperties.REQUEST_TIMEOUT, 60000);
ctx.put(BindingProvider.USERNAME_PROPERTY, "auth_user");
ctx.put(BindingProvider.PASSWORD_PROPERTY, "auth_password");
}
}

How to set JAX-WS client timeout?

I did the following steps and fixed the problem:

  1. Upgraded jbossws-native library, follow this link.

    jbossws-native-3.4.0 is the latest supported version for Jboss 5.1.0GA. You can see JBossWS - Supported Target Containers

  2. Used StubExt.PROPERTY_CLIENT_TIMEOUT

    int timeoutMillisecond=3000;
    bp.getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, timeoutMillisecond);

By the way, in this version StubExt.PROPERTY_CONNECTION_TIMEOUT also works correctly.



Related Topics



Leave a reply



Submit