Class AbstractRestClient

    • Field Detail

      • _hasRequestCorrelation

        protected boolean _hasRequestCorrelation
      • _hasSessionCorrelation

        protected boolean _hasSessionCorrelation
    • Constructor Detail

      • AbstractRestClient

        public AbstractRestClient​(java.util.concurrent.ExecutorService aExecutorService)
        Instantiates a new abstract rest client.
        Parameters:
        aExecutorService - the executor service
      • AbstractRestClient

        public AbstractRestClient​()
        Instantiates a new abstract rest client.
    • Method Detail

      • initMedaTypeFactories

        protected void initMedaTypeFactories​()
        Adds the default MediaTypeFactory instances. Can be overridden.
      • setOauthToken

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

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

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

        public boolean hasRequestCorrelation​()
        Specified by:
        hasRequestCorrelation in interface org.refcodes.runtime.RequestCorrelation<RestClient>
      • setSessionCorrelation

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

        public boolean hasSessionCorrelation​()
        Specified by:
        hasSessionCorrelation in interface org.refcodes.runtime.SessionCorrelation<RestClient>
      • doRequest

        public RestResponse doRequest​(org.refcodes.net.HttpMethod aHttpMethod,
                                      org.refcodes.net.Url aUrl,
                                      org.refcodes.net.RequestHeaderFields aHeaderFields,
                                      java.lang.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,
                                           java.lang.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.
      • buildRequest

        public RestRequestBuilder buildRequest​(org.refcodes.net.HttpMethod aHttpMethod,
                                               org.refcodes.net.Url aUrl,
                                               org.refcodes.net.RequestHeaderFields aHeaderFields,
                                               java.lang.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.
      • addMediaTypeFactory

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

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

        public org.refcodes.net.MediaType[] getFactoryMediaTypes​()
        Specified by:
        getFactoryMediaTypes in interface org.refcodes.net.MediaTypeFactoryLookup
      • getUserAgent

        public java.lang.String getUserAgent​()
        Specified by:
        getUserAgent in interface org.refcodes.net.UserAgentAccessor
      • setUserAgent

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

        protected void onRestRequest​(RestRequestHandler aHandler)
        Sets the hook receiving a prepared RestCallerBuilder instance to be used to do the technical request with the technology chosen by the implementing sub-class.
        Parameters:
        aHandler - The RestRequestHandler for handling the HTTP request.
      • doRequestCorrelation

        protected void doRequestCorrelation​(org.refcodes.net.RequestHeaderFields aRequestHeaderFields)
        Do request correlation.
        Parameters:
        aRequestHeaderFields - the request Header-Fields
      • doSessionCorrelation

        protected void doSessionCorrelation​(org.refcodes.net.RequestHeaderFields aRequestHeaderFields)
        Do session correlation.
        Parameters:
        aRequestHeaderFields - the request Header-Fields
      • doRequestCorrelation

        protected void doRequestCorrelation​(org.refcodes.net.ResponseHeaderFields aResponseHeaderFields)
        Do request correlation.
        Parameters:
        aResponseHeaderFields - the response Header-Fields
      • doSessionCorrelation

        protected void doSessionCorrelation​(org.refcodes.net.ResponseHeaderFields aResponseHeaderFields)
        Do session correlation.
        Parameters:
        aResponseHeaderFields - the response Header-Fields