Package net.shibboleth.shared.httpclient
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
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 Summary
FieldsModifier and TypeFieldDescriptionprivate ScheduledExecutorServiceExecutor service which implements the timeout handling.private org.apache.hc.client5.http.classic.HttpClientThe wrapped HttpClient instance.private final org.slf4j.LoggerLogger.private DurationClient-level request timeout. -
Constructor Summary
ConstructorsConstructorDescriptionRequestTimeLimitingHttpClient(org.apache.hc.client5.http.classic.HttpClient client, ScheduledExecutorService executor, Duration requestTimeout) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidclose(org.apache.hc.core5.io.CloseMode closeMode) protected org.apache.hc.core5.http.ClassicHttpResponsedoExecute(org.apache.hc.core5.http.HttpHost target, org.apache.hc.core5.http.ClassicHttpRequest request, org.apache.hc.core5.http.protocol.HttpContext context) Execute the HTTP request.protected DurationresolveEffectiveTimeout(org.apache.hc.core5.http.protocol.HttpContext context) Resolve the effective request timeout to use for the current request.Methods inherited from class net.shibboleth.shared.httpclient.AbstractHttpClient
execute, execute, execute, execute, execute, execute, execute, executeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hc.client5.http.classic.HttpClient
executeOpen
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logLogger. -
httpClient
@Nonnull private org.apache.hc.client5.http.classic.HttpClient httpClientThe wrapped HttpClient instance. -
executorService
Executor service which implements the timeout handling. -
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 instanceexecutor- executor service which implements the timeout handlingrequestTimeout- 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:
doExecutein classAbstractHttpClient- Parameters:
target- the target host for the request, may benullrequest- the request to executecontext- the context to use for the execution, ornullto 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
- Throws:
IOException
-
close
public void close(org.apache.hc.core5.io.CloseMode closeMode)
-