Class AbstractHttpRestClientDecorator<B extends HttpRestClient>

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


    public abstract class AbstractHttpRestClientDecorator<B extends HttpRestClient>
    extends Object
    implements HttpRestClient
    Abstract class for easily decorating a HttpRestClient.
    • Method Detail

      • getOauthToken

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

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

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

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

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

        public void closeIn​(int aCloseInMillis)
        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
      • disableRequestCorrelation

        public void disableRequestCorrelation​()
        Specified by:
        disableRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<B extends HttpRestClient>
      • disableSessionCorrelation

        public void disableSessionCorrelation​()
        Specified by:
        disableSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<B extends HttpRestClient>
      • enableRequestCorrelation

        public void enableRequestCorrelation​()
        Specified by:
        enableRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<B extends HttpRestClient>
      • enableSessionCorrelation

        public void enableSessionCorrelation​()
        Specified by:
        enableSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<B extends HttpRestClient>
      • getBaseUrl

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

        public org.refcodes.net.MediaType[] getFactoryMediaTypes​()
        Specified by:
        getFactoryMediaTypes in interface org.refcodes.net.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.net.UserAgentAccessor
      • hasMediaTypeFactory

        public boolean hasMediaTypeFactory​(org.refcodes.net.MediaType aMediaType)
        Specified by:
        hasMediaTypeFactory in interface org.refcodes.net.MediaTypeFactoryLookup
      • hasRequestCorrelation

        public boolean hasRequestCorrelation​()
        Specified by:
        hasRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<B extends HttpRestClient>
      • hasSessionCorrelation

        public boolean hasSessionCorrelation​()
        Specified by:
        hasSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<B extends HttpRestClient>
      • open

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

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

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

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

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

        public void setRequestCorrelation​(boolean hasRequestCorrelation)
        Specified by:
        setRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<B extends HttpRestClient>
      • setSessionCorrelation

        public void setSessionCorrelation​(boolean hasSessionCorrelation)
        Specified by:
        setSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<B extends HttpRestClient>
      • setTrustStoreDescriptor

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

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

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

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

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

        public RestRequestBuilder buildRequest​(org.refcodes.net.HttpMethod aHttpMethod,
                                               org.refcodes.net.Url aUrl,
                                               org.refcodes.net.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.net.HttpMethod aHttpMethod,
                                      org.refcodes.net.Url aUrl,
                                      org.refcodes.net.RequestHeaderFields aHeaderFields,
                                      Object aRequest,
                                      int aRedirectDepth)
                               throws org.refcodes.net.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.net.HttpResponseException - thrown in case of some unexpected response.
      • doRequest

        public RestCallerBuilder doRequest​(org.refcodes.net.HttpMethod aHttpMethod,
                                           org.refcodes.net.Url aUrl,
                                           org.refcodes.net.RequestHeaderFields aHeaderFields,
                                           Object aRequest,
                                           int aRedirectDepth,
                                           RestResponseObserver aResponseObserver)
        Creates a request with the possible attributes and returns the according RestCallerBuilder instance used for the request. The HTTP-Request is actually sent not earlier than you calling Openable.open() on the returned RestCallerBuilder as the RestCallerBuilder still may be modified after invoking this method!
        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.
        aResponseObserver - The listener processing a response targeted at this RestCallerBuilder.
        Returns:
        The RestCallerBuilder which is used by the request.
      • toUrl

        protected org.refcodes.net.Url toUrl​(org.refcodes.net.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.