Class AbstractRestfulHttpClientDecorator<B extends RestfulHttpClient>

java.lang.Object
org.refcodes.rest.AbstractRestfulHttpClientDecorator<B>
Type Parameters:
B - the generic type
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:
AbstractRestfulHttpDiscoveryClientDecorator

public abstract class AbstractRestfulHttpClientDecorator<B extends RestfulHttpClient> extends Object implements RestfulHttpClient
Abstract class for easily decorating a RestfulHttpClient.
  • Field Details

  • Constructor Details

  • Method Details

    • getOauthToken

      public org.refcodes.web.OauthToken getOauthToken()
      Specified by:
      getOauthToken in interface org.refcodes.web.OauthTokenAccessor
    • setOauthToken

      public void setOauthToken(org.refcodes.web.OauthToken aOauthToken)
      Specified by:
      setOauthToken in interface org.refcodes.web.OauthTokenAccessor.OauthTokenMutator
    • getConnectionStatus

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

      public boolean addMediaTypeFactory(org.refcodes.web.MediaTypeFactory aMediaTypeFactory)
      Specified by:
      addMediaTypeFactory in interface org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
    • close

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

      public void closeIn(int aCloseMillis)
      Specified by:
      closeIn in interface org.refcodes.component.Closable
    • closeQuietly

      public void closeQuietly()
      Specified by:
      closeQuietly in interface org.refcodes.component.Closable
    • closeUnchecked

      public void closeUnchecked()
      Specified by:
      closeUnchecked in interface org.refcodes.component.Closable
    • getBaseUrl

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

      public org.refcodes.web.MediaType[] getFactoryMediaTypes()
      Specified by:
      getFactoryMediaTypes in interface org.refcodes.web.MediaTypeFactoryLookup
    • getTrustStoreDescriptor

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

      public String getUserAgent()
      Specified by:
      getUserAgent in interface org.refcodes.web.UserAgentAccessor
    • hasMediaTypeFactory

      public boolean hasMediaTypeFactory(org.refcodes.web.MediaType aMediaType)
      Specified by:
      hasMediaTypeFactory in interface org.refcodes.web.MediaTypeFactoryLookup
    • open

      public void open() throws IOException
      Specified by:
      open in interface org.refcodes.component.Openable
      Specified by:
      open in interface RestfulHttpClient
      Throws:
      IOException
    • 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.
    • openUnchecked

      public void openUnchecked()
      Specified by:
      openUnchecked in interface org.refcodes.component.Openable
    • setBaseUrl

      public void setBaseUrl(org.refcodes.data.Scheme aProtocol, String aHost) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(org.refcodes.data.Scheme aProtocol, String aHost, int aPort) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(org.refcodes.data.Scheme aProtocol, String aHost, int aPort, String aPath) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(org.refcodes.data.Scheme aProtocol, String aHost, String aPath) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(String aBaseUrl) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(String aProtocol, String aHost) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(String aProtocol, String aHost, int aPort) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(String aProtocol, String aHost, int aPort, String aPath) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • setBaseUrl

      public void setBaseUrl(String aProtocol, String aHost, String aPath) throws MalformedURLException
      Specified by:
      setBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlMutator
      Throws:
      MalformedURLException
    • 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
    • setUserAgent

      public void setUserAgent(String aUserAgent)
      Specified by:
      setUserAgent in interface org.refcodes.web.UserAgentAccessor.UserAgentMutator
    • toMediaTypeFactory

      public org.refcodes.web.MediaTypeFactory toMediaTypeFactory(org.refcodes.web.MediaType aMediaType)
      Specified by:
      toMediaTypeFactory in interface org.refcodes.web.MediaTypeFactoryLookup
    • withBaseUrl

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

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

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

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

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

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

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

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

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

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

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

      public B withUserAgent(String aUserAgent)
      Specified by:
      withUserAgent in interface RestfulHttpClient
      Specified by:
      withUserAgent in interface org.refcodes.web.UserAgentAccessor.UserAgentBuilder<B extends RestfulHttpClient>
    • buildRequest

      public RestRequestBuilder buildRequest(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth)
      Prepares a request builder with the possible attributes and returns the according request's RestRequestBuilder instance. Invoking RestRequestBuilder.toRestResponse() starts the request and synchronously returns the response.
      Specified by:
      buildRequest in interface RestRequestClient
      Parameters:
      aHttpMethod - The HTTP-Method for the request.
      aUrl - The Url from which to take the URL specific data.
      aHeaderFields - The HTTP-Header's fields to be used for the request.
      aRequest - The body to be sent with the request (e.g. when doing a HttpMethod.POST request.
      aRedirectDepth - The number of redirect ping-pong cycles to follow before when issuing the HTTP-Request.
      Returns:
      The RestRequestBuilder at this request.
    • doRequest

      public RestResponse doRequest(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth) throws org.refcodes.web.HttpResponseException
      Sends a request with the possible attributes and returns the according request's RestResponse instance synchronously.
      Specified by:
      doRequest in interface RestRequestClient
      Parameters:
      aHttpMethod - The HTTP-Method for the request.
      aUrl - The Url from which to take the URL specific data.
      aHeaderFields - The HTTP-Header's fields to be used for the request.
      aRequest - The body to be sent with the request (e.g. when doing a HttpMethod.POST request.
      aRedirectDepth - The redirect depth provides the count of HTTP-Request and HTTP-Response cycles where the response represents a redirect as of HttpStatusCode.isRedirectStatus(). A value of -1 represents the default behavior, e.g. using HttpURLConnection's redirection means.
      Returns:
      The RestResponse for this request.
      Throws:
      org.refcodes.web.HttpResponseException - thrown in case of some unexpected response.
    • onResponse

      public RestResponseHandler onResponse(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer)
      Creates a request with the possible attributes and returns the according RestResponseHandler instance used for the request. The HTTP-Request is actually sent not earlier than you calling RestResponseHandler.open() on the returned RestResponseHandler as the RestResponseHandler still may be modified after invoking this method!
      Specified by:
      onResponse in interface RestRequestClient
      Parameters:
      aHttpMethod - The HTTP-Method for the request.
      aUrl - The Url from which to take the URL specific data.
      aHeaderFields - The HTTP-Header's fields to be used for the request.
      aRequest - The body to be sent with the request (e.g. when doing a HttpMethod.POST request.
      aRedirectDepth - The redirect depth provides the count of HTTP-Request and HTTP-Response cycles where the response represents a redirect as of HttpStatusCode.isRedirectStatus(). A value of -1 represents the default behavior, e.g. using HttpURLConnection's redirection means.
      aResponseConsumer - The listener processing a response targeted at this RestResponseHandler.
      Returns:
      The RestResponseHandler which is used by the request.
    • onResponse

      public RestResponseResult onResponse(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth)
      Creates a request with the possible attributes and returns the according RestResponseResult instance used for the request. The HTTP-Request is actually sent not earlier than you calling RestResponseResult.open() on the returned RestResponseResult as the RestResponseResult still may be modified after invoking this method!
      Specified by:
      onResponse in interface RestRequestClient
      Parameters:
      aHttpMethod - The HTTP-Method for the request.
      aUrl - The Url from which to take the URL specific data.
      aHeaderFields - The HTTP-Header's fields to be used for the request.
      aRequest - The body to be sent with the request (e.g. when doing a HttpMethod.POST request.
      aRedirectDepth - The redirect depth provides the count of HTTP-Request and HTTP-Response cycles where the response represents a redirect as of HttpStatusCode.isRedirectStatus(). A value of -1 represents the default behavior, e.g. using HttpURLConnection's redirection means.
      Returns:
      The RestResponseResult which is used by the request.
    • hasPreHttpInterceptor

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

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

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

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

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

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

      protected org.refcodes.web.Url toUrl(org.refcodes.web.Url aUrl)
      Hook for sub-classes to modify the request URL.
      Parameters:
      aUrl - The Url for the request.
      Returns:
      The tinkered Url, by default it returns the provided Url unmodified.