You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Yuchen Wang <yw...@shopping.com> on 2005/09/20 02:09:47 UTC

Bug in disabling retry of httpclient 3.0?

Hi,

I am using HttpClient 3.0 rc2 for our project. I try to disable the
retry when there is a failure with execution of an HTTP method. I
followed the instruction from
http://jakarta.apache.org/commons/httpclient/exception-handling.html#Cus
tom%20exception%20handler but it can NOT stop the httpclient from
retrying. 

 
httpclient.getHttpConnectionManager().getParams().setParameter(HttpMetho
dParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));

After looking at the source code of class HttpMethodDirector.java, I
found that the method executeWithRetry uses this code to get the
HttpMethodRetryHandler:

	handler =
(HttpMethodRetryHandler)method.getParams().getParameter(HttpMethodParams
.RETRY_HANDLER);

However, in the method of getParameter in class DefaultHttpParams.java,
this.parameters is always null even if I already set it, which caused
the problem. I have to use following code to disable the retry:

        PostMethod post = new
PostMethod("http://www.this_is_my_host.com");
        DefaultMethodRetryHandler handler = new
DefaultMethodRetryHandler();
        handler.setRetryCount(0);
        post.setMethodRetryHandler(handler);

Is this a bug? 

Also, in general, I don't think having the auto-retry turned as default
is a good idea. As a framework, tt should leave to the user to decide if
it needs to be turned on.

Thanks.

Yuchen


Re: Bug in disabling retry of httpclient 3.0?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, Sep 19, 2005 at 05:09:47PM -0700, Yuchen Wang wrote:
> Hi,
> 
> I am using HttpClient 3.0 rc2 for our project. I try to disable the
> retry when there is a failure with execution of an HTTP method. I
> followed the instruction from
> http://jakarta.apache.org/commons/httpclient/exception-handling.html#Cus
> tom%20exception%20handler but it can NOT stop the httpclient from
> retrying. 
> 
>  
> httpclient.getHttpConnectionManager().getParams().setParameter(HttpMetho
> dParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
> 

Yuchen,

Retry handler can be set on a per method or a per client basis. Retry
handler set on the connection manager level will have no effect.

Try this instead:

httpclient.getParams().setParameter(
  HttpMethodParams.RETRY_HANDLER, 
  new DefaultHttpMethodRetryHandler(0, false));


> After looking at the source code of class HttpMethodDirector.java, I
> found that the method executeWithRetry uses this code to get the
> HttpMethodRetryHandler:
> 
> 	handler =
> (HttpMethodRetryHandler)method.getParams().getParameter(HttpMethodParams
> .RETRY_HANDLER);
> 
> However, in the method of getParameter in class DefaultHttpParams.java,
> this.parameters is always null even if I already set it, which caused
> the problem. I have to use following code to disable the retry:
> 
>         PostMethod post = new
> PostMethod("http://www.this_is_my_host.com");
>         DefaultMethodRetryHandler handler = new
> DefaultMethodRetryHandler();
>         handler.setRetryCount(0);
>         post.setMethodRetryHandler(handler);
> 
> Is this a bug? 
> 
> Also, in general, I don't think having the auto-retry turned as default
> is a good idea. As a framework, tt should leave to the user to decide if
> it needs to be turned on.
> 

The default retry handler will retry a failed method ONLY if 
(1) the request has not been fully transmitted to the target server (the 
connection was dropped by server while the client was still sending the 
data)
(2) The target server dropped the connection without returning a response

In both cases it is generally safe to retry the failed method without
the user's intervention. In all other cases the method will not be
retried per default

Oleg


> Thanks.
> 
> Yuchen
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org