2010-02-06 74 views
3

看來,軸管理客戶端org.apache.axis2.client.ServiceClient 發出org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry()和 重試就像默認3次。有沒有辦法設置不重試?AXIS2如何設置連接重試?

我的代碼:

 ServiceClient client = new ServiceClient(); 
     Options opts = new Options(); 
     opts.setTo(new EndpointReference(strWebServiceUrl)); 
     opts.setAction(strNameOfMethodToInvoke); 
     opts.setTimeOutInMilliSeconds(timeOut); 
     client.setOptions(opts); 
     OMElement res = client.sendReceive(createRequest()); 
     return (res.toString()); 

代碼現在是

 ServiceClient client = new ServiceClient(); 
     Options opts = new Options(); 
     opts.setTo(new EndpointReference(strWebServiceUrl)); 
     opts.setAction("urn:" + strNameOfMethodToInvoke); 
     opts.setTimeOutInMilliSeconds(timeOut); 

     HttpMethodParams methodParams = new HttpMethodParams(); 
     DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false); 
     methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); 
     opts.setProperty(HTTPConstants.HTTP_METHOD_PARAMS, methodParams); 

     client.setOptions(opts); 
     OMElement res = client.sendReceive(createRequest()); 
     return (res.toString()); 
+0

StackOverflow不是論壇;如果您需要添加更多詳細信息,請[編輯您的問題](http://stackoverflow.com/posts/2211578/edit)。答案應該是答案,而不是關於問題的附加信息。 – Will

回答

4

您可以使用HttpMethodParams.RETRY_HANDLER參數設置。在你的情況下,例如:

HttpMethodParams methodParams = new HttpMethodParams(); 
DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false); 
methodParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); 
opts.setProperty(HTTPConstants.HTTP_METHOD_PARAMS, methodParams); 

wso2.org website有一個線程。

+0

不! HTTPConstants.HTTP_METHOD_PARAMS不存在。我嘗試使用HTTPConstants.HTTP_METHOD仍在重試.. :( – Leonardo

+0

您正在使用哪個版本的axis2?因爲HTTPConstants.HTTP_METHOD_PARAMS是否存在於Axis2的1.5版本中 http://ws.apache.org/axis2/1_5/api/ org/apache/axis2/transport/http/HTTPConstants.html – rochb

+0

我使用了Axis2 1.3,現在升級到了1.5+依賴關係。 但是仍在重試..:( 我添加了下面的最後一個代碼 – Leonardo