Enterprise Integration Zone is brought to you in partnership with:

I'm Singaram Subramanian, and I work with CSC India as a Software Developer. My blog is an attempt to share my learnings with all (mainly, for those who desperately mine google finding ways to solve problems, fix issues, learn about a Java/Open source software, or deciding on tough choices etc. during software development as I do). Singaram is a DZone MVB and is not an employee of DZone and has posted 36 posts at DZone. You can read more from them at their website. View Full User Profile

How to Configure Timeout Duration on the Client Side for Axis2 Web Services

06.17.2013
| 5534 views |
  • submit to reddit

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));



Published at DZone with permission of Singaram Subramanian, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)