Sunday, March 28, 2010

How to set timeout for JAX-WS client invocations programmatically in WebSphere

A few of my teammates find it difficult to get this working properly. I hope this write-up and example code below would help you. It's actually not too hard.

What can I adjust?

There are three timeouts you can set:

1. CONNECTION_TIMEOUT: The amount of time WebSphere JAX-WS client would wait to establish a http/https connection (default is 180 seconds)
2. WRITE_TIMEOUT: The amount of time the client would wait to finish sending the request (default is 300 seconds)
3. RESPONSE_TIMEOUT: The amount of time the client would wait to finish receiving the response (default is 300 seconds)

How can I set them in my application code?

You can adjust them by setting properties on the requestContext. See code sample below.

HelloWorldSOAPProxy proxy = new HelloWorldSOAPProxy(); // generated proxy class

Map requestContext = ((BindingProvider)proxy._getDescriptor().getProxy()).getRequestContext();
requestContext.put(com.ibm.wsspi.webservices.Constants.CONNECTION_TIMEOUT_PROPERTY , "1");
requestContext.put(com.ibm.wsspi.webservices.Constants.WRITE_TIMEOUT_PROPERTY , "2");
requestContext.put(com.ibm.wsspi.webservices.Constants.RESPONSE_TIMEOUT_PROPERTY , "40");

proxy.sayHello("Billy");


Note: The property value in the Map must be a String; and in seconds.

My code does not work in my environment. How do I troubleshoot it?

Use the WebSphere AdminConsole to enable this trace specification (on the client side): "com.ibm.ws.websvcs.*=all=enabled:org.apache.axis2.*=all=enabled"

You should see something like this in the trace (if you set the response timeout).

[04/08/2009 19:28:37:937 EDT] 00000000 > ibm.ws.websvcs.transport.http.SOAPOverHTTPSender prepareHttpRequestHeaders(): com.ibm.ws.websvcs.transport.http.SOAPOverHTTPSender@33233323 Entry
[04/08/2009 19:28:37:953 EDT] 00000000 3 ibm.ws.websvcs.transport.common.ConfigFromJAX_WS ...ConfigFromJAX_WS.getReadTimeout() : 40
[04/08/2009 19:28:37:953 EDT] 00000000 3 ibm.ws.websvcs.transport.http.SOAPOverHTTPSender syncTimeoutValue 40000 ms for http


Additional tip:

If you are using a standalone Java client (outside of the J2EE container), you can set the WebSphere traceSpec using system properties.

System.setProperty("java.util.logging.manager","com.ibm.ws.bootstrap.WsLogManager");
System.setProperty("traceSettingsFile","MyTraceSettings.properties");
System.setProperty("java.util.logging.configureByServer","true");


and put your traceSpec in a file (e.g. MyTraceSettings.properties) on the working directory.

traceFileName=c:/temp/trace.log
com.ibm.ws.websvcs.*=all=enabled:org.apache.axis2.*=all=enabled


What if I can't or don't want to change the application code?

You can configure the HTTP Transport Policy to adjust these timeouts. See link in InfoCentre for details.

That's all for now.

Wednesday, March 24, 2010

JAX-RS support now exists in WebSphere Application Server!

I'm pleased to see that WebSphere released formal support for JAX-RS 1.0 (plus more) via an upgrade to the Web 2.0 Feature Pack today.  Support also includes JSON support and support for a client API.  Enjoy!