Setting a JAX-WS web service client timeout – why is the answer so dang elusive??

Trying to set a connection/read timeout in a WS client… can’t and found this post? Welcome to the club.

Does ANYONE OUT THERE have a proven, easy to implement, somewhat universal way, to simple set connect and read timeouts for JAX-WS web-service clients? I can’t seem to find them, and neither can tons of others out there by the looks for dozens of posts/blogs I have read in forums etc.

This is one of the most insidious problems with an application. Timeouts, or the lack thereof causing a thread in your application to mysteriously (or not) hang up sitting there forever. Is my app deadlocked? Why is this thread hung? Then after a while your app’s thread pool may be exhausted etc leading to harder to diagnose and worthless artifact error symptoms being spewed into a log file.

In an enterprise app, one of the common things we do is use a web-service to send or receive data from some other application out there… and a lot of people use some sort of JAX-WS generated variant of clients.

Here is my question. HOW can I reliably set a jax-ws client timeout for both connect and read operations? I seem to see various answers to this, often time they don’t work for folks. Other times I suspect folks are getting confused with regards to the actual JAX-WS client implementation executing their code (jboss, glassfish, websphere etc).. and I guess these settings vary based on where you code is deployed, which is SUPER convenient because there is not abstract definition of this in the spec itself to allow developers to specify their timeouts in a portable way??

Hey Oracle: Why can’t Java just support a simple solution to this stupid time-wasting problem?? @see Axis clients and how easy it is to do there!


Here are some examples I’ve seen out there of threads that have random answers that often go unanswered.

10 thoughts on “Setting a JAX-WS web service client timeout – why is the answer so dang elusive??

  1. In IBM WebSphere Application Server (WAS), there are three ways to set the read-timeout in a jax-ws client: (This assumes you are using the IBM jax-ws implementation and your client is running in WAS)

    1.) (easiest, no code change, no JVM property to manage) Use a policy set

    2.) programitacally on the message context (MC)

    import; service= …; Printer myPrinterProxy = service.getPort(portName, Printer.class); bp = (;

    // Retrieve the request context for the BindingProvider object Map rc = myBindingProvider.getRequestContext(); rc.put(REQUEST_TIMEOUT_PROPERTY, 30); // 30 seconds

    3.) use the “timeout” JVM custom property. That’s correct, just “timeout”, without the quotes of course.


    Rules of precedence in WAS: Policy set -> MC -> JVM property -> then default

  2. Hi,

    the best answer I have found is the following, directly from redhat support:

    Timeout Configuration
    Two different properties control the timeout behavior of the HTTP connection and the timeout of a client which is waiting to receive a message. The first is and the second is Each is expressed in milliseconds, and the correct syntax is shown below.

    public void testConfigureTimeout() throws Exception
    //Set timeout until a connection is established
    ((BindingProvider)port).getRequestContext().put(“”, “6000”);

    //Set timeout until the response is received
    ((BindingProvider) port).getRequestContext().put(“”, “1000”);


    This is for EAP 6 and should also work for AS 7+
    Don’t know about other Application Servers

  3. Hi, for me worked this solution, but it is probably JBOSS only :
    (BindingProvider)wsPort).getRequestContext().put(“”, yourTimeoutInMillisec);

    which is equivalent to

    (BindingProvider)wsPort).getRequestContext().put(StubExt.PROPERTY_CLIENT_TIMEOUT, yourTimeoutInMillisec);

  4. The IBM documentation is correct. All the means is you can not set jax-ws timeouts in deployment descriptor (ibm-webservicesclient-bnd.xmi) like you do for a jax-rpc application.

    “JAX-WS timeout properties”

    Further reference:
    Configuring the JAX-RPC web services client bindings in the ibm-webservicesclient-bnd.xmi deployment descriptor

  5. I needed to set request timeout on Jboss 6.2EAP when using soap over jms (soapjms). Jboss uses org.apacge.cxf internally. After some struggle I finally used directly the cxf classes to set the timeout.

    final Client cl = ClientProxy.getClient(wsClient);
    final JMSConduit jmsConduit = (JMSConduit) cl.getConduit();
    jmsConduit.getJmsConfig().setReceiveTimeout(30000L); // milliseconds

    To get this working I had to add a dependency to Jboss cxf internal module by adding
    org.apache.cxf.impl with “export” keyword to MANIFEST.MF dependencies section.

    Manifest-Version: 1.0
    Dependencies: org.apache.cxf.impl export, // is just other dependency

    This allowed access to Jboss private cxf implementation classes in rune-time. In project I use maven org.apache.cxf dependencies with scope “provided” so they are not packed to ear.




  6. import;

    public class somehing
    private static final String CONNECTION_TIMEOUT = “”;
    private static final String RECEIVE_TIMEOUT = “”;

    //example method
    public String doGet(String url, Object body, Map headers) {

    Client client = ClientBuilder.newClient();, 240000); //4 minutes, 240000);
    WebTarget target =;


    property field is public on which is extended by soooo….

  7. I’ve just seen that, if you have a client which doesn’t include code strictly dependent from any implementation, and you want set timeouts without knowing if your client will execute in a container where it will find CXF or the default jdk implementation (JDK JAX-WS RI), then you have to put both pairs of properties, for example for request timeout:

    ((BindingProvider) port).getRequestContext().put(CXF_REQUEST_TIMEOUT, requestTimeout);
    ((BindingProvider) port).getRequestContext().put(JAXWS_REQUEST_TIMEOUT, requestTimeout);


    give a look to this

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s