似乎是 Axis 管理客户端 org.apache.axis2.client.ServiceClient 正在发行 org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry() 和 默认情况下重试 3 次。有没有办法设置不重试?
我的代码:
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());
最佳答案
您可以使用 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 上有一个线程.
关于java - AXIS2 如何设置连接重试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2211578/