Class AbstractHttpClient

  • All Implemented Interfaces:
    Direct Known Subclasses:
    MultithreadedHttpClient, SimpleHttpClient

    public abstract class AbstractHttpClient
    extends Object
    implements HTTPClient
    A base class for HTTPClient, that implements everything except the get and post methods.
    Andrea Aime - GeoSolutions
    • Field Detail

      • user

        protected String user
      • password

        protected String password
      • connectTimeout

        protected int connectTimeout
      • readTimeout

        protected int readTimeout
      • tryGzip

        protected boolean tryGzip
    • Constructor Detail

      • AbstractHttpClient

        public AbstractHttpClient()
    • Method Detail

      • getUser

        public String getUser()
        Specified by:
        getUser in interface HTTPClient
        the HTTP BASIC Authentication user name, or null if not set
      • setUser

        public void setUser​(String user)
        Specified by:
        setUser in interface HTTPClient
        user - the HTTP BASIC Authentication user name
      • getPassword

        public String getPassword()
        Specified by:
        getPassword in interface HTTPClient
        the HTTP BASIC Authentication password, or null if not set
      • setPassword

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

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

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

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

        public void setReadTimeout​(int readTimeout)
        Specified by:
        setReadTimeout in interface HTTPClient
        readTimeout - socket read timeout in seconds
      • isFile

        protected boolean isFile​(URL url)
      • createFileResponse

        protected HTTPResponse createFileResponse​(URL url)
                                           throws IOException
      • post

        public abstract HTTPResponse post​(URL url,
                                          InputStream content,
                                          String contentType)
                                   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
        url - the URL against which to execute the POST request
        content - an input stream with the contents of the POST body
        contentType - the MIME type of the contents sent as the request POST body, can be null
        the HTTPResponse encapsulating the response to the HTTP POST request