Class DefaultResourceRetriever

    • Constructor Detail

      • DefaultResourceRetriever

        public DefaultResourceRetriever()
        Creates a new resource retriever. The HTTP timeouts and entity size limit are set to zero (infinite).
      • DefaultResourceRetriever

        public DefaultResourceRetriever​(int connectTimeout,
                                        int readTimeout)
        Creates a new resource retriever. The HTTP entity size limit is set to zero (infinite).
        Parameters:
        connectTimeout - The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.
        readTimeout - The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.
      • DefaultResourceRetriever

        public DefaultResourceRetriever​(int connectTimeout,
                                        int readTimeout,
                                        int sizeLimit)
        Creates a new resource retriever.
        Parameters:
        connectTimeout - The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.
        readTimeout - The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.
        sizeLimit - The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.
      • DefaultResourceRetriever

        public DefaultResourceRetriever​(int connectTimeout,
                                        int readTimeout,
                                        int sizeLimit,
                                        boolean disconnectAfterUse)
        Creates a new resource retriever.
        Parameters:
        connectTimeout - The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.
        readTimeout - The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.
        sizeLimit - The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.
        disconnectAfterUse - If true the disconnect method of the underlying HttpURLConnection will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of the keep.alive system property.
      • DefaultResourceRetriever

        public DefaultResourceRetriever​(int connectTimeout,
                                        int readTimeout,
                                        int sizeLimit,
                                        boolean disconnectAfterUse,
                                        SSLSocketFactory sslSocketFactory)
        Creates a new resource retriever.
        Parameters:
        connectTimeout - The HTTP connects timeout, in milliseconds, zero for infinite. Must not be negative.
        readTimeout - The HTTP read timeout, in milliseconds, zero for infinite. Must not be negative.
        sizeLimit - The HTTP entity size limit, in bytes, zero for infinite. Must not be negative.
        disconnectAfterUse - If true the disconnect method of the underlying HttpURLConnection will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of the keep.alive system property.
        sslSocketFactory - An SSLSocketFactory for establishing the TLS connections, null to use the default one.
    • Method Detail

      • disconnectsAfterUse

        public boolean disconnectsAfterUse()
        Returns true if the disconnect method of the underlying HttpURLConnection will be called after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of the keep.alive system property.
        Returns:
        If true the disconnect method of the underlying HttpURLConnection will be called after trying to retrieve the resource.
      • setDisconnectsAfterUse

        public void setDisconnectsAfterUse​(boolean disconnectAfterUse)
        Controls calling of the disconnect method the underlying HttpURLConnection after trying to retrieve the resource. Whether the TCP socket is actually closed or reused depends on the underlying HTTP implementation and the setting of the keep.alive system property. If true the disconnect method of the underlying HttpURLConnection will be called after trying to retrieve the resource.
      • getProxy

        public Proxy getProxy()
        Returns the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource. Note that the JVM may have a system wide proxy configured via the https.proxyHost Java system property.
        Returns:
        The proxy to use or null if no proxy should be used.
      • setProxy

        public void setProxy​(Proxy proxy)
        Sets the HTTP proxy to use when opening the HttpURLConnection to retrieve the resource. Note that the JVM may have a system wide proxy configured via the https.proxyHost Java system property.
        Parameters:
        proxy - The proxy to use or null if no proxy should be used.
      • retrieveResource

        public Resource retrieveResource​(URL url)
                                  throws IOException
        Description copied from interface: ResourceRetriever
        Retrieves the resource from the specified HTTP(S) URL.
        Specified by:
        retrieveResource in interface ResourceRetriever
        Parameters:
        url - The URL of the resource. Its scheme must be HTTP or HTTPS. Must not be null.
        Returns:
        The retrieved resource.
        Throws:
        IOException - If the HTTP connection to the specified URL failed or the resource couldn't be retrieved.
      • openConnection

        protected HttpURLConnection openConnection​(URL url)
                                            throws IOException
        Opens a connection the specified HTTP(S) URL. Uses the configured Proxy if available.
        Parameters:
        url - The URL of the resource. Its scheme must be HTTP or HTTPS. Must not be null.
        Returns:
        The opened HTTP(S) connection
        Throws:
        IOException - If the HTTP(S) connection to the specified URL failed.