Class HttpRestClient

All Implemented Interfaces:
org.refcodes.component.Closable, org.refcodes.component.ConnectionComponent<org.refcodes.web.HttpClientContext>, org.refcodes.component.ConnectionOpenable<org.refcodes.web.HttpClientContext>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.LinkComponent, org.refcodes.component.Openable, org.refcodes.component.Openable.OpenBuilder<RestfulHttpClient>, org.refcodes.component.OpenedAccessor, RestDeleteClient, RestfulClient, RestfulHttpClient, RestGetClient, RestPostClient, RestPutClient, RestRequestClient, RestRequestHandler, org.refcodes.security.TrustStoreDescriptorAccessor, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorBuilder<RestfulHttpClient>, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorMutator, org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorProperty, org.refcodes.web.BaseUrlAccessor, org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>, org.refcodes.web.BaseUrlAccessor.BaseUrlMutator, org.refcodes.web.BaseUrlAccessor.BaseUrlProperty, org.refcodes.web.BasicAuthCredentialsAccessor, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestfulClient>, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty, org.refcodes.web.HttpClientInterceptable, org.refcodes.web.MediaTypeFactoryLookup, org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, org.refcodes.web.OauthTokenAccessor, org.refcodes.web.OauthTokenAccessor.OauthTokenBuilder<RestfulClient>, org.refcodes.web.OauthTokenAccessor.OauthTokenMutator, org.refcodes.web.OauthTokenAccessor.OauthTokenProperty, org.refcodes.web.PostHttpClientInterceptable, org.refcodes.web.PostHttpInterceptable<org.refcodes.web.PostHttpClientInterceptor>, org.refcodes.web.PreHttpClientInterceptable, org.refcodes.web.PreHttpInterceptable<org.refcodes.web.PreHttpClientInterceptor>, org.refcodes.web.UserAgentAccessor, org.refcodes.web.UserAgentAccessor.UserAgentBuilder<RestfulClient>, org.refcodes.web.UserAgentAccessor.UserAgentMutator, org.refcodes.web.UserAgentAccessor.UserAgentProperty
Direct Known Subclasses:
HttpRestClientSingleton

public class HttpRestClient extends AbstractRestfulClient implements RestfulHttpClient
The HttpRestClient implements the RestfulHttpClient interface. The HttpRestClient is being initialized with some common MediaTypeFactory instances (as implemented by the AbstractRestfulClient). At the time of writing this document the MediaTypeFactory instances being preconfigured are:
  • JsonMediaTypeFactory
  • XmlMediaTypeFactory
  • TextMediaTypeFactory
  • FormMediaTypeFactory
  • HtmlMediaTypeFactory
The HttpRestClient 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 Details

  • Method Details

    • close

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

      public org.refcodes.web.Url getBaseUrl()
      Specified by:
      getBaseUrl in interface org.refcodes.web.BaseUrlAccessor
    • getConnectionStatus

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

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

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

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

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

      public void setTrustStoreDescriptor(org.refcodes.security.TrustStoreDescriptor aTrustStoreDescriptor)
      Specified by:
      setTrustStoreDescriptor in interface org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorMutator
    • hasPreHttpInterceptor

      public boolean hasPreHttpInterceptor(org.refcodes.web.PreHttpClientInterceptor aPreInterceptor)
      Specified by:
      hasPreHttpInterceptor in interface org.refcodes.web.PreHttpInterceptable<org.refcodes.web.PreHttpClientInterceptor>
    • addPreHttpInterceptor

      public boolean addPreHttpInterceptor(org.refcodes.web.PreHttpClientInterceptor aPreInterceptor)
      Specified by:
      addPreHttpInterceptor in interface org.refcodes.web.PreHttpInterceptable<org.refcodes.web.PreHttpClientInterceptor>
    • removePreHttpInterceptor

      public boolean removePreHttpInterceptor(org.refcodes.web.PreHttpClientInterceptor aPreInterceptor)
      Specified by:
      removePreHttpInterceptor in interface org.refcodes.web.PreHttpInterceptable<org.refcodes.web.PreHttpClientInterceptor>
    • hasPostHttpInterceptor

      public boolean hasPostHttpInterceptor(org.refcodes.web.PostHttpClientInterceptor aPostInterceptor)
      Specified by:
      hasPostHttpInterceptor in interface org.refcodes.web.PostHttpInterceptable<org.refcodes.web.PostHttpClientInterceptor>
    • addPostHttpInterceptor

      public boolean addPostHttpInterceptor(org.refcodes.web.PostHttpClientInterceptor aPostInterceptor)
      Specified by:
      addPostHttpInterceptor in interface org.refcodes.web.PostHttpInterceptable<org.refcodes.web.PostHttpClientInterceptor>
    • removePostHttpInterceptor

      public boolean removePostHttpInterceptor(org.refcodes.web.PostHttpClientInterceptor aPostInterceptor)
      Specified by:
      removePostHttpInterceptor in interface org.refcodes.web.PostHttpInterceptable<org.refcodes.web.PostHttpClientInterceptor>
    • withOpen

      public HttpRestClient withOpen() throws IOException
      Open the component's connection(s).
      Specified by:
      withOpen in interface org.refcodes.component.Openable.OpenBuilder<RestfulHttpClient>
      Specified by:
      withOpen in interface RestfulHttpClient
      Returns:
      This instance as of the builder pattern.
      Throws:
      IOException - Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
    • withOpen

      public HttpRestClient withOpen(org.refcodes.web.HttpClientContext aCtx) throws IOException
      Opens the component with the given connection.
      Specified by:
      withOpen in interface RestfulHttpClient
      Parameters:
      aCtx - The context used for opening the connection.
      Returns:
      This instance as of the builder pattern.
      Throws:
      IOException - Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
    • withOpen

      public HttpRestClient withOpen(org.refcodes.security.TrustStoreDescriptor aStoreDescriptor) throws IOException
      Configures the HTTPS client connection with the provided configuration parameters.
      Specified by:
      withOpen in interface RestfulHttpClient
      Parameters:
      aStoreDescriptor - The TrustStoreDescriptor pointing to your KeyStore.
      Returns:
      This instance as of the builder pattern.
      Throws:
      IOException - thrown in case something went wrong.
    • withOpen

      public HttpRestClient withOpen(org.refcodes.web.Url aBaseUrl) throws IOException
      Configures the HTTPS client connection with the provided configuration parameters.
      Specified by:
      withOpen in interface RestfulHttpClient
      Parameters:
      aBaseUrl - The base Url to be used.
      Returns:
      This instance as of the builder pattern.
      Throws:
      IOException - thrown in case something went wrong.
    • withOpen

      public HttpRestClient withOpen(org.refcodes.web.Url aBaseUrl, org.refcodes.security.TrustStoreDescriptor aStoreDescriptor) throws IOException
      Configures the HTTPS client connection with the provided configuration parameters.
      Specified by:
      withOpen in interface RestfulHttpClient
      Parameters:
      aBaseUrl - The base Url to be used.
      aStoreDescriptor - The TrustStoreDescriptor pointing to your KeyStore.
      Returns:
      This instance as of the builder pattern.
      Throws:
      IOException - thrown in case something went wrong.
    • withBaseUrl

      public HttpRestClient withBaseUrl(String aBaseUrl) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Specified by:
      withBaseUrl in interface RestfulHttpClient
      Throws:
      MalformedURLException
    • withBaseUrl

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

      public HttpRestClient withBaseUrl(URL aBaseURL)
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Specified by:
      withBaseUrl in interface RestfulHttpClient
    • withBasicAuthCredentials

      public HttpRestClient withBasicAuthCredentials(org.refcodes.web.BasicAuthCredentials aBasicAuthCredentials)
      Specified by:
      withBasicAuthCredentials in interface org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestfulClient>
      Specified by:
      withBasicAuthCredentials in interface RestfulHttpClient
    • withBasicAuthCredentials

      public HttpRestClient withBasicAuthCredentials(String aUserName, String aSecret)
      Specified by:
      withBasicAuthCredentials in interface org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestfulClient>
      Specified by:
      withBasicAuthCredentials in interface RestfulHttpClient
    • withOAuthToken

      public HttpRestClient withOAuthToken(org.refcodes.web.OauthToken aOauthToken)
      Specified by:
      withOAuthToken in interface org.refcodes.web.OauthTokenAccessor.OauthTokenBuilder<RestfulClient>
      Specified by:
      withOAuthToken in interface RestfulHttpClient
    • withTrustStoreDescriptor

      public HttpRestClient withTrustStoreDescriptor(org.refcodes.security.TrustStoreDescriptor aStoreDescriptor)
      Specified by:
      withTrustStoreDescriptor in interface RestfulHttpClient
      Specified by:
      withTrustStoreDescriptor in interface org.refcodes.security.TrustStoreDescriptorAccessor.TrustStoreDescriptorBuilder<RestfulHttpClient>
    • withUserAgent

      public HttpRestClient withUserAgent(String aUserAgent)
      Specified by:
      withUserAgent in interface RestfulHttpClient
      Specified by:
      withUserAgent in interface org.refcodes.web.UserAgentAccessor.UserAgentBuilder<RestfulClient>
    • withBaseUrl

      public HttpRestClient withBaseUrl(String aProtocol, String aHost) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(org.refcodes.data.Scheme aScheme, String aHost) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(String aProtocol, String aHost, String aPath) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(org.refcodes.data.Scheme aScheme, String aHost, String aPath) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(String aProtocol, String aHost, int aPort) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(org.refcodes.data.Scheme aScheme, String aHost, int aPort) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(String aProtocol, String aHost, int aPort, String aPath) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withBaseUrl

      public HttpRestClient withBaseUrl(org.refcodes.data.Scheme aScheme, String aHost, int aPort, String aPath) throws MalformedURLException
      Specified by:
      withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<RestfulHttpClient>
      Throws:
      MalformedURLException
    • withOpenUnchecked

      public HttpRestClient withOpenUnchecked()
      Specified by:
      withOpenUnchecked in interface org.refcodes.component.Openable.OpenBuilder<RestfulHttpClient>
    • pipe

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

      protected void preIntercept(org.refcodes.web.HttpClientRequest aRequest, org.refcodes.web.HttpClientResponse aResponse)
      Invoked to pre-process a HttpClientRequest alongside a HttpClientResponse.
      Overrides:
      preIntercept in class AbstractRestfulClient
      Parameters:
      aRequest - The HttpClientRequest to pre-process.
      aResponse - The HttpClientResponse to post-process.
    • postIntercept

      protected void postIntercept(org.refcodes.web.HttpClientRequest aRequest, org.refcodes.web.HttpClientResponse aResponse)
      Invoked to post-process a HttpClientRequest alongside a HttpClientResponse.
      Overrides:
      postIntercept in class AbstractRestfulClient
      Parameters:
      aRequest - The HttpClientRequest to post-process.
      aResponse - The HttpClientResponse to post-process.