Axis2 ServiceClient选项忽略超时

时间:2012-11-23 03:22:41

标签: java rest soap timeout axis2

我在版本中使用Axis2:

Implementation-Version: 1.7.0-SNAPSHOT
Implementation-Vendor-Id: org.apache.axis2
Implementation-Vendor: The Apache Software Foundation
Jenkins-Build-Number: 1847

我想将ServiceClient的超时设置为2000毫秒,这是我们的代码:

Options options = new Options();
options.setTo(new EndpointReference(getUserServiceEndPoint()));
options.setProperty(Constants.Configuration.ENABLE_REST,
        Constants.VALUE_TRUE);
// setting timeout to 2 second should be sufficient, if the server is
// not available within the 3 second interval you got a problem anyway
options.setTimeOutInMilliSeconds(2000);

ServiceClient sender = new ServiceClient();
sender.engageModule(new QName(Constants.MODULE_ADDRESSING)
        .getLocalPart());
sender.setOptions(options);
OMElement getSessionResult = sender
        .sendReceive(getPayloadMethodGetSession());

但是我仍然在日志中看到:

  

org.apache.axis2.AxisFault:主机不接受连接   超时60000毫秒

它真的需要60秒。因此错误消息不仅仅是错误的,似乎只是忽略了超时选项,它总是使用默认选项。

有人有过类似的问题吗?

感谢
塞巴斯蒂安

2 个答案:

答案 0 :(得分:5)

我能够解决这个问题(虽然它看起来有些重复我)

int timeOutInMilliSeconds = 2000;
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
options.setProperty(HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeOutInMilliSeconds);

塞巴斯蒂安

答案 1 :(得分:0)

根据Axis2 1.6.3的API文档,它是两个属性或timeOutInMillis:

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

options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);

消息来源: http://axis.apache.org/axis2/java/core/docs/http-transport.html