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...
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...
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...
//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.


A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.