我在以下版本中使用 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: The host did not accept the connection within timeout of 60000 ms
而且它确实也需要 60 秒。所以错误消息不仅仅是错误的,似乎超时选项只是被忽略了,它总是使用默认值。
有人遇到过类似的问题吗?
谢谢
塞巴斯蒂安
最佳答案
我能够解决这个问题(尽管它看起来有点重复)
int timeOutInMilliSeconds = 2000;
options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
options.setProperty(HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeOutInMilliSeconds);
塞巴斯蒂安
关于java - Axis2 ServiceClient 选项忽略超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13522686/