Top Description Fields Constructors Methods
org.apache.hc.client5.http.impl

public Class DefaultHttpRequestRetryStrategy

extends Object
implements HttpRequestRetryStrategy
Class Inheritance
All Implemented Interfaces
org.apache.hc.client5.http.HttpRequestRetryStrategy
Annotations
@Contract
threading:STATELESS
Imports
java.io.IOException, .InterruptedIOException, java.net.ConnectException, .NoRouteToHostException, .UnknownHostException, java.time.Instant, java.util.Arrays, .Collection, .HashSet, .Set, javax.net.ssl.SSLException, org.apache.hc.client5.http.HttpRequestRetryStrategy, org.apache.hc.client5.http.utils.DateUtils, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior, org.apache.hc.core5.concurrent.CancellableDependency, org.apache.hc.core5.http.ConnectionClosedException, .Header, .HttpHeaders, .HttpRequest, .HttpResponse, .HttpStatus, .Method, org.apache.hc.core5.http.protocol.HttpContext, org.apache.hc.core5.util.Args, .TimeValue

Default implementation of the HttpRequestRetryStrategy interface.
Since
5.0

Field Summary

Modifier and TypeField and Description
private final TimeValue
defaultRetryInterval

Retry interval between subsequent retries

public static final DefaultHttpRequestRetryStrategy
private final int
maxRetries

Maximum number of allowed retries

private final Set<Class<? extends IOException>>
nonRetriableIOExceptionClasses

Derived IOExceptions which shall not be retried

private final Set<Integer>
retriableCodes

HTTP status codes which shall be retried

Constructor Summary

AccessConstructor and Description
protected
DefaultHttpRequestRetryStrategy(final int maxRetries, final TimeValue defaultRetryInterval, final Collection<Class<? extends IOException>> clazzes, final Collection<Integer> codes)

public
DefaultHttpRequestRetryStrategy(final int
how many times to retry; 0 means no retries
maxRetries
,
final TimeValue
the default retry interval between subsequent retries if the Retry-After header is not set or invalid.
defaultRetryInterval
)

Create the HTTP request retry strategy using the following list of non-retriable I/O exception classes:

  • InterruptedIOException
  • UnknownHostException
  • ConnectException
  • ConnectionClosedException
  • NoRouteToHostException
  • SSLException
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

Method Summary

Modifier and TypeMethod and Description
public TimeValue
getRetryInterval(final HttpResponse
the response from the target server
response
,
final int
the number of times this method has been unsuccessfully executed
execCount
,
final HttpContext
the context for the request execution
context
)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.getRetryInterval.

Determines the retry interval between subsequent retries.
protected boolean
public boolean
retryRequest(final HttpRequest
the request failed due to an I/O exception
request
,
final IOException
the exception that occurred
exception
,
final int
the number of times this method has been unsuccessfully executed
execCount
,
final HttpContext
the context for the request execution
context
)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Determines if a method should be retried after an I/O exception occurred during execution.
public boolean
retryRequest(final HttpResponse
the response from the target server
response
,
final int
the number of times this method has been unsuccessfully executed
execCount
,
final HttpContext
the context for the request execution
context
)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Determines if a method should be retried given the response from the target server.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultRetryIntervalback to summary
private final TimeValue defaultRetryInterval

Retry interval between subsequent retries

INSTANCEback to summary
public static final DefaultHttpRequestRetryStrategy INSTANCE
maxRetriesback to summary
private final int maxRetries

Maximum number of allowed retries

nonRetriableIOExceptionClassesback to summary
private final Set<Class<? extends IOException>> nonRetriableIOExceptionClasses

Derived IOExceptions which shall not be retried

retriableCodesback to summary
private final Set<Integer> retriableCodes

HTTP status codes which shall be retried

Constructor Detail

DefaultHttpRequestRetryStrategyback to summary
protected DefaultHttpRequestRetryStrategy(final int maxRetries, final TimeValue defaultRetryInterval, final Collection<Class<? extends IOException>> clazzes, final Collection<Integer> codes)
DefaultHttpRequestRetryStrategyback to summary
public DefaultHttpRequestRetryStrategy(final int maxRetries, final 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)
Parameters
maxRetries:int

how many times to retry; 0 means no retries

defaultRetryInterval:TimeValue

the default retry interval between subsequent retries if the Retry-After header is not set or invalid.

DefaultHttpRequestRetryStrategyback to summary
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
and retriable HTTP status codes:
  • SC_TOO_MANY_REQUESTS (429)
  • SC_SERVICE_UNAVAILABLE (503)

Method Detail

getRetryIntervalback to summary
public TimeValue getRetryInterval(final HttpResponse response, final int execCount, final HttpContext context)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.getRetryInterval.

Doc from org.apache.hc.client5.http.HttpRequestRetryStrategy.getRetryInterval.

Determines the retry interval between subsequent retries.

Parameters
response:HttpResponse

the response from the target server

execCount:int

the number of times this method has been unsuccessfully executed

context:HttpContext

the context for the request execution

Returns:TimeValue

the retry interval between subsequent retries

Annotations
@Override
handleAsIdempotentback to summary
protected boolean handleAsIdempotent(final HttpRequest request)
retryRequestback to summary
public boolean retryRequest(final HttpRequest request, final IOException exception, final int execCount, final HttpContext context)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Doc from org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Determines if a method should be retried after an I/O exception occurred during execution.

Parameters
request:HttpRequest

the request failed due to an I/O exception

exception:IOException

the exception that occurred

execCount:int

the number of times this method has been unsuccessfully executed

context:HttpContext

the context for the request execution

Returns:boolean

true if the request should be retried, false otherwise

Annotations
@Override
retryRequestback to summary
public boolean retryRequest(final HttpResponse response, final int execCount, final HttpContext context)

Implements org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Doc from org.apache.hc.client5.http.HttpRequestRetryStrategy.retryRequest.

Determines if a method should be retried given the response from the target server.

Parameters
response:HttpResponse

the response from the target server

execCount:int

the number of times this method has been unsuccessfully executed

context:HttpContext

the context for the request execution

Returns:boolean

true if the request should be retried, false otherwise

Annotations
@Override