How to configure timeout duration at client side for axis2 web services?


Axis2 uses CommonsHTTPTransportSender by default, which is based on commons-httpclient-3.1. At transport level, there’re two types of timeouts that can be set:

1. Socket Timeout
2. Connection Timeout

Here’s how you can configure the above ones:

Way #1: Configuring timeouts in axis2.xml

Socket Timeout
<parameter name=”SO_TIMEOUT”>some_integer_value</parameter>

Connection timeout
<parameter name=”CONNECTION_TIMEOUT”>some_integer_value</parameter>

Way #2: Configuring timeouts in code


Options options = new Options();
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));

// or
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);

Real-life code: How to set timeout for a Axis2 Stub?


 long timeout = 2 * 60 * 1000; // Two minutes
 Stub stub = new TestStub();
 stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(soTimeout);

 //or

 long timeout = 2 * 60 * 1000; // Two minutes
 Stub stub = new TestStub();
 stub._getServiceClient().getOptions().setProperty(
                  HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
 stub._getServiceClient().getOptions().setProperty(
                  HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));

Reference

Axis2 HTTP Transport – http://axis.apache.org/axis2/java/core/docs/http-transport.html

About these ads

2 comments

  1. What is the default if I don’t set a timeout?

    1. I think it must be an infinite time unless we set it

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: