Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

Connect and read timeout settings for webservice clients are not standardised across different versions of the JDK, nor the application containers like WebLogic, JBoss, Glassfish, etc. So when it comes to setting these values correctly for your specific environment, you can get stuck in a cycle of trying all known properties until one works. This is what I had to do recently.

There actually is an Oracle Support Note that talks about this - How to set Timeout for Weblogic Webservice Client(jaxws and jaxrpc) (Doc ID 1056121.1). This note is a little old and references some JAR files that no longer exist, so I didn't quite get the answer I was looking for here but it set me on the right path.

Lets see what the documented portable way of setting timeouts is... You need to cast your port object to a BindingProvider and then retrieve the request context, which is a Java Map of key/value pairs. Then, you set the connect and read timeout properties to whatever values you wish to use - this is specified in milliseconds. For example...
 Java
Map requestContext = ((BindingProvider) port).getRequestContext();
requestContext.put(JAXWSProperties.CONNECT_TIMEOUT, 30000);
requestContext.put(JAXWSProperties.REQUEST_TIMEOUT, 30000);


Seems simple, right? Well it is, however it all depends on which JAXWSProperties class you import, which JDK you have and which application server you are running. This is where it gets difficult. I found that using the portable approach by setting properties from constant field values was not the best case. Due to the myriad of different property names out there that the same constant fields defined, I opted to use literal strings instead that I knew would work with WebLogic 12c...
 Java
Map requestContext = ((BindingProvider) port).getRequestContext();
requestContext.put("com.sun.xml.ws.connect.timeout", 30000);
requestContext.put("com.sun.xml.ws.request.timeout", 30000);


That worked like a charm. I know it's not the cleanest way to do it, but it works very well in this case.



Here are a bunch of other property names that I've tried that had no effect...
 Java
//requestContext.put("com.sun.xml.internal.ws.connect.timeout", 10);
//requestContext.put("com.sun.xml.internal.ws.request.timeout", 10);
//requestContext.put("oracle.webservices.httpReadTimeout", 10);
//requestContext.put("oracle.webservices.httpConnTimeout", 10);
//requestContext.put("javax.xml.ws.client.connectionTimeout", 10);
//requestContext.put("javax.xml.ws.client.receiveTimeout", 10);


By the way there's an open ticket over at the metro-jax-ws Git repository to address this very issue with not having a standardised set of properties - Standardize timeout settings #1166. This ticket was opened in 2015 and hasn't seen much traction.

-i

Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...