DefaultHttpRequestRetryHandlerpublic class DefaultHttpRequestRetryHandler extends Object implements HttpRequestRetryHandlerThe default {@link HttpRequestRetryHandler} used by request executors. |
Fields Summary |
---|
private final int | retryCountthe number of times a method will be retried | private final boolean | requestSentRetryEnabledWhether 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 int | getRetryCount()
return retryCount;
| public boolean | isRequestSentRetryEnabled()
return requestSentRetryEnabled;
| public boolean | retryRequest(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;
|
|