Class AbstractHttpRestClientDecorator<B extends 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.OpenedAccessor, HttpRestClient, RestClient, RestDeleteClient, RestGetClient, RestPostClient, RestPutClient, RestRequestClient, RestRequestHandler, 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, org.refcodes.web.BaseUrlAccessor, org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<HttpRestClient>, org.refcodes.web.BaseUrlAccessor.BaseUrlMutator, org.refcodes.web.BaseUrlAccessor.BaseUrlProperty, org.refcodes.web.BasicAuthCredentialsAccessor, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestClient>, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, org.refcodes.web.BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty, org.refcodes.web.MediaTypeFactoryLookup, org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, org.refcodes.web.OauthTokenAccessor, org.refcodes.web.OauthTokenAccessor.OauthTokenBuilder<RestClient>, org.refcodes.web.OauthTokenAccessor.OauthTokenMutator, org.refcodes.web.OauthTokenAccessor.OauthTokenProperty, org.refcodes.web.UserAgentAccessor, org.refcodes.web.UserAgentAccessor.UserAgentBuilder<RestClient>, org.refcodes.web.UserAgentAccessor.UserAgentMutator, org.refcodes.web.UserAgentAccessor.UserAgentProperty
    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.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 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.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
      • 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​(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 HttpRestClient
        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,
                               int aPort)
                        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
      • 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 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.web.Url aBaseUrl)
        Specified by:
        withBaseUrl in interface org.refcodes.web.BaseUrlAccessor.BaseUrlBuilder<B extends HttpRestClient>
        Specified by:
        withBaseUrl in interface HttpRestClient
      • withBaseUrl

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

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

        public B withSessionCorrelation​(boolean hasSessionCorrelation)
        Specified by:
        withSessionCorrelation in interface HttpRestClient
        Specified by:
        withSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<B extends HttpRestClient>
      • 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.
      • 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.