Class HttpConnectionManager

java.lang.Object
net.sf.basedb.util.uri.http.HttpConnectionManager
All Implemented Interfaces:
ConnectionManager, ResumableConnectionManager

public class HttpConnectionManager extends Object implements ResumableConnectionManager
Connection manager implementation that support HTTP and HTTPS URI:s. It supports Basic and Digest authentication schemes. When HTTPS is used it provides support for validation of both server- and client-side certificates.
Since:
3.0
Author:
Nicklas
Last modified
$Date: 2017-10-13 13:40:38 +0200 (fr, 13 okt 2017) $
  • Field Details

    • uri

      private final URI uri
    • parameters

      private final ConnectionParameters parameters
    • metadata

      private UriMetadata metadata
    • responseFilter

      private Filter<org.apache.http.HttpResponse> responseFilter
    • timeout

      private int timeout
  • Constructor Details

  • Method Details

    • getURI

      public URI getURI()
      Description copied from interface: ConnectionManager
      Get the URI of the resource we are interested in.
      Specified by:
      getURI in interface ConnectionManager
      Returns:
      An URI
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: ConnectionManager
      Get an InputStream for reading the contents of the resource.
      Specified by:
      getInputStream in interface ConnectionManager
      Returns:
      An InputStream object, or null if the no data is available
      Throws:
      IOException - If there is an error creating the stream
    • getInputStream

      public InputStream getInputStream(long offset) throws IOException
      Description copied from interface: ResumableConnectionManager
      Get an InputStream for reading the contents of the resource.
      Specified by:
      getInputStream in interface ResumableConnectionManager
      Parameters:
      offset - The offset to start reading from
      Returns:
      An InputStream object, or null if the no data is available
      Throws:
      IOException - If there is an error creating the stream
    • getMetadata

      public UriMetadata getMetadata() throws IOException
      Description copied from interface: ConnectionManager
      Get metadata about the resource. If no metadata can be obtained the handler should still create an empty UriMetadata object.
      Specified by:
      getMetadata in interface ConnectionManager
      Returns:
      A metadata object
      Throws:
      IOException - If there is an error getting the metadata
    • setResponseFilter

      public void setResponseFilter(Filter<org.apache.http.HttpResponse> filter)
      Set a filter that will inspect the response before an input stream is returned to the calling code. The filter must return true to allow the processing to proceed. A false value aborts the processing. The filter may also throw an exception.
      Since:
      3.12
    • setTimeout

      public void setTimeout(int timeoutInSeconds)
      Set a timeout in seconds to allocate for the request to return (not including downloading of data).
      Parameters:
      timeoutInSeconds - Timeout in seconds
      Since:
      3.12
    • createCloseableHttpClient

      public org.apache.http.impl.client.CloseableHttpClient createCloseableHttpClient(URI uri, ConnectionParameters parameters) throws IOException
      Get a HttpClient object that has been configured to access the given URI.
      Throws:
      IOException
    • createMetadata

      public UriMetadata createMetadata(URI uri, org.apache.http.HttpResponse response)
      Read metadata from the given http response and put the information in a UriMetadata object. This method uses whatever information that is in the response headers:
      • Content-Length: The length of the resource
      • Last-Modified: The last modified date
      • Content-Type: The MIME type and character set