Setting Timeout for Axis SOAP Webservice

lathspell42 picture lathspell42 · Nov 16, 2011 · Viewed 22.7k times · Source

I'm using an Axis 1.4 webservice like this:

FooServiceLocator fooLocator = new FooServiceLocator();
fooLocator.getEngine().setOption("sendMultiRefs", false);
Foo foo = fooLocator.getFooService(new URL(soapServiceUrl));

How can I set a timeout for the connection establishment and for the opened connection? (Similar to org.apache.commons.net.SocketClient setTimeout() and setSoTimeout())?

I found a hint that suggested setting a timeout like this:

((Stub) sPcspService).setTimeout(soapTimeoutSecs * 1000);

but the explicit cast looks more like a hack than on official API usage.

Grepping the source code I found references to

DefaultCommonsHTTPClientProperties.CONNECTION_DEFAULT_SO_TIMEOUT_KEY

but neither do I know if I use the Commons HTTP Client or another, nor how to apply this option.

Answer

Osify picture Osify · Sep 28, 2012

I used to use axis 1.4 and soap as well, to set timeout for stub with your example, I would do as:

FooServiceLocator fooLocator = new FooServiceLocator();
fooLocator.getEngine().setOption("sendMultiRefs", false);
Foo foo = fooLocator.getFooService(new URL(soapServiceUrl));

FooStub binding = (FooStub) foo;
binding.setTimeout(soapTimeoutSecs * 1000);

Your FooStub is extended to org.apache.axis.client.Stub and if you generated the classes via wsdl2java you would got them already.