Class RequestTimeLimitingHttpClient

java.lang.Object
net.shibboleth.shared.httpclient.AbstractHttpClient
net.shibboleth.shared.httpclient.RequestTimeLimitingHttpClient
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.hc.client5.http.classic.HttpClient, org.apache.hc.core5.io.ModalCloseable

public class RequestTimeLimitingHttpClient extends AbstractHttpClient
An HttpClient implementation which implements an overall request timeout for a wrapped client instance.

The request timeout Duration may be supplied as either a statically-configured value on the client instance, or via the passed HttpContext in the attribute HttpClientSupport.CONTEXT_KEY_REQUEST_TIMEOUT. A non-null context value will override the static client value.

Requests that exceed the effective timeout will throw RequestTimeoutExceededException.

  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Logger.
    • httpClient

      @Nonnull private org.apache.hc.client5.http.classic.HttpClient httpClient
      The wrapped HttpClient instance.
    • executorService

      @Nonnull private ScheduledExecutorService executorService
      Executor service which implements the timeout handling.
    • timeout

      @Nullable private Duration timeout
      Client-level request timeout.
  • Constructor Details

    • RequestTimeLimitingHttpClient

      public RequestTimeLimitingHttpClient(@Nonnull org.apache.hc.client5.http.classic.HttpClient client, @Nonnull ScheduledExecutorService executor, @Nullable Duration requestTimeout)
      Constructor.
      Parameters:
      client - the wrapped HttpClient instance
      executor - executor service which implements the timeout handling
      requestTimeout - client-level request timeout
  • Method Details

    • doExecute

      protected org.apache.hc.core5.http.ClassicHttpResponse doExecute(@Nullable org.apache.hc.core5.http.HttpHost target, @Nonnull org.apache.hc.core5.http.ClassicHttpRequest request, @Nullable org.apache.hc.core5.http.protocol.HttpContext context) throws IOException
      Execute the HTTP request.
      Specified by:
      doExecute in class AbstractHttpClient
      Parameters:
      target - the target host for the request, may be null
      request - the request to execute
      context - the context to use for the execution, or null to use the default context
      Returns:
      the response to the request
      Throws:
      IOException - in case of a problem or the connection was aborted
    • resolveEffectiveTimeout

      @Nullable protected Duration resolveEffectiveTimeout(@Nullable org.apache.hc.core5.http.protocol.HttpContext context)
      Resolve the effective request timeout to use for the current request.
      Parameters:
      context - the client context
      Returns:
      the effective timeout, may be null
    • close

      public void close() throws IOException
      Throws:
      IOException
    • close

      public void close(org.apache.hc.core5.io.CloseMode closeMode)