Axis2 ServiceClient选项忽略超时

seb*_*ner 3 java rest soap axis2 timeout

我在版本中使用Axis2:

Implementation-Version: 1.7.0-SNAPSHOT
Implementation-Vendor-Id: org.apache.axis2
Implementation-Vendor: The Apache Software Foundation
Jenkins-Build-Number: 1847
Run Code Online (Sandbox Code Playgroud)

我想将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());
Run Code Online (Sandbox Code Playgroud)

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

org.apache.axis2.AxisFault:主机在60000毫秒的超时时间内未接受连接

而且确实需要60秒。因此,错误消息不仅是错误的,而且似乎只是忽略了超时选项,并且始终使用默认选项。

有人有类似的问题吗?

由于
塞巴斯蒂安

seb*_*ner 5

我能够解决此问题(尽管看起来好像对我来说有些重复)

int timeOutInMilliSeconds = 2000;
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
options.setProperty(HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeOutInMilliSeconds);
Run Code Online (Sandbox Code Playgroud)

塞巴斯蒂安

  • 它看起来是重复的,但是两个超时有重要区别。SO_TIMEOUT是尝试建立与服务器的连接时的超时。CONNECTION_TIMEOUT是发送请求后套接字将等待接收响应的时间。 (2认同)
  • 但是什么是options.setTimeOutInMilliSeconds(timeOutInMilliSeconds); 有好处吗?它似乎根本没有作用。 (2认同)