AXIS2如何设置连接重试?

时间:2010-02-06 01:23:28

标签: java httpclient axis2

似乎是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());

1 个答案:

答案 0 :(得分: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上有一个帖子。