5

我在版本中使用 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秒。所以错误消息不仅仅是错误的,似乎超时选项只是被忽略了,它总是使用默认选项。

有人有类似的问题吗?

谢谢塞巴斯蒂安
_

4

2 回答 2

5

我能够解决这个问题(尽管它在我看来有点重复)

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

塞巴斯蒂安

于 2012-11-23T03:53:45.863 回答
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

于 2015-08-20T20:03:33.483 回答