2012-11-23 31 views
1

我使用Axis2的版本:的Axis2 ServiceClient选项忽略超时

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:主机在超时时间内不接受连接 o f 60000 ms

而且它确实也需要60秒。所以错误信息不仅仅是错误的,它看起来像超时选项被忽略,它总是使用默认的选项。

任何人都有类似的问题?

谢谢
塞巴斯蒂安

回答

2

我能解决这个问题(虽然看起来莫名其妙地复制到我)

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

塞巴斯蒂安

+2

它看起来复制,但两个超时有一个重要的区别。 SO_TIMEOUT是尝试建立与服务器的连接时的超时时间。 CONNECTION_TIMEOUT是套接字在请求发送后等待接收响应的时间。 –

+2

但什么是options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);对吗?它似乎根本没有效果。 –

+0

我希望我能告诉你。 Options类中的javadoc没有提供很多信息。我会想通过一种方法来设置这两个值。我的google-fu似乎也很难得到答案。 –

0

每API文档的Axis2 1.6.3,它是两个属性还是timeOutInMillis类似的:

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

OR

options.setTimeOutInMilliSeconds(timeOutInMilliSeconds); 

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

+0

我不确定是否java类实现为c代码上的包装,但在options.c中,setTimeoutInMilliseconds仅修改连接超时:axis2_options_set_property (options,env,AXIS2_HTTP_CONNECTION_TIMEOUT,property); –

+0

在使用端,setTimeoutInMilliseconds与SO_TIMEOUT仅在使用curl后端时有所不同。 –