views:

491

answers:

2

It seems that the Axis admin client org.apache.axis2.client.ServiceClient is issuing org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry() and the retry is like 3 times by default. Is there a way to set to not do retries?

My code:

        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());

Tnx!

A: 

You can set it using the HttpMethodParams.RETRY_HANDLER parameter. In you case, for example:

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

There is a thread on the wso2.org website.

rochb
excuse my english!setParameter is no member from Options, also DefaultMethodRetryHandler is deprecated. I try with Options.setProperty and DefaultHttpMethodRetryHandler but still Retrying...Try also sample from wso2.org website but HTTPConstants.HTTP_METHOD_PARAMS don't exist and with HTTPConstants.HTTP_METHOD still Retrying.What am I doing wrong?
Leonardo
I've edited my answer. Sorry for the confusion. Hope it works now. :)
rochb
No! HTTPConstants.HTTP_METHOD_PARAMS don't exist. I try with HTTPConstants.HTTP_METHOD still Retrying.. :(
Leonardo
Which version of axis2 are you using? Because, HTTPConstants.HTTP_METHOD_PARAMS DOES exist in 1.5 of Axis2.http://ws.apache.org/axis2/1_5/api/org/apache/axis2/transport/http/HTTPConstants.html
rochb
I used Axis2 1.3, now upgraded to 1.5 + dependencies.But still Retrying .. : (I add the last code below
Leonardo
I've debugged it. When it reaches executeWithRetry, it looks up the value of HTTP_METHOD_PARAMS. When I set it up in my Axis2 client code, the param appears in HttpMethodDirector.executeWithRetry(): http.method.retry-handler=org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@1eb904d.It's here: http://kickjava.com/src/org/apache/commons/httpclient/HttpMethodDirector.java.htm#427Which version of httpclient do you use? You should have commons-httpclient-3.1.jar.
rochb
A: 

The code now is

        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());
Leonardo