Class HTTPMetadataResolver

    • Field Detail

      • log

        @Nonnull
        private final org.slf4j.Logger log
        Class logger.
      • httpClient

        private org.apache.http.client.HttpClient httpClient
        HTTP Client used to pull the metadata.
      • metadataURI

        private URI metadataURI
        URL to the Metadata.
      • cachedMetadataETag

        private String cachedMetadataETag
        The ETag provided when the currently cached metadata was fetched.
      • cachedMetadataLastModified

        private String cachedMetadataLastModified
        The Last-Modified information provided when the currently cached metadata was fetched.
      • httpClientSecurityParameters

        @Nullable
        private HttpClientSecurityParameters httpClientSecurityParameters
        Optional HttpClient security parameters.
    • Constructor Detail

      • HTTPMetadataResolver

        public HTTPMetadataResolver​(org.apache.http.client.HttpClient client,
                                    String metadataURL)
                             throws ResolverException
        Constructor.
        Parameters:
        client - HTTP client used to pull in remote metadata
        metadataURL - URL to the remove remote metadata
        Throws:
        ResolverException - thrown if the HTTP client is null or the metadata URL provided is invalid
      • HTTPMetadataResolver

        public HTTPMetadataResolver​(Timer backgroundTaskTimer,
                                    org.apache.http.client.HttpClient client,
                                    String metadataURL)
                             throws ResolverException
        Constructor.
        Parameters:
        backgroundTaskTimer - timer used to schedule background metadata refresh tasks
        client - HTTP client used to pull in remote metadata
        metadataURL - URL to the remove remote metadata
        Throws:
        ResolverException - thrown if the HTTP client is null or the metadata URL provided is invalid
    • Method Detail

      • getMetadataURI

        public String getMetadataURI()
        Gets the URL to fetch the metadata.
        Returns:
        the URL to fetch the metadata
      • getHttpClientSecurityParameters

        @Nullable
        protected HttpClientSecurityParameters getHttpClientSecurityParameters()
        Get the instance of HttpClientSecurityParameters which provides various parameters to influence the security behavior of the HttpClient instance.
        Returns:
        the parameters instance, or null
      • setHttpClientSecurityParameters

        public void setHttpClientSecurityParameters​(@Nullable
                                                    HttpClientSecurityParameters params)
        Set an instance of HttpClientSecurityParameters which provides various parameters to influence the security behavior of the HttpClient instance.

        For all TLS-related parameters, must be used in conjunction with an HttpClient instance which is configured with either a:

        For convenience methods for building a TLSSocketFactory, see HttpClientSupport.

        If the appropriate TLS socket factory is not configured and a trust engine is specified, then this will result in no TLS trust evaluation being performed and a ResolverException will ultimately be thrown.

        Parameters:
        params - the security parameters
      • getMetadataIdentifier

        protected String getMetadataIdentifier()
        Gets an identifier which may be used to distinguish this metadata in logging statements.
        Specified by:
        getMetadataIdentifier in class AbstractReloadingMetadataResolver
        Returns:
        identifier which may be used to distinguish this metadata in logging statements
      • fetchMetadata

        protected byte[] fetchMetadata()
                                throws ResolverException
        Gets the metadata document from the remote server.
        Specified by:
        fetchMetadata in class AbstractReloadingMetadataResolver
        Returns:
        the metadata from remote server, or null if the metadata document has not changed since the last retrieval
        Throws:
        ResolverException - thrown if there is a problem retrieving the metadata from the remote server
      • buildHttpGet

        protected org.apache.http.client.methods.HttpGet buildHttpGet()
        Builds the HttpGet instance used to fetch the metadata. The returned method advertises support for GZIP and deflate compression, enables conditional GETs if the cached metadata came with either an ETag or Last-Modified information, and sets up basic authentication if such is configured.
        Returns:
        the constructed HttpGet instance
      • buildHttpClientContext

        protected org.apache.http.client.protocol.HttpClientContext buildHttpClientContext​(@Nonnull
                                                                                           org.apache.http.client.methods.HttpUriRequest request)
        Build the HttpClientContext instance which will be used to invoke the HttpClient request.
        Parameters:
        request - the current HTTP request
        Returns:
        a new instance of HttpClientContext
      • processConditionalRetrievalHeaders

        protected void processConditionalRetrievalHeaders​(org.apache.http.HttpResponse response)
        Records the ETag and Last-Modified headers, from the response, if they are present.
        Parameters:
        response - GetMethod containing a valid HTTP response
      • getMetadataBytesFromResponse

        protected byte[] getMetadataBytesFromResponse​(org.apache.http.HttpResponse response)
                                               throws ResolverException
        Extracts the raw metadata bytes from the response taking in to account possible deflate and GZip compression.
        Parameters:
        response - GetMethod containing a valid HTTP response
        Returns:
        the raw metadata bytes
        Throws:
        ResolverException - thrown if there is a problem getting the raw metadata bytes from the response