Class HttpInterface

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class HttpInterface
    extends java.lang.Object
    implements java.io.Closeable
    An HTTP interface for performing HTTP requests in one specific thread. This also means it is not thread safe and should not be used in a thread it was not obtained in. For multi-thread use HttpInterfaceManager.getInterface(), should be called in each thread separately.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpInterface​(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.protocol.HttpClientContext context, boolean ownedClient, HttpContextFilter filter)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acquire()
      Acquire exclusive use of this instance.
      void close()  
      org.apache.http.client.methods.CloseableHttpResponse execute​(org.apache.http.client.methods.HttpUriRequest request)
      Executes the given query using the client and context stored in this instance.
      org.apache.http.client.protocol.HttpClientContext getContext()  
      java.net.URI getFinalLocation()  
      org.apache.http.impl.client.CloseableHttpClient getHttpClient()  
      • Methods inherited from class java.lang.Object

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

      • HttpInterface

        public HttpInterface​(org.apache.http.impl.client.CloseableHttpClient client,
                             org.apache.http.client.protocol.HttpClientContext context,
                             boolean ownedClient,
                             HttpContextFilter filter)
        Parameters:
        client - The http client instance used.
        context - The http context instance used.
        ownedClient - True if the client should be closed when this instance is closed.
        filter -
    • Method Detail

      • acquire

        public boolean acquire()
        Acquire exclusive use of this instance. This is released by calling close.
        Returns:
        True if this instance was not exclusively used when this method was called.
      • execute

        public org.apache.http.client.methods.CloseableHttpResponse execute​(org.apache.http.client.methods.HttpUriRequest request)
                                                                     throws java.io.IOException
        Executes the given query using the client and context stored in this instance.
        Parameters:
        request - The request to execute.
        Returns:
        Closeable response from the server.
        Throws:
        java.io.IOException - On network error.
      • getFinalLocation

        public java.net.URI getFinalLocation()
        Returns:
        The final URL after redirects for the last processed request. Original URL if no redirects were performed. Null if no requests have been executed. Undefined state if last request threw an exception.
      • getContext

        public org.apache.http.client.protocol.HttpClientContext getContext()
        Returns:
        Http client context used by this interface.
      • getHttpClient

        public org.apache.http.impl.client.CloseableHttpClient getHttpClient()
        Returns:
        Http client instance used by this instance.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException