FileDocCategorySizeDatePackage
DefaultHttpRequestRetryHandler.javaAPI DocAndroid 1.5 API4774Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

DefaultHttpRequestRetryHandler

public class DefaultHttpRequestRetryHandler extends Object implements HttpRequestRetryHandler
The default {@link HttpRequestRetryHandler} used by request executors.
author
Michael Becke
author
Oleg Kalnichevski

Fields Summary
private final int
retryCount
the number of times a method will be retried
private final boolean
requestSentRetryEnabled
Whether or not methods that have successfully sent their request will be retried
Constructors Summary
public DefaultHttpRequestRetryHandler(int retryCount, boolean requestSentRetryEnabled)
Default constructor

        super();
        this.retryCount = retryCount;
        this.requestSentRetryEnabled = requestSentRetryEnabled;
    
public DefaultHttpRequestRetryHandler()
Default constructor

        this(3, false);
    
Methods Summary
public intgetRetryCount()

return
the maximum number of times a method will be retried

        return retryCount;
    
public booleanisRequestSentRetryEnabled()

return
true if this handler will retry methods that have successfully sent their request, false otherwise

        return requestSentRetryEnabled;
    
public booleanretryRequest(java.io.IOException exception, int executionCount, org.apache.http.protocol.HttpContext context)
Used retryCount and requestSentRetryEnabled to determine if the given method should be retried.

        if (exception == null) {
            throw new IllegalArgumentException("Exception parameter may not be null");
        }
        if (context == null) {
            throw new IllegalArgumentException("HTTP context may not be null");
        }
        if (executionCount > this.retryCount) {
            // Do not retry if over max retry count
            return false;
        }
        if (exception instanceof NoHttpResponseException) {
            // Retry if the server dropped connection on us
            return true;
        }
        if (exception instanceof InterruptedIOException) {
            // Timeout
            return false;
        }
        if (exception instanceof UnknownHostException) {
            // Unknown host
            return false;
        }
        if (exception instanceof SSLHandshakeException) {
            // SSL handshake exception
            return false;
        }
        Boolean b = (Boolean)
            context.getAttribute(ExecutionContext.HTTP_REQ_SENT);
        boolean sent = (b != null && b.booleanValue());
        if (!sent || this.requestSentRetryEnabled) {
            // Retry if the request has not been sent fully or
            // if it's OK to retry methods that have been sent
            return true;
        }
        // otherwise do not retry
        return false;