class ContextHandlingHttpClient extends CloseableHttpClient
HttpClient which invokes supplied instances of HttpClientContextHandler
before and after request execution.
By definition the handlers will only be invoked for the HttpClient execute(...) method variants
which take an HttpContext argument.
The order of execution is:
HttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS,
in original list orderHttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS,
in reverse list order| Modifier and Type | Field and Description |
|---|---|
private List<HttpClientContextHandler> |
handlers
Optional list of static handlers supplied to this class instance.
|
private CloseableHttpClient |
httpClient
The wrapped client instance.
|
private org.slf4j.Logger |
log
Logger.
|
| Constructor and Description |
|---|
ContextHandlingHttpClient(CloseableHttpClient client)
Constructor.
|
ContextHandlingHttpClient(CloseableHttpClient client,
List<HttpClientContextHandler> staticHandlers)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected CloseableHttpResponse |
doExecute(org.apache.http.HttpHost target,
org.apache.http.HttpRequest request,
org.apache.http.protocol.HttpContext context) |
ClientConnectionManager |
getConnectionManager() |
org.apache.http.params.HttpParams |
getParams() |
private void |
invokeAfter(HttpUriRequest request,
HttpClientContext context,
Throwable priorError)
Invoke
HttpClientContextHandler.invokeAfter(HttpClientContext, HttpUriRequest)
for all supplied handlers. |
private void |
invokeBefore(HttpUriRequest request,
HttpClientContext context)
Invoke
HttpClientContextHandler.invokeBefore(HttpClientContext, HttpUriRequest)
for supplied handlers. |
private void |
processErrorsForInvokeAfter(IOException invokeAfterException,
Throwable priorError)
Process errors for
invokeAfter(HttpUriRequest, HttpClientContext, Throwable). |
private IOException |
processHandlerErrors(String stage,
List<Throwable> errors)
Process the error(s) seen during
invokeBefore(HttpUriRequest, HttpClientContext)
or #invokeAfter(HttpUriRequest, HttpClientContext, IOException, boolean)
into a single IOException that will be propagated out of that method. |
private org.slf4j.Logger log
@Nonnull private CloseableHttpClient httpClient
@Nonnull private List<HttpClientContextHandler> handlers
public ContextHandlingHttpClient(@Nonnull CloseableHttpClient client)
client - the wrapped client instancepublic ContextHandlingHttpClient(@Nonnull CloseableHttpClient client, @Nonnull List<HttpClientContextHandler> staticHandlers)
client - the wrapped client instancestaticHandlers - the list of static handlerspublic org.apache.http.params.HttpParams getParams()
public ClientConnectionManager getConnectionManager()
public void close()
throws IOException
IOExceptionprotected CloseableHttpResponse doExecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws IOException, ClientProtocolException
doExecute in class CloseableHttpClientIOExceptionClientProtocolExceptionprivate void invokeBefore(HttpUriRequest request, HttpClientContext context) throws IOException
HttpClientContextHandler.invokeBefore(HttpClientContext, HttpUriRequest)
for supplied handlers.request - the HTTP requestcontext - the HTTP contextIOException - if any handler throws an errorprivate void invokeAfter(HttpUriRequest request, HttpClientContext context, Throwable priorError) throws IOException
HttpClientContextHandler.invokeAfter(HttpClientContext, HttpUriRequest)
for all supplied handlers.request - the HTTP requestcontext - the HTTP contextpriorError - an error thrown by by either invokeBefore(HttpUriRequest, HttpClientContext)
or by HttpClient execute(...).IOException - if any handler throws an error, or if priorError is an IOException. If priorError
is a type of unchecked error (RuntimeException or Error) that will be propagated out
here as well.private IOException processHandlerErrors(String stage, List<Throwable> errors)
invokeBefore(HttpUriRequest, HttpClientContext)
or #invokeAfter(HttpUriRequest, HttpClientContext, IOException, boolean)
into a single IOException that will be propagated out of that method.stage - the name of the stage, for reporting purposeserrors - all errors seen during the method executionprivate void processErrorsForInvokeAfter(IOException invokeAfterException, Throwable priorError) throws IOException
invokeAfter(HttpUriRequest, HttpClientContext, Throwable).invokeAfterException - the exception thrown by invokeAfter handlers, if anypriorError - an error thrown by by either invokeBefore(HttpUriRequest, HttpClientContext)
or by HttpClient execute(...), if any.IOException - if invokeAfterException is non-null, or if priorError is an IOException. If priorError
is a type of unchecked error (RuntimeException or Error) that will be propagated out
here as well.Copyright © 1999–2019 Shibboleth Consortium. All rights reserved.