Class MultithreadedHttpClient

Object
AbstractHttpClient
MultithreadedHttpClient
All Implemented Interfaces:
Closeable, AutoCloseable, HTTPBehavior, HTTPClient, HTTPConnectionPooling, HTTPProxy

public class MultithreadedHttpClient extends AbstractHttpClient implements HTTPConnectionPooling, HTTPProxy
An Apache commons HTTP client based HTTPClient backed by a multithreaded connection manager that allows to reuse connections to the backing server and to limit the max number of concurrent connections.

Java System properties http.proxyHost, http.proxyPort, http.proxyUser, and http.proxyPassword are respected.

Copied from gt-wms.

Author:
groldan, awaterme
See Also:
  • Constructor Details

    • MultithreadedHttpClient

      public MultithreadedHttpClient()
  • Method Details

    • post

      public MultithreadedHttpClient.HttpMethodResponse post(URL url, InputStream postContent, String postContentType) throws IOException
      Description copied from interface: HTTPClient
      Executes an HTTP POST request against the provided URL, sending the contents of postContent as the POST method body and setting the Content-Type request header to postContentType if given, and returns the server response.

      If an HTTP authentication user and password is set, the appropriate authentication HTTP header will be sent with the request.

      If a connection timeout is set, the http connection will be set to respect that timeout.

      If a read timeout is set, the http connection will be set to respect it.

      Specified by:
      post in interface HTTPClient
      Specified by:
      post in class AbstractHttpClient
      Parameters:
      url - the URL against which to execute the POST request
      postContent - an input stream with the contents of the POST body
      postContentType - the MIME type of the contents sent as the request POST body, can be null
      Returns:
      the HTTPResponse encapsulating the response to the HTTP POST request
      Throws:
      IOException
    • post

      public MultithreadedHttpClient.HttpMethodResponse post(URL url, InputStream postContent, String postContentType, Map<String,String> headers) throws IOException
      Description copied from interface: HTTPClient
      Executes an HTTP POST request against the provided URL, sending the contents of postContent as the POST method body and setting the Content-Type request header to postContentType if given, and returns the server response.

      If an HTTP authentication user and password is set, the appropriate authentication HTTP header will be sent with the request.

      If a connection timeout is set, the http connection will be set to respect that timeout.

      If a read timeout is set, the http connection will be set to respect it.

      header parameter contains additional headers to add to the request.

      Specified by:
      post in interface HTTPClient
      Parameters:
      url - the URL against which to execute the POST request
      postContent - an input stream with the contents of the POST body
      postContentType - the MIME type of the contents sent as the request POST body, can be null
      headers - a list of custom headers to add to the request.
      Returns:
      the HTTPResponse encapsulating the response to the HTTP POST request
      Throws:
      IOException
    • get

      public HTTPResponse get(URL url) throws IOException
      Description copied from interface: HTTPClient
      Executes an HTTP GET request against the provided URL and returns the server response.

      If an HTTP authentication user and password is set, the appropriate authentication HTTP header will be sent with the request.

      If a connection timeout is set, the http connection will be set to respect that timeout.

      If a read timeout is set, the http connection will be set to respect it.

      Specified by:
      get in interface HTTPClient
      Parameters:
      url - the URL to retrieve
      Returns:
      an HTTPResponse encapsulating the response to the HTTP GET request
      Throws:
      IOException
    • get

      public HTTPResponse get(URL url, Map<String,String> headers) throws IOException
      Description copied from interface: HTTPClient
      Executes an HTTP GET request against the provided URL and returns the server response.

      If an HTTP authentication user and password is set, the appropriate authentication HTTP header will be sent with the request.

      If a connection timeout is set, the http connection will be set to respect that timeout.

      If a read timeout is set, the http connection will be set to respect it.

      header parameter contains additional headers to add to the request.

      Specified by:
      get in interface HTTPClient
      Parameters:
      url - the URL to retrieve
      headers - a list of custom headers to add to the request.
      Returns:
      an HTTPResponse encapsulating the response to the HTTP GET request
      Throws:
      IOException
    • setUser

      public void setUser(String user)
      Specified by:
      setUser in interface HTTPClient
      Overrides:
      setUser in class AbstractHttpClient
      Parameters:
      user - the HTTP BASIC Authentication user name
    • setPassword

      public void setPassword(String password)
      Specified by:
      setPassword in interface HTTPClient
      Overrides:
      setPassword in class AbstractHttpClient
      Parameters:
      password - the HTTP BASIC Authentication password
    • getConnectTimeout

      public int getConnectTimeout()
      Specified by:
      getConnectTimeout in interface HTTPClient
      Overrides:
      getConnectTimeout in class AbstractHttpClient
      Returns:
      the tcp/ip connect timeout in seconds
    • setConnectTimeout

      public void setConnectTimeout(int connectTimeout)
      Specified by:
      setConnectTimeout in interface HTTPClient
      Overrides:
      setConnectTimeout in class AbstractHttpClient
      Parameters:
      connectTimeout - tcp/ip connect timeout in seconds
    • getReadTimeout

      public int getReadTimeout()
      Specified by:
      getReadTimeout in interface HTTPClient
      Overrides:
      getReadTimeout in class AbstractHttpClient
      Returns:
      the socket read timeout in seconds
    • setReadTimeout

      public void setReadTimeout(int readTimeout)
      Specified by:
      setReadTimeout in interface HTTPClient
      Overrides:
      setReadTimeout in class AbstractHttpClient
      Parameters:
      readTimeout - socket read timeout in seconds
    • getMaxConnections

      public int getMaxConnections()
      Description copied from interface: HTTPConnectionPooling
      Max connections kept in the pool
      Specified by:
      getMaxConnections in interface HTTPConnectionPooling
      Returns:
    • setMaxConnections

      public void setMaxConnections(int maxConnections)
      Description copied from interface: HTTPConnectionPooling
      Sets max connections kept in the pool
      Specified by:
      setMaxConnections in interface HTTPConnectionPooling
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable