Class HttpRestClientImpl

  • All Implemented Interfaces:
    org.refcodes.component.Closable, org.refcodes.component.ConnectionComponent<org.refcodes.net.HttpClientContext>, org.refcodes.component.ConnectionOpenable<org.refcodes.net.HttpClientContext>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.LinkComponent, org.refcodes.component.Openable, org.refcodes.net.BaseUrlAccessor, org.refcodes.net.BaseUrlAccessor.BaseUrlBuilder<HttpRestClient>, org.refcodes.net.BaseUrlAccessor.BaseUrlMutator, org.refcodes.net.BaseUrlAccessor.BaseUrlProperty, org.refcodes.net.MediaTypeFactoryLookup, org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, org.refcodes.net.UserAgentAccessor, org.refcodes.net.UserAgentAccessor.UserAgentBuilder<RestClient>, org.refcodes.net.UserAgentAccessor.UserAgentMutator, org.refcodes.net.UserAgentAccessor.UserAgentProperty, HttpRestClient, RestClient, RestDeleteClient, RestGetClient, RestPostClient, RestPutClient, RestRequestClient, org.refcodes.runtime.RequestCorrelation<RestClient>, org.refcodes.runtime.SessionCorrelation<RestClient>, org.refcodes.security.TrustStoreDescriptorAccessor, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorBuilder<HttpRestClient>, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorMutator, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorProperty
    Direct Known Subclasses:
    HttpRestClientSingleton

    public class HttpRestClientImpl
    extends AbstractRestClient
    implements HttpRestClient
    The HttpRestClientImpl implements the HttpRestClient interface. The HttpRestClientImpl is being initialized with some common MediaTypeFactory instances (as implemented by the AbstractRestClient). At the time of writing this document the MediaTypeFactory instances being pre-configured are:
    • JsonMediaTypeFactory
    • XmlMediaTypeFactory
    • TextMediaTypeFactory
    • FormMediaTypeFactory
    The HttpRestClientImpl supports HTTP as well as HTTPS protocols as being based on the HttpURLConnection. For configuring HTTPS capabilities, refer to the methods such as open(Url, TrustStoreDescriptor) or open(Url, TrustStoreDescriptor).
    • Constructor Detail

      • HttpRestClientImpl

        public HttpRestClientImpl​(java.util.concurrent.ExecutorService aExecutorService)
        Constructs a HttpRestClientImpl. Use HttpRestClient.open() or similar to activate it.
        Parameters:
        aExecutorService - An executor service to be used when creating Threads.
    • Method Detail

      • setBaseUrl

        public void setBaseUrl​(java.net.URL aBaseUrl)
        Specified by:
        setBaseUrl in interface org.refcodes.net.BaseUrlAccessor.BaseUrlMutator
      • setTrustStoreDescriptor

        public void setTrustStoreDescriptor​(org.refcodes.security.TrustStoreDescriptor aStoreDescriptor)
        Specified by:
        setTrustStoreDescriptor in interface org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorMutator
      • withBaseUrl

        public HttpRestClient withBaseUrl​(org.refcodes.net.Url aBaseUrl)
        Specified by:
        withBaseUrl in interface org.refcodes.net.BaseUrlAccessor.BaseUrlBuilder<HttpRestClient>
      • withBaseUrl

        public HttpRestClient withBaseUrl​(java.net.URL aBaseURL)
        Specified by:
        withBaseUrl in interface org.refcodes.net.BaseUrlAccessor.BaseUrlBuilder<HttpRestClient>
      • close

        public void close()
                   throws org.refcodes.component.CloseException
        Specified by:
        close in interface org.refcodes.component.Closable
        Throws:
        org.refcodes.component.CloseException
      • getBaseUrl

        public org.refcodes.net.Url getBaseUrl()
        Specified by:
        getBaseUrl in interface org.refcodes.net.BaseUrlAccessor
      • getTrustStoreDescriptor

        public org.refcodes.security.TrustStoreDescriptor getTrustStoreDescriptor()
        Specified by:
        getTrustStoreDescriptor in interface org.refcodes.security.TrustStoreDescriptorAccessor
      • open

        public void open​(org.refcodes.net.Url aBaseUrl,
                         org.refcodes.security.TrustStoreDescriptor aStoreDescriptor)
                  throws org.refcodes.component.OpenException
        Configures the HTTPS client connection with the provided configuration parameters.
        Specified by:
        open in interface HttpRestClient
        Parameters:
        aBaseUrl - The base Url to be used.
        aStoreDescriptor - The TrustStoreDescriptor pointing to your KeyStore.
        Throws:
        org.refcodes.component.OpenException - thrown in case something went wrong.
      • setBaseUrl

        public void setBaseUrl​(org.refcodes.net.Url aBaseUrl)
        Specified by:
        setBaseUrl in interface org.refcodes.net.BaseUrlAccessor.BaseUrlMutator
      • getConnectionStatus

        public org.refcodes.component.ConnectionStatus getConnectionStatus()
        Specified by:
        getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessor
      • pipe

        protected static void pipe​(java.io.InputStream aInputStream,
                                   java.io.OutputStream aOutoutStream)
                            throws java.io.IOException
        Pipe.
        Parameters:
        aInputStream - the input stream
        aOutoutStream - the output stream
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.