- java.lang.Object
-
- org.refcodes.web.HttpRequestImpl
-
- org.refcodes.web.HttpClientRequestImpl
-
- org.refcodes.rest.RestResponseHandler
-
- All Implemented Interfaces:
org.refcodes.component.Closable,org.refcodes.component.Closable.CloseBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>,org.refcodes.component.ConnectionStatusAccessor,org.refcodes.component.LinkComponent,org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>,org.refcodes.component.Openable,org.refcodes.component.Openable.OpenBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>,org.refcodes.component.OpenedAccessor,RestResponseConsumer,org.refcodes.web.HeaderFieldsAccessor<org.refcodes.web.RequestHeaderFields>,org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsBuilder<org.refcodes.web.RequestHeaderFields,RestResponseHandler>,org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsMutator<org.refcodes.web.RequestHeaderFields>,org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsProperty<org.refcodes.web.RequestHeaderFields>,org.refcodes.web.HttpBodyAccessor.HttpBodyProvider<org.refcodes.web.BadRequestException>,org.refcodes.web.HttpClientRequest,org.refcodes.web.HttpClientRequest.HttpClientRequestBuilder,org.refcodes.web.HttpMethodAccessor,org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>,org.refcodes.web.HttpMethodAccessor.HttpMethodMutator,org.refcodes.web.HttpMethodAccessor.HttpMethodProperty,org.refcodes.web.HttpRequest,org.refcodes.web.HttpRequestBuilder<RestResponseHandler>,org.refcodes.web.QueryFieldsAccessor,org.refcodes.web.QueryFieldsAccessor.QueryFieldsMutator,org.refcodes.web.QueryFieldsAccessor.QueryFieldsProperty,org.refcodes.web.RedirectDepthAccessor,org.refcodes.web.RedirectDepthAccessor.RedirectDepthBuilder<org.refcodes.web.HttpClientRequest.HttpClientRequestBuilder>,org.refcodes.web.RedirectDepthAccessor.RedirectDepthMutator,org.refcodes.web.RedirectDepthAccessor.RedirectDepthProperty,org.refcodes.web.UrlAccessor,org.refcodes.web.UrlAccessor.UrlBuilder,org.refcodes.web.UrlAccessor.UrlMutator
public class RestResponseHandler extends org.refcodes.web.HttpClientRequestImpl implements RestResponseConsumer, org.refcodes.web.HttpClientRequest, org.refcodes.web.QueryFieldsAccessor.QueryFieldsProperty, org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsProperty<org.refcodes.web.RequestHeaderFields>, org.refcodes.web.HttpClientRequest.HttpClientRequestBuilder, org.refcodes.web.HttpRequestBuilder<RestResponseHandler>, org.refcodes.web.HttpMethodAccessor.HttpMethodProperty, org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>, org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsBuilder<org.refcodes.web.RequestHeaderFields,RestResponseHandler>
ARestResponseHandlerdescribes a REST request and theRestResponseConsumerin charge for handling a REST response. TheRestResponseHandlerdescribes theHttpMethodto be used, the targeted URL, theHeaderFieldsas well as the Query-Fields and the requestObjectorInputStream. It provides builder functionality andlambdasupport for handling the responses addressed to thisRestResponseHandler. Thelambdadefined asRestResponseConsumeracts as the single listener to thisRestResponseHandlerresponsible for handling the responses for which thisRestResponseHandleris responsible. The locator to which aRestResponseHandlertargets for is defined by thegetUrl()property.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.component.Closable
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.ConnectionStatusAccessor
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.HeaderFieldsAccessor
org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsBuilder<T extends org.refcodes.web.HeaderFields<?,?>,B extends org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsBuilder<T,B>>, org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsMutator<T extends org.refcodes.web.HeaderFields<?,?>>, org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsProperty<T extends org.refcodes.web.HeaderFields<?,?>>
-
Nested classes/interfaces inherited from interface org.refcodes.web.HttpClientRequest
org.refcodes.web.HttpClientRequest.HttpClientRequestBuilder
-
Nested classes/interfaces inherited from interface org.refcodes.web.HttpMethodAccessor
org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<B extends org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<B>>, org.refcodes.web.HttpMethodAccessor.HttpMethodMutator, org.refcodes.web.HttpMethodAccessor.HttpMethodProperty
-
Nested classes/interfaces inherited from interface org.refcodes.component.LinkComponent
org.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.Openable
org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>
-
Nested classes/interfaces inherited from interface org.refcodes.component.OpenedAccessor
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.QueryFieldsAccessor
org.refcodes.web.QueryFieldsAccessor.QueryFieldsBuilder<B extends org.refcodes.web.QueryFieldsAccessor.QueryFieldsBuilder<?>>, org.refcodes.web.QueryFieldsAccessor.QueryFieldsMutator, org.refcodes.web.QueryFieldsAccessor.QueryFieldsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.web.RedirectDepthAccessor
org.refcodes.web.RedirectDepthAccessor.RedirectDepthBuilder<B extends org.refcodes.web.RedirectDepthAccessor.RedirectDepthBuilder<B>>, org.refcodes.web.RedirectDepthAccessor.RedirectDepthMutator, org.refcodes.web.RedirectDepthAccessor.RedirectDepthProperty
-
-
Constructor Summary
Constructors Constructor Description RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, Object aRequest, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, RestResponseConsumer aResponseConsumer, int aRedirectDepth, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.RestResponseHandler(org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RestResponseHandlerbuild(RestClient aRestClient)This is a convenience method for easily instantiating the according builder.voidclose()org.refcodes.component.ConnectionStatusgetConnectionStatus()org.refcodes.web.HttpMethodgetHttpMethod()org.refcodes.web.FormFieldsgetQueryFields()RestResponseConsumergetResponseObserver()Retrieves theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.org.refcodes.web.UrlgetUrl()voidonResponse(RestResponseEvent aResponse)The invoker provides a response context being aRestResponseEventdescribing the response being processed upon by yourlambda's code.voidopen()voidsetHeaderFields(org.refcodes.web.RequestHeaderFields aHeaderFields)voidsetHttpMethod(org.refcodes.web.HttpMethod aHttpMethod)voidsetQueryFields(org.refcodes.web.FormFields aQueryFields)voidsetResponseObserver(RestResponseConsumer aLambda)Sets theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.voidsetUrl(org.refcodes.web.Url aUrl)StringtoString()RestResponseHandlerwithClose()RestResponseHandlerwithCloseIn(int aCloseInMillis)RestResponseHandlerwithCloseQuietly()RestResponseHandlerwithHeaderFields(org.refcodes.web.RequestHeaderFields aRequestHeaderFields)RestResponseHandlerwithHttpMethod(org.refcodes.web.HttpMethod aHttpMethod)RestResponseHandlerwithOpen()<REQ> RestResponseHandlerwithRequest(REQ aRequest)RestResponseHandlerwithResponseObserver(RestResponseConsumer aLambda)Builder method for setting theRestResponseConsumer.RestResponseHandlerwithUrl(org.refcodes.web.Url aUrl)-
Methods inherited from class org.refcodes.web.HttpClientRequestImpl
getRedirectDepth, getRequest, setRedirectDepth, setRequest, toHttpBody
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
Methods inherited from interface org.refcodes.web.HeaderFieldsAccessor.HeaderFieldsProperty
letHeaderFields
-
Methods inherited from interface org.refcodes.web.HttpClientRequest
getRequest, setRequest, toHttpBody
-
Methods inherited from interface org.refcodes.web.HttpClientRequest.HttpClientRequestBuilder
withRedirectDepth
-
Methods inherited from interface org.refcodes.web.HttpMethodAccessor.HttpMethodProperty
letHttpMethod
-
Methods inherited from interface org.refcodes.web.HttpRequestBuilder
withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToQueryFields, withAddToQueryFields, withAddToQueryFields
-
Methods inherited from interface org.refcodes.web.QueryFieldsAccessor.QueryFieldsProperty
letQueryFields
-
-
-
-
Constructor Detail
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aHeaderFields- the Header-FieldsaRequest- the requestaResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)
Instantiates a newRestResponseHandler.- Parameters:
aMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, Object aRequest, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aRequest- the requestaResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, RestResponseConsumer aResponseConsumer, int aRedirectDepth, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.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.aResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aRequest- the requestaRedirectDepth- 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.aResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(org.refcodes.web.HttpMethod aHttpMethod, org.refcodes.web.Url aUrl, org.refcodes.web.RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, org.refcodes.web.MediaTypeFactoryLookup aMediaTypeFactoryLookup)Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aHeaderFields- the Header-FieldsaRequest- the requestaRedirectDepth- 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.aResponseConsumer- the response observeraMediaTypeFactoryLookup- the media type factory lookup
-
-
Method Detail
-
setQueryFields
public void setQueryFields(org.refcodes.web.FormFields aQueryFields)
- Specified by:
setQueryFieldsin interfaceorg.refcodes.web.QueryFieldsAccessor.QueryFieldsMutator
-
getQueryFields
public org.refcodes.web.FormFields getQueryFields()
- Specified by:
getQueryFieldsin interfaceorg.refcodes.web.QueryFieldsAccessor
-
withUrl
public RestResponseHandler withUrl(org.refcodes.web.Url aUrl)
- Specified by:
withUrlin interfaceorg.refcodes.web.UrlAccessor.UrlBuilder
-
withHttpMethod
public RestResponseHandler withHttpMethod(org.refcodes.web.HttpMethod aHttpMethod)
- Specified by:
withHttpMethodin interfaceorg.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>
-
withRequest
public <REQ> RestResponseHandler withRequest(REQ aRequest)
- Specified by:
withRequestin interfaceorg.refcodes.web.HttpClientRequest.HttpClientRequestBuilder
-
onResponse
public void onResponse(RestResponseEvent aResponse) throws org.refcodes.web.HttpResponseException
The invoker provides a response context being aRestResponseEventdescribing the response being processed upon by yourlambda's code. The method works synchronously and waits (blocks the caller's thread) till it finishes execution.- Specified by:
onResponsein interfaceRestResponseConsumer- Parameters:
aResponse- The response of typeRestResponseEventdescribing the response context. UseHttpClientResponseImpl.getResponse(Class)to retrieve the server's response body orHttpResponseImpl.getHttpStatusCode()to retrieve the respone's HTTP Status-Code.- Throws:
org.refcodes.web.HttpResponseException- thrown by a HTTP-Response handling system in case of some unexpected response.
-
getHttpMethod
public org.refcodes.web.HttpMethod getHttpMethod()
- Specified by:
getHttpMethodin interfaceorg.refcodes.web.HttpMethodAccessor- Overrides:
getHttpMethodin classorg.refcodes.web.HttpRequestImpl
-
setHttpMethod
public void setHttpMethod(org.refcodes.web.HttpMethod aHttpMethod)
- Specified by:
setHttpMethodin interfaceorg.refcodes.web.HttpMethodAccessor.HttpMethodMutator
-
getResponseObserver
public RestResponseConsumer getResponseObserver()
Retrieves theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.- Returns:
- The (user defined)
RestResponseConsumerto handle responses.
-
setResponseObserver
public void setResponseObserver(RestResponseConsumer aLambda)
Sets theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.- Parameters:
aLambda- The (user defined)RestResponseConsumerto handle responses, feel free to code it aslambdaexpression!
-
open
public void open() throws IOException- Specified by:
openin interfaceorg.refcodes.component.Openable- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceorg.refcodes.component.Closable- Throws:
IOException
-
getConnectionStatus
public org.refcodes.component.ConnectionStatus getConnectionStatus()
- Specified by:
getConnectionStatusin interfaceorg.refcodes.component.ConnectionStatusAccessor
-
setHeaderFields
public void setHeaderFields(org.refcodes.web.RequestHeaderFields aHeaderFields)
- Specified by:
setHeaderFieldsin interfaceorg.refcodes.web.HeaderFieldsAccessor.HeaderFieldsMutator<org.refcodes.web.RequestHeaderFields>
-
getUrl
public org.refcodes.web.Url getUrl()
- Specified by:
getUrlin interfaceorg.refcodes.web.UrlAccessor- Overrides:
getUrlin classorg.refcodes.web.HttpRequestImpl
-
setUrl
public void setUrl(org.refcodes.web.Url aUrl)
- Specified by:
setUrlin interfaceorg.refcodes.web.UrlAccessor.UrlMutator
-
withResponseObserver
public RestResponseHandler withResponseObserver(RestResponseConsumer aLambda)
Builder method for setting theRestResponseConsumer.- Parameters:
aLambda- The (user defined)RestResponseConsumerto handle responses, feel free to code it aslambdaexpression- Returns:
- The
RestResponseHandlerfor the sake of a fluent API.
-
withHeaderFields
public RestResponseHandler withHeaderFields(org.refcodes.web.RequestHeaderFields aRequestHeaderFields)
- Specified by:
withHeaderFieldsin interfaceorg.refcodes.web.HeaderFieldsAccessor.HeaderFieldsBuilder<org.refcodes.web.RequestHeaderFields,RestResponseHandler>
-
withOpen
public RestResponseHandler withOpen() throws IOException
- Specified by:
withOpenin interfaceorg.refcodes.component.Openable.OpenBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>- Throws:
IOException
-
withClose
public RestResponseHandler withClose() throws IOException
- Specified by:
withClosein interfaceorg.refcodes.component.Closable.CloseBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>- Throws:
IOException
-
withCloseQuietly
public RestResponseHandler withCloseQuietly()
- Specified by:
withCloseQuietlyin interfaceorg.refcodes.component.Closable.CloseBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>
-
withCloseIn
public RestResponseHandler withCloseIn(int aCloseInMillis)
- Specified by:
withCloseInin interfaceorg.refcodes.component.Closable.CloseBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestResponseHandler>>
-
toString
public String toString()
- Overrides:
toStringin classorg.refcodes.web.HttpClientRequestImpl
-
build
public static RestResponseHandler build(RestClient aRestClient)
This is a convenience method for easily instantiating the according builder.- Parameters:
aRestClient- the rest client to take care of the caller.- Returns:
- an instance (using a public implementation) of this builder
-
-