Class DefaultHttpRequestRetryStrategy
java.lang.Object
org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy
- All Implemented Interfaces:
HttpRequestRetryStrategy
@Contract(threading=STATELESS)
public class DefaultHttpRequestRetryStrategy
extends Object
implements HttpRequestRetryStrategy
Default implementation of the
HttpRequestRetryStrategy interface.- Since:
- 5.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.hc.core5.util.TimeValueRetry interval between subsequent retriesstatic final DefaultHttpRequestRetryStrategyprivate final intMaximum number of allowed retriesprivate final Set<Class<? extends IOException>> DerivedIOExceptionswhich shall not be retriedHTTP status codes which shall be retried -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate the HTTP request retry strategy with a max retry count of 1, default retry interval of 1 second, and using the following list of non-retriable I/O exception classes:
InterruptedIOException UnknownHostException ConnectException ConnectionClosedException SSLException and retriable HTTP status codes:
SC_TOO_MANY_REQUESTS (429) SC_SERVICE_UNAVAILABLE (503)DefaultHttpRequestRetryStrategy(int maxRetries, org.apache.hc.core5.util.TimeValue defaultRetryInterval) Create the HTTP request retry strategy using the following list of non-retriable I/O exception classes:
InterruptedIOException UnknownHostException ConnectException ConnectionClosedException NoRouteToHostException SSLException and retriable HTTP status codes:
SC_TOO_MANY_REQUESTS (429) SC_SERVICE_UNAVAILABLE (503)protectedDefaultHttpRequestRetryStrategy(int maxRetries, org.apache.hc.core5.util.TimeValue defaultRetryInterval, Collection<Class<? extends IOException>> clazzes, Collection<Integer> codes) -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.hc.core5.util.TimeValuegetRetryInterval(org.apache.hc.core5.http.HttpResponse response, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Determines the retry interval between subsequent retries.protected booleanhandleAsIdempotent(org.apache.hc.core5.http.HttpRequest request) booleanretryRequest(org.apache.hc.core5.http.HttpRequest request, IOException exception, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Determines if a method should be retried after an I/O exception occurred during execution.booleanretryRequest(org.apache.hc.core5.http.HttpResponse response, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Determines if a method should be retried given the response from the target server.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HttpRequestRetryStrategy
getRetryInterval
-
Field Details
-
INSTANCE
-
maxRetries
private final int maxRetriesMaximum number of allowed retries -
defaultRetryInterval
private final org.apache.hc.core5.util.TimeValue defaultRetryIntervalRetry interval between subsequent retries -
nonRetriableIOExceptionClasses
DerivedIOExceptionswhich shall not be retried -
retriableCodes
-
-
Constructor Details
-
DefaultHttpRequestRetryStrategy
protected DefaultHttpRequestRetryStrategy(int maxRetries, org.apache.hc.core5.util.TimeValue defaultRetryInterval, Collection<Class<? extends IOException>> clazzes, Collection<Integer> codes) -
DefaultHttpRequestRetryStrategy
public DefaultHttpRequestRetryStrategy(int maxRetries, org.apache.hc.core5.util.TimeValue defaultRetryInterval) Create the HTTP request retry strategy using the following list of non-retriable I/O exception classes:
- InterruptedIOException
- UnknownHostException
- ConnectException
- ConnectionClosedException
- NoRouteToHostException
- SSLException
- SC_TOO_MANY_REQUESTS (429)
- SC_SERVICE_UNAVAILABLE (503)
- Parameters:
maxRetries- how many times to retry; 0 means no retriesdefaultRetryInterval- the default retry interval between subsequent retries if theRetry-Afterheader is not set or invalid.
-
DefaultHttpRequestRetryStrategy
public DefaultHttpRequestRetryStrategy()Create the HTTP request retry strategy with a max retry count of 1, default retry interval of 1 second, and using the following list of non-retriable I/O exception classes:
- InterruptedIOException
- UnknownHostException
- ConnectException
- ConnectionClosedException
- SSLException
- SC_TOO_MANY_REQUESTS (429)
- SC_SERVICE_UNAVAILABLE (503)
-
-
Method Details
-
retryRequest
public boolean retryRequest(org.apache.hc.core5.http.HttpRequest request, IOException exception, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Description copied from interface:HttpRequestRetryStrategyDetermines if a method should be retried after an I/O exception occurred during execution.- Specified by:
retryRequestin interfaceHttpRequestRetryStrategy- Parameters:
request- the request failed due to an I/O exceptionexception- the exception that occurredexecCount- the number of times this method has been unsuccessfully executedcontext- the context for the request execution- Returns:
trueif the request should be retried,falseotherwise
-
retryRequest
public boolean retryRequest(org.apache.hc.core5.http.HttpResponse response, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Description copied from interface:HttpRequestRetryStrategyDetermines if a method should be retried given the response from the target server.- Specified by:
retryRequestin interfaceHttpRequestRetryStrategy- Parameters:
response- the response from the target serverexecCount- the number of times this method has been unsuccessfully executedcontext- the context for the request execution- Returns:
trueif the request should be retried,falseotherwise
-
getRetryInterval
public org.apache.hc.core5.util.TimeValue getRetryInterval(org.apache.hc.core5.http.HttpResponse response, int execCount, org.apache.hc.core5.http.protocol.HttpContext context) Description copied from interface:HttpRequestRetryStrategyDetermines the retry interval between subsequent retries.- Specified by:
getRetryIntervalin interfaceHttpRequestRetryStrategy- Parameters:
response- the response from the target serverexecCount- the number of times this method has been unsuccessfully executedcontext- the context for the request execution- Returns:
- the retry interval between subsequent retries
-
handleAsIdempotent
protected boolean handleAsIdempotent(org.apache.hc.core5.http.HttpRequest request)
-