Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've used JAXWS-RI 2.1 to create an interface for my web service, based on a WSDL. I can interact with the web service no problems, but haven't been able to specify a timeout for sending requests to the web service. If for some reason it does not respond the client just seems to spin it's wheels forever.

Hunting around has revealed that I should probably be trying to do something like this:

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

I also discovered that, depending on which version of JAXWS-RI you have, you may need to set these properties instead:

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

The problem I have is that, regardless of which of the above is correct, I don't know where I can do this. All I've got is a Service subclass that implements the auto-generated interface to the webservice and at the point that this is getting instanciated, if the WSDL is non-responsive then it's already too late to set the properties:

MyWebServiceSoap soap; MyWebService service = new MyWebService("http://www.google.com"); soap = service.getMyWebServiceSoap(); soap.sendRequestToMyWebService(); 

Can anyone point me in the right direction?!

like image 661
ninesided Avatar asked Jan 27 '10 17:01

ninesided


People also ask

How do I increase WebService timeout?

You can control the connection and socket timeout of the loading of the WSDL definition by setting enable-wsdl-discovery-timeouts . Use the value -1 to use the default of the underlying infrastructure. Use the value 0 to disable the timeouts. Use a positive integer to specify a timeout in milliseconds.

How do I test a JAX-WS web service?

A JAX-WS web service can be tested by using the Web Service Tester View displayed in Figure 7.1, “Web Service Test View”. The JAX-WS test is specified by: Selecting the JAX-WS combobox option. Entering the location of the WDSL file.

What is BindingProvider in Web service?

The BindingProvider interface provides access to the protocol binding and associated context objects for request and response message processing.


1 Answers

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.

like image 158
alpian Avatar answered Sep 30 '22 09:09

alpian