Class ContextHandlingHttpClient

  • All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.http.client.HttpClient

    class ContextHandlingHttpClient
    extends org.apache.http.impl.client.CloseableHttpClient
    A wrapper implementation of 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:

    1. Static handlers supplied via the constructor, in original list order
    2. Dynamic handlers from the context attribute HttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS, in original list order
    3. the wrapped client's corresponding execute(...) method
    4. Dynamic handlers from the context attribute HttpClientSupport.CONTEXT_KEY_DYNAMIC_CONTEXT_HANDLERS, in reverse list order
    5. Static handlers supplied via the constructor, in reverse list order
    • Field Detail

      • log

        private org.slf4j.Logger log
        Logger.
      • httpClient

        @Nonnull
        private org.apache.http.impl.client.CloseableHttpClient httpClient
        The wrapped client 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 instance
        staticHandlers - the list of static handlers