Class HttpClientManager

java.lang.Object
com.helger.httpclient.HttpClientManager
All Implemented Interfaces:
AutoCloseable

public class HttpClientManager extends Object implements AutoCloseable
A small wrapper around CloseableHttpClient.
Author:
Philip Helger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final void
     
    void
     
    create(HttpClientSettings aHttpClientSettings)
     
    <T> T
    execute(org.apache.hc.client5.http.classic.methods.HttpUriRequest aRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler)
    Execute the provided request without any special context.
    <T> T
    execute(org.apache.hc.core5.http.ClassicHttpRequest aRequest, org.apache.hc.core5.http.protocol.HttpContext aHttpContext, org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler)
    Execute the provided request with an optional special context.
    final boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpClientManager

      public HttpClientManager()
    • HttpClientManager

      public HttpClientManager(@Nonnull IHttpClientProvider aHttpClientSupplier)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • isClosed

      public final boolean isClosed()
      Returns:
      true if this manager is already closed, and no further requests can be executed, false if this manager is not yet closed.
      Since:
      8.8.2
    • checkIfClosed

      protected final void checkIfClosed()
    • execute

      @Nullable public <T> T execute(@Nonnull org.apache.hc.client5.http.classic.methods.HttpUriRequest aRequest, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException
      Execute the provided request without any special context. The response handler is invoked as a callback. This method automatically cleans up all used resources and as such is preferred over the execute methods returning the CloseableHttpResponse.
      Type Parameters:
      T - return type
      Parameters:
      aRequest - The request to be executed. May not be null.
      aResponseHandler - The response handler to be executed. May not be null.
      Returns:
      The evaluated response of the response handler. May be null.
      Throws:
      IOException - In case of error
      IllegalStateException - If this manager was already closed!
    • execute

      @Nullable public <T> T execute(@Nonnull org.apache.hc.core5.http.ClassicHttpRequest aRequest, @Nullable org.apache.hc.core5.http.protocol.HttpContext aHttpContext, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<? extends T> aResponseHandler) throws IOException
      Execute the provided request with an optional special context. The response handler is invoked as a callback. This method automatically cleans up all used resources and as such is preferred over the execute methods returning the CloseableHttpResponse.
      Type Parameters:
      T - return type
      Parameters:
      aRequest - The request to be executed. May not be null.
      aHttpContext - The optional context to be used. May be null to
      aResponseHandler - The response handler to be executed. May not be null.
      Returns:
      The evaluated response of the response handler. May be null.
      Throws:
      IOException - In case of error
      IllegalStateException - If this manager was already closed!
    • create

      @Nonnull public static HttpClientManager create(@Nonnull HttpClientSettings aHttpClientSettings)