Class ContextHandlingHttpClient
- java.lang.Object
-
- org.apache.http.impl.client.CloseableHttpClient
-
- net.shibboleth.utilities.java.support.httpclient.ContextHandlingHttpClient
-
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.http.client.HttpClient
class ContextHandlingHttpClient extends org.apache.http.impl.client.CloseableHttpClientA wrapper implementation ofHttpClientwhich invokes supplied instances ofHttpClientContextHandlerbefore and after request execution.By definition the handlers will only be invoked for the
HttpClientexecute(...) method variants which take anHttpContextargument.The order of execution is:
- Static handlers supplied via the constructor, in original list order
- Dynamic handlers from the context attribute
HttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS, in original list order - the wrapped client's corresponding execute(...) method
- Dynamic handlers from the context attribute
HttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS, in reverse list order - Static handlers supplied via the constructor, in reverse list order
-
-
Field Summary
Fields Modifier and Type Field Description private List<HttpClientContextHandler>handlersOptional list of static handlers supplied to this class instance.private org.apache.http.impl.client.CloseableHttpClienthttpClientThe wrapped client instance.private org.slf4j.LoggerlogLogger.
-
Constructor Summary
Constructors Constructor Description ContextHandlingHttpClient(org.apache.http.impl.client.CloseableHttpClient client)Constructor.ContextHandlingHttpClient(org.apache.http.impl.client.CloseableHttpClient client, List<HttpClientContextHandler> staticHandlers)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()protected org.apache.http.client.methods.CloseableHttpResponsedoExecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)org.apache.http.conn.ClientConnectionManagergetConnectionManager()Deprecated.org.apache.http.params.HttpParamsgetParams()Deprecated.private voidinvokeAfter(org.apache.http.client.methods.HttpUriRequest request, org.apache.http.client.protocol.HttpClientContext context, Throwable priorError)InvokeHttpClientContextHandler.invokeAfter(HttpClientContext, HttpUriRequest)for all supplied handlers.private voidinvokeBefore(org.apache.http.client.methods.HttpUriRequest request, org.apache.http.client.protocol.HttpClientContext context)InvokeHttpClientContextHandler.invokeBefore(HttpClientContext, HttpUriRequest)for supplied handlers.private voidprocessErrorsForInvokeAfter(IOException invokeAfterException, Throwable priorError)Process errors forinvokeAfter(HttpUriRequest, HttpClientContext, Throwable).private IOExceptionprocessHandlerErrors(String stage, List<Throwable> errors)Process the error(s) seen duringinvokeBefore(HttpUriRequest, HttpClientContext)orinvokeAfter(HttpUriRequest, HttpClientContext, Throwable)into a singleIOExceptionthat will be propagated out of that method.
-
-
-
Field Detail
-
log
private org.slf4j.Logger log
Logger.
-
httpClient
@Nonnull private org.apache.http.impl.client.CloseableHttpClient httpClient
The wrapped client instance.
-
handlers
@Nonnull private List<HttpClientContextHandler> handlers
Optional list of static handlers supplied to this class instance.
-
-
Constructor Detail
-
ContextHandlingHttpClient
public ContextHandlingHttpClient(@Nonnull org.apache.http.impl.client.CloseableHttpClient client)Constructor.- Parameters:
client- the wrapped client instance
-
ContextHandlingHttpClient
public ContextHandlingHttpClient(@Nonnull org.apache.http.impl.client.CloseableHttpClient client, @Nonnull List<HttpClientContextHandler> staticHandlers)Constructor.- Parameters:
client- the wrapped client instancestaticHandlers- the list of static handlers
-
-
Method Detail
-
getParams
@Deprecated public org.apache.http.params.HttpParams getParams()
Deprecated.
-
getConnectionManager
@Deprecated public org.apache.http.conn.ClientConnectionManager getConnectionManager()
Deprecated.
-
close
public void close() throws IOException- Throws:
IOException
-
doExecute
protected org.apache.http.client.methods.CloseableHttpResponse doExecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws IOException, org.apache.http.client.ClientProtocolException- Specified by:
doExecutein classorg.apache.http.impl.client.CloseableHttpClient- Throws:
IOExceptionorg.apache.http.client.ClientProtocolException
-
invokeBefore
private void invokeBefore(org.apache.http.client.methods.HttpUriRequest request, org.apache.http.client.protocol.HttpClientContext context) throws IOExceptionInvokeHttpClientContextHandler.invokeBefore(HttpClientContext, HttpUriRequest)for supplied handlers.- Parameters:
request- the HTTP requestcontext- the HTTP context- Throws:
IOException- if any handler throws an error
-
invokeAfter
private void invokeAfter(org.apache.http.client.methods.HttpUriRequest request, org.apache.http.client.protocol.HttpClientContext context, Throwable priorError) throws IOExceptionInvokeHttpClientContextHandler.invokeAfter(HttpClientContext, HttpUriRequest)for all supplied handlers.- Parameters:
request- the HTTP requestcontext- the HTTP contextpriorError- an error thrown by by eitherinvokeBefore(HttpUriRequest, HttpClientContext)or by HttpClient execute(...).- Throws:
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.
-
processHandlerErrors
private IOException processHandlerErrors(String stage, List<Throwable> errors)
Process the error(s) seen duringinvokeBefore(HttpUriRequest, HttpClientContext)orinvokeAfter(HttpUriRequest, HttpClientContext, Throwable)into a singleIOExceptionthat will be propagated out of that method.- Parameters:
stage- the name of the stage, for reporting purposeserrors- all errors seen during the method execution- Returns:
- the single exception to be propagated out, will be null if no errors present
-
processErrorsForInvokeAfter
private void processErrorsForInvokeAfter(IOException invokeAfterException, Throwable priorError) throws IOException
Process errors forinvokeAfter(HttpUriRequest, HttpClientContext, Throwable).- Parameters:
invokeAfterException- the exception thrown by invokeAfter handlers, if anypriorError- an error thrown by by eitherinvokeBefore(HttpUriRequest, HttpClientContext)or by HttpClient execute(...), if any.- Throws:
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.
-
-