Package org.refcodes.rest
Class AbstractRestClient
- java.lang.Object
-
- org.refcodes.rest.AbstractRestClient
-
- All Implemented Interfaces:
org.refcodes.net.MediaTypeFactoryLookup
,org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
,org.refcodes.net.OauthTokenAccessor
,org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<RestClient>
,org.refcodes.net.OauthTokenAccessor.OauthTokenMutator
,org.refcodes.net.OauthTokenAccessor.OauthTokenProperty
,org.refcodes.net.UserAgentAccessor
,org.refcodes.net.UserAgentAccessor.UserAgentBuilder<RestClient>
,org.refcodes.net.UserAgentAccessor.UserAgentMutator
,org.refcodes.net.UserAgentAccessor.UserAgentProperty
,RestClient
,RestDeleteClient
,RestGetClient
,RestPostClient
,RestPutClient
,RestRequestClient
,org.refcodes.runtime.RequestCorrelation<RestClient>
,org.refcodes.runtime.SessionCorrelation<RestClient>
- Direct Known Subclasses:
HttpRestClientImpl
,LoopbackRestClientImpl
public abstract class AbstractRestClient extends java.lang.Object implements RestClient
Abstract base implementation of theRestClient
interface being the foundation for variousRestClient
implementations such asHttpRestClientImpl
orLoopbackRestClientImpl
. TheAbstractRestClient
is pre-configured with the followingMediaTypeFactory
instances:JsonMediaTypeFactory
XmlMediaTypeFactory
TextMediaTypeFactory
FormMediaTypeFactory
initMedaTypeFactories()
, therein callingaddMediaTypeFactory(MediaTypeFactory)
to add (by also invoking super'sinitMedaTypeFactories()
) or to set your own (without invoking super'sinitMedaTypeFactories()
)MediaTypeFactory
instances.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.net.MediaTypeFactoryLookup
org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
-
Nested classes/interfaces inherited from interface org.refcodes.net.OauthTokenAccessor
org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<B extends org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder<B>>, org.refcodes.net.OauthTokenAccessor.OauthTokenMutator, org.refcodes.net.OauthTokenAccessor.OauthTokenProperty
-
Nested classes/interfaces inherited from interface org.refcodes.net.UserAgentAccessor
org.refcodes.net.UserAgentAccessor.UserAgentBuilder<B extends org.refcodes.net.UserAgentAccessor.UserAgentBuilder<B>>, org.refcodes.net.UserAgentAccessor.UserAgentMutator, org.refcodes.net.UserAgentAccessor.UserAgentProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_hasRequestCorrelation
protected boolean
_hasSessionCorrelation
-
Constructor Summary
Constructors Constructor Description AbstractRestClient()
Instantiates a new abstract rest client.AbstractRestClient(java.util.concurrent.ExecutorService aExecutorService)
Instantiates a new abstract rest client.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
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'sRestRequestBuilder
instance.RestResponse
doRequest(org.refcodes.net.HttpMethod aHttpMethod, org.refcodes.net.Url aUrl, org.refcodes.net.RequestHeaderFields aHeaderFields, java.lang.Object aRequest, int aRedirectDepth)
Sends a request with the possible attributes and returns the according request'sRestResponse
instance synchronously.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 accordingRestCallerBuilder
instance used for the request.protected void
doRequestCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields)
Do request correlation.protected void
doRequestCorrelation(org.refcodes.net.ResponseHeaderFields aResponseHeaderFields)
Do request correlation.protected void
doSessionCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields)
Do session correlation.protected void
doSessionCorrelation(org.refcodes.net.ResponseHeaderFields aResponseHeaderFields)
Do session correlation.org.refcodes.net.MediaType[]
getFactoryMediaTypes()
org.refcodes.net.OauthToken
getOauthToken()
java.lang.String
getUserAgent()
boolean
hasRequestCorrelation()
boolean
hasSessionCorrelation()
protected void
initMedaTypeFactories()
Adds the defaultMediaTypeFactory
instances.protected void
onRestRequest(RestRequestHandler aHandler)
Sets the hook receiving a preparedRestCallerBuilder
instance to be used to do the technical request with the technology chosen by the implementing sub-class.void
setOauthToken(org.refcodes.net.OauthToken aOauthToken)
void
setRequestCorrelation(boolean hasRequestCorrelation)
void
setSessionCorrelation(boolean hasSessionCorrelation)
void
setUserAgent(java.lang.String aUserAgent)
org.refcodes.net.MediaTypeFactory
toMediaTypeFactory(org.refcodes.net.MediaType aMediaType)
-
Methods inherited from interface org.refcodes.net.OauthTokenAccessor.OauthTokenBuilder
withOAuthToken
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.runtime.RequestCorrelation
disableRequestCorrelation, enableRequestCorrelation
-
Methods inherited from interface org.refcodes.rest.RestClient
withDisableRequestCorrelation, withDisableSessionCorrelation, withEnableRequestCorrelation, withEnableSessionCorrelation, withRequestCorrelation, withSessionCorrelation, withUserAgent
-
Methods inherited from interface org.refcodes.rest.RestDeleteClient
buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete
-
Methods inherited from interface org.refcodes.rest.RestGetClient
buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet
-
Methods inherited from interface org.refcodes.rest.RestPostClient
buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost
-
Methods inherited from interface org.refcodes.rest.RestPutClient
buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut
-
Methods inherited from interface org.refcodes.rest.RestRequestClient
buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest
-
-
-
-
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 defaultMediaTypeFactory
instances. Can be overridden.
-
setOauthToken
public void setOauthToken(org.refcodes.net.OauthToken aOauthToken)
- Specified by:
setOauthToken
in interfaceorg.refcodes.net.OauthTokenAccessor.OauthTokenMutator
-
getOauthToken
public org.refcodes.net.OauthToken getOauthToken()
- Specified by:
getOauthToken
in interfaceorg.refcodes.net.OauthTokenAccessor
-
setRequestCorrelation
public void setRequestCorrelation(boolean hasRequestCorrelation)
- Specified by:
setRequestCorrelation
in interfaceorg.refcodes.runtime.RequestCorrelation<RestClient>
-
hasRequestCorrelation
public boolean hasRequestCorrelation()
- Specified by:
hasRequestCorrelation
in interfaceorg.refcodes.runtime.RequestCorrelation<RestClient>
-
setSessionCorrelation
public void setSessionCorrelation(boolean hasSessionCorrelation)
- Specified by:
setSessionCorrelation
in interfaceorg.refcodes.runtime.SessionCorrelation<RestClient>
-
hasSessionCorrelation
public boolean hasSessionCorrelation()
- Specified by:
hasSessionCorrelation
in interfaceorg.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'sRestResponse
instance synchronously.- Specified by:
doRequest
in interfaceRestRequestClient
- Parameters:
aHttpMethod
- The HTTP-Method for the request.aUrl
- TheUrl
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 aHttpMethod.POST
request.aRedirectDepth
- The redirect depth provides the count of HTTP-Request and HTTP-Response cycles where the response represents a redirect as ofHttpStatusCode.isRedirectStatus()
. A value of -1 represents the default behavior, e.g. usingHttpURLConnection
'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 accordingRestCallerBuilder
instance used for the request. The HTTP-Request is actually sent not earlier than you callingOpenable.open()
on the returnedRestCallerBuilder
as theRestCallerBuilder
still may be modified after invoking this method!- Specified by:
doRequest
in interfaceRestRequestClient
- Parameters:
aHttpMethod
- The HTTP-Method for the request.aUrl
- TheUrl
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 aHttpMethod.POST
request.aRedirectDepth
- The redirect depth provides the count of HTTP-Request and HTTP-Response cycles where the response represents a redirect as ofHttpStatusCode.isRedirectStatus()
. A value of -1 represents the default behavior, e.g. usingHttpURLConnection
's redirection means.aResponseObserver
- The listener processing a response targeted at thisRestCallerBuilder
.- 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'sRestRequestBuilder
instance. InvokingRestRequestBuilder.toRestResponse()
starts the request and synchronously returns the response.- Specified by:
buildRequest
in interfaceRestRequestClient
- Parameters:
aHttpMethod
- The HTTP-Method for the request.aUrl
- TheUrl
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 aHttpMethod.POST
request.- Returns:
- The
RestRequestBuilder
at this request.
-
addMediaTypeFactory
public boolean addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
- Specified by:
addMediaTypeFactory
in interfaceorg.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
-
toMediaTypeFactory
public org.refcodes.net.MediaTypeFactory toMediaTypeFactory(org.refcodes.net.MediaType aMediaType)
- Specified by:
toMediaTypeFactory
in interfaceorg.refcodes.net.MediaTypeFactoryLookup
-
getFactoryMediaTypes
public org.refcodes.net.MediaType[] getFactoryMediaTypes()
- Specified by:
getFactoryMediaTypes
in interfaceorg.refcodes.net.MediaTypeFactoryLookup
-
getUserAgent
public java.lang.String getUserAgent()
- Specified by:
getUserAgent
in interfaceorg.refcodes.net.UserAgentAccessor
-
setUserAgent
public void setUserAgent(java.lang.String aUserAgent)
- Specified by:
setUserAgent
in interfaceorg.refcodes.net.UserAgentAccessor.UserAgentMutator
-
onRestRequest
protected void onRestRequest(RestRequestHandler aHandler)
Sets the hook receiving a preparedRestCallerBuilder
instance to be used to do the technical request with the technology chosen by the implementing sub-class.- Parameters:
aHandler
- TheRestRequestHandler
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
-
-