My Axis based client progr开发者_StackOverflow社区am tries to connect to a webservice, when the server is down I don't want to wait too much time . I want to wait max 3 seconds, So I need to set a timeout.
There is attribute CONNECTION_TIMEOUT_PROPERTY on the Call class -Axis' JAXRPC Dynamic Invocation . I don't know how to use it. serached alot the web and didn't find out how to do it.I cannot get connection timeouts to work.
I use such definition in client proxy for Axis 1.3:
<bean id="serviceTarget" class="com.nxsec.log4ensics.dbmanager.ws.DMJaxRpcPortProxyFactoryBean">
<property name="customPropertyMap"><map>
<entry key="axis.connection.timeout">
<value type="java.lang.Integer">3000</value>
</entry>
</map></property>
</bean>
I found here the way to set timeout by stub, it might help you.
There is a setTimeout method on the org.apache.axis.client.Stub class, which is the class all emitted stubs extend.
Here is how to set the timeout given a service named Foo:
FooServiceLocator loc = new FooServiceLocator();
FooService binding = loc.getFooService();
org.apache.axis.client.Stub s = (Stub) binding;
s.setTimeout(1000); // 1 second, in miliseconds
See: http://ws.apache.org/axis/faq.html#faq17
I found this to work well:
long soTimeout = 2 * 60 * 1000; // Two minutes
Stub stub = new TestStub();
stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(soTimeout);
//or
int timeOutInMilliSeconds = 2 * 60 * 1000; // Two minutes
Stub stub = new TestStub();
stub._getServiceClient().getOptions().setProperty(
HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
stub._getServiceClient().getOptions().setProperty(
HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));
Found here: https://singztechmusings.wordpress.com/2011/05/07/how-to-configure-timeout-duration-at-client-side-for-axis2-web-services/
精彩评论