Class HttpClientHandler

    • Field Detail

      • LAST_MODIFIED_FORMAT

        private static final java.text.SimpleDateFormat LAST_MODIFIED_FORMAT
      • httpClient

        private final org.apache.http.impl.client.CloseableHttpClient httpClient
    • Constructor Detail

      • HttpClientHandler

        public HttpClientHandler()
    • Method Detail

      • buildUnderlyingClient

        private org.apache.http.impl.client.CloseableHttpClient buildUnderlyingClient()
      • createProxyRoutePlanner

        private static org.apache.http.conn.routing.HttpRoutePlanner createProxyRoutePlanner()
      • createAuthSchemeRegistry

        private static org.apache.http.config.Lookup<org.apache.http.auth.AuthSchemeProvider> createAuthSchemeRegistry()
      • createConnectionManager

        private static org.apache.http.conn.HttpClientConnectionManager createConnectionManager()
      • getAuthSchemePreferredOrder

        private static java.util.List<java.lang.String> getAuthSchemePreferredOrder()
      • openStream

        public java.io.InputStream openStream​(java.net.URL url)
                                       throws java.io.IOException
        Specified by:
        openStream in interface URLHandler
        Parameters:
        url - ditto
        Returns:
        InputStream
        Throws:
        java.io.IOException - if something goes wrong
      • openStream

        public java.io.InputStream openStream​(java.net.URL url,
                                              TimeoutConstraint timeoutConstraint)
                                       throws java.io.IOException
        Description copied from interface: TimeoutConstrainedURLHandler
        Opens and returns an InputStream to the passed url.
        Specified by:
        openStream in interface TimeoutConstrainedURLHandler
        Parameters:
        url - The URL to which an InputStream has to be opened
        timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
        Returns:
        InputStream
        Throws:
        java.io.IOException - if something goes wrong
      • download

        public void download​(java.net.URL src,
                             java.io.File dest,
                             CopyProgressListener l)
                      throws java.io.IOException
        Specified by:
        download in interface URLHandler
        Parameters:
        src - URL
        dest - File
        l - CopyProgressListener
        Throws:
        java.io.IOException - if something goes wrong
      • download

        public void download​(java.net.URL src,
                             java.io.File dest,
                             CopyProgressListener listener,
                             TimeoutConstraint timeoutConstraint)
                      throws java.io.IOException
        Description copied from interface: TimeoutConstrainedURLHandler
        Downloads the resource available at src to the target dest
        Specified by:
        download in interface TimeoutConstrainedURLHandler
        Parameters:
        src - The source URL to download the resource from
        dest - The destination File to download the resource to
        listener - The listener that will be notified of the download progress
        timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
        Throws:
        java.io.IOException - if something goes wrong
      • upload

        public void upload​(java.io.File src,
                           java.net.URL dest,
                           CopyProgressListener l)
                    throws java.io.IOException
        Specified by:
        upload in interface URLHandler
        Parameters:
        src - File
        dest - URL
        l - CopyProgressListener
        Throws:
        java.io.IOException - if something goes wrong
      • upload

        public void upload​(java.io.File src,
                           java.net.URL dest,
                           CopyProgressListener listener,
                           TimeoutConstraint timeoutConstraint)
                    throws java.io.IOException
        Description copied from interface: TimeoutConstrainedURLHandler
        Uploads the src File to the target dest URL
        Specified by:
        upload in interface TimeoutConstrainedURLHandler
        Parameters:
        src - The source File to upload
        dest - The target URL where the File has to be uploaded
        listener - The listener that will be notified of the upload progress
        timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
        Throws:
        java.io.IOException - if something goes wrong
      • getURLInfo

        public URLHandler.URLInfo getURLInfo​(java.net.URL url)
        Specified by:
        getURLInfo in interface URLHandler
        Parameters:
        url - The url from which information is retrieved.
        Returns:
        The URLInfo extracted from the given url, or URLHandler.UNAVAILABLE instance when the url is not reachable.
      • getURLInfo

        public URLHandler.URLInfo getURLInfo​(java.net.URL url,
                                             int timeout)
        Specified by:
        getURLInfo in interface URLHandler
        Parameters:
        url - The url from which information is retrieved.
        timeout - The timeout in milliseconds.
        Returns:
        The URLInfo extracted from the given url, or URLHandler.UNAVAILABLE when the url is not reachable, never null.
      • getContentLength

        public long getContentLength​(java.net.URL url,
                                     TimeoutConstraint timeoutConstraint)
        Description copied from interface: TimeoutConstrainedURLHandler
        Returns the number of bytes of data that's available for the resource at the passed url. Returns 0 if the passed url isn't reachable
        Specified by:
        getContentLength in interface TimeoutConstrainedURLHandler
        Parameters:
        url - The URL to access
        timeoutConstraint - The connectivity timeout constraints. Can be null, in which case the timeouts are implementation specific
        Returns:
        long
      • checkStatusCode

        private boolean checkStatusCode​(java.lang.String httpMethod,
                                        java.net.URL sourceURL,
                                        org.apache.http.HttpResponse response)
      • requireSuccessStatus

        private void requireSuccessStatus​(java.lang.String httpMethod,
                                          java.net.URL sourceURL,
                                          org.apache.http.client.methods.CloseableHttpResponse response)
                                   throws java.io.IOException
        Checks the status code of the response and if it's considered as successful response, then this method just returns back. Else it closes the response and throws an IOException for the unsuccessful response.
        Parameters:
        httpMethod - The HTTP method that was used for the source request
        sourceURL - The URL of the source request
        response - The response to the source request
        Throws:
        java.io.IOException - Thrown if the response was considered unsuccessful
      • getContentEncoding

        private org.apache.http.Header getContentEncoding​(org.apache.http.HttpResponse response)
      • getLastModified

        private long getLastModified​(org.apache.http.HttpResponse response)
      • doGet

        private org.apache.http.client.methods.CloseableHttpResponse doGet​(java.net.URL url,
                                                                           int connectionTimeout,
                                                                           int readTimeout)
                                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • doHead

        private org.apache.http.client.methods.CloseableHttpResponse doHead​(java.net.URL url,
                                                                            int connectionTimeout,
                                                                            int readTimeout)
                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • hasCredentialsConfigured

        private boolean hasCredentialsConfigured​(java.net.URL url)
      • close

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