Class RestResponseHandler
java.lang.Object
org.refcodes.web.AbstractHttpRequest
org.refcodes.web.HttpClientRequest
org.refcodes.rest.RestResponseHandler
- All Implemented Interfaces:
Closable, Closable.CloseBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>, ConnectionStatusAccessor, LinkComponent, LinkComponent.LinkComponentBuilder<RestResponseHandler>, Openable, Openable.OpenBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>, OpenedAccessor, RestResponseConsumer, HeaderFieldsAccessor<RequestHeaderFields>, HeaderFieldsAccessor.HeaderFieldsBuilder<RequestHeaderFields, RestResponseHandler>, HeaderFieldsAccessor.HeaderFieldsMutator<RequestHeaderFields>, HeaderFieldsAccessor.HeaderFieldsProperty<RequestHeaderFields>, HttpBodyAccessor.HttpBodyProvider<BadRequestException>, HttpMethodAccessor, HttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>, HttpMethodAccessor.HttpMethodMutator, HttpMethodAccessor.HttpMethodProperty, HttpRequest, HttpRequestBuilder<RestResponseHandler>, QueryFieldsAccessor, QueryFieldsAccessor.QueryFieldsMutator, QueryFieldsAccessor.QueryFieldsProperty, RedirectDepthAccessor, RedirectDepthAccessor.RedirectDepthBuilder<RestResponseHandler>, RedirectDepthAccessor.RedirectDepthMutator, RedirectDepthAccessor.RedirectDepthProperty, UrlAccessor, UrlAccessor.UrlBuilder, UrlAccessor.UrlMutator
public class RestResponseHandler
extends HttpClientRequest
implements RestResponseConsumer, QueryFieldsAccessor.QueryFieldsProperty, HeaderFieldsAccessor.HeaderFieldsProperty<RequestHeaderFields>, RedirectDepthAccessor.RedirectDepthBuilder<RestResponseHandler>, HttpRequestBuilder<RestResponseHandler>, HttpMethodAccessor.HttpMethodProperty, HttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>, LinkComponent.LinkComponentBuilder<RestResponseHandler>, ConnectionStatusAccessor, HeaderFieldsAccessor.HeaderFieldsBuilder<RequestHeaderFields, RestResponseHandler>
A
RestResponseHandler describes a REST request and the
RestResponseConsumer in charge for handling a REST response. The
RestResponseHandler describes the HttpMethod to be used, the
targeted URL, the HeaderFields as well as the Query-Fields and the
request Object or InputStream. It provides builder
functionality and lambda support for handling the responses
addressed to this RestResponseHandler. The lambda
defined as RestResponseConsumer acts as the single listener to this
RestResponseHandler responsible for handling the responses for which
this RestResponseHandler is responsible. The locator to which a
RestResponseHandler targets for is defined by the getUrl()
property.-
Nested Class Summary
Nested classes/interfaces inherited from interface Closable
Closable.CloseAutomaton, Closable.CloseBuilder<B>Nested classes/interfaces inherited from interface ConnectionStatusAccessor
ConnectionStatusAccessor.ConnectionStatusMutator, ConnectionStatusAccessor.ConnectionStatusPropertyNested classes/interfaces inherited from interface HeaderFieldsAccessor
HeaderFieldsAccessor.HeaderFieldsBuilder<T,B>, HeaderFieldsAccessor.HeaderFieldsMutator<T>, HeaderFieldsAccessor.HeaderFieldsProperty<T> Nested classes/interfaces inherited from interface HttpMethodAccessor
HttpMethodAccessor.HttpMethodBuilder<B>, HttpMethodAccessor.HttpMethodMutator, HttpMethodAccessor.HttpMethodPropertyNested classes/interfaces inherited from interface LinkComponent
LinkComponent.LinkAutomaton, LinkComponent.LinkComponentBuilder<B>Nested classes/interfaces inherited from interface Openable
Openable.OpenAutomaton, Openable.OpenBuilder<B>Nested classes/interfaces inherited from interface OpenedAccessor
OpenedAccessor.OpenedMutator, OpenedAccessor.OpenedPropertyNested classes/interfaces inherited from interface QueryFieldsAccessor
QueryFieldsAccessor.QueryFieldsBuilder<B>, QueryFieldsAccessor.QueryFieldsMutator, QueryFieldsAccessor.QueryFieldsPropertyNested classes/interfaces inherited from interface RedirectDepthAccessor
RedirectDepthAccessor.RedirectDepthBuilder<B>, RedirectDepthAccessor.RedirectDepthMutator, RedirectDepthAccessor.RedirectDepthPropertyNested classes/interfaces inherited from interface UrlAccessor
UrlAccessor.UrlBuilder, UrlAccessor.UrlMutator, UrlAccessor.UrlProperty -
Field Summary
Fields inherited from class HttpClientRequest
_mediaTypeFactoryLookup, DEFAULT_REDIRECT_DEPTHFields inherited from class AbstractHttpRequest
_headerFields, _httpMethod, _url -
Constructor Summary
ConstructorsConstructorDescriptionRestResponseHandler(HttpMethod aHttpMethod, Url aUrl, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, Object aRequest, RestResponseConsumer aResponseConsumer, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, RestResponseConsumer aResponseConsumer, int aRedirectDepth, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, RestResponseConsumer aResponseConsumer, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, RequestHeaderFields aHeaderFields, Object aRequest, RestResponseConsumer aResponseConsumer, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.RestResponseHandler(MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler. -
Method Summary
Modifier and TypeMethodDescriptionstatic RestResponseHandlerbuild(RestClient aRestClient) This is a convenience method for easily instantiating the according builder.voidclose()Retrieves theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.getUrl()voidonResponse(RestResponseEvent aResponse) The invoker provides a response context being aRestResponseEventdescribing the response being processed upon by yourlambda's code.voidopen()voidsetHeaderFields(RequestHeaderFields aHeaderFields) voidsetHttpMethod(HttpMethod aHttpMethod) voidsetQueryFields(FormFields aQueryFields) voidsetResponseObserver(RestResponseConsumer aLambda) Sets theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.voidtoString()withCloseIn(int aCloseMillis) withHeaderFields(RequestHeaderFields aRequestHeaderFields) withHttpMethod(HttpMethod aHttpMethod) withOpen()withRedirectDepth(int aRedirectDepth) <REQ> RestResponseHandlerwithRequest(REQ aRequest) Sets the request for the request property.withResponseObserver(RestResponseConsumer aLambda) Builder method for setting theRestResponseConsumer.Methods inherited from class HttpClientRequest
getRedirectDepth, getRequest, setRedirectDepth, setRequest, toHttpBodyMethods inherited from class AbstractHttpRequest
getHeaderFieldsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface Closable.CloseBuilder
withCloseUncheckedMethods inherited from interface ConnectionStatusAccessor
isOpenedMethods inherited from interface HeaderFieldsAccessor
getHeaderFieldsMethods inherited from interface HeaderFieldsAccessor.HeaderFieldsProperty
letHeaderFieldsMethods inherited from interface HttpMethodAccessor.HttpMethodProperty
letHttpMethodMethods inherited from interface HttpRequestBuilder
withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToHeaderFields, withAddToQueryFields, withAddToQueryFields, withAddToQueryFieldsMethods inherited from interface Openable
openUncheckedMethods inherited from interface Openable.OpenBuilder
withOpenUncheckedMethods inherited from interface QueryFieldsAccessor.QueryFieldsProperty
letQueryFieldsMethods inherited from interface RedirectDepthAccessor.RedirectDepthProperty
letRedirectDepth
-
Constructor Details
-
RestResponseHandler
public RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, RequestHeaderFields aHeaderFields, Object aRequest, RestResponseConsumer aResponseConsumer, 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(HttpMethod aHttpMethod, Url aUrl, RestResponseConsumer aResponseConsumer, 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
Instantiates a newRestResponseHandler.- Parameters:
aMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, Object aRequest, RestResponseConsumer aResponseConsumer, 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(HttpMethod aHttpMethod, Url aUrl, RestResponseConsumer aResponseConsumer, int aRedirectDepth, MediaTypeFactoryLookup aMediaTypeFactoryLookup) Instantiates a newRestResponseHandler.- Parameters:
aHttpMethod- the http methodaUrl- TheUrlfrom which to take the URL specific data.aResponseConsumer- the response observeraRedirectDepth- 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.aMediaTypeFactoryLookup- the media type factory lookup
-
RestResponseHandler
public RestResponseHandler(HttpMethod aHttpMethod, Url aUrl, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, 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(HttpMethod aHttpMethod, Url aUrl, RequestHeaderFields aHeaderFields, Object aRequest, int aRedirectDepth, RestResponseConsumer aResponseConsumer, 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 Details
-
withRedirectDepth
- Specified by:
withRedirectDepthin interfaceRedirectDepthAccessor.RedirectDepthBuilder<RestResponseHandler>
-
setQueryFields
- Specified by:
setQueryFieldsin interfaceQueryFieldsAccessor.QueryFieldsMutator
-
getQueryFields
- Specified by:
getQueryFieldsin interfaceQueryFieldsAccessor
-
withUrl
- Specified by:
withUrlin interfaceUrlAccessor.UrlBuilder
-
withHttpMethod
- Specified by:
withHttpMethodin interfaceHttpMethodAccessor.HttpMethodBuilder<RestResponseHandler>
-
withRequest
Sets the request for the request property.- Type Parameters:
REQ- the generic type- Parameters:
aRequest- The request to be stored by the request property.- Returns:
- The builder for applying multiple build operations.
-
onResponse
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. UseHttpClientResponse.getResponse(Class)to retrieve the server's response body orAbstractHttpResponse.getHttpStatusCode()to retrieve the respone's HTTP Status-Code.- Throws:
HttpResponseException- thrown by a HTTP-Response handling system in case of some unexpected response.
-
getHttpMethod
- Specified by:
getHttpMethodin interfaceHttpMethodAccessor- Overrides:
getHttpMethodin classAbstractHttpRequest
-
setHttpMethod
- Specified by:
setHttpMethodin interfaceHttpMethodAccessor.HttpMethodMutator
-
getResponseObserver
Retrieves theRestResponseConsumerto which any responses are delegated upon invocation of theonResponse(RestResponseEvent)method.- Returns:
- The (user defined)
RestResponseConsumerto handle responses.
-
setResponseObserver
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
- Specified by:
openin interfaceOpenable- Throws:
IOException
-
close
- Specified by:
closein interfaceClosable- Throws:
IOException
-
getConnectionStatus
- Specified by:
getConnectionStatusin interfaceConnectionStatusAccessor
-
setHeaderFields
- Specified by:
setHeaderFieldsin interfaceHeaderFieldsAccessor.HeaderFieldsMutator<RequestHeaderFields>
-
getUrl
- Specified by:
getUrlin interfaceUrlAccessor- Overrides:
getUrlin classAbstractHttpRequest
-
setUrl
- Specified by:
setUrlin interfaceUrlAccessor.UrlMutator
-
withResponseObserver
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
- Specified by:
withHeaderFieldsin interfaceHeaderFieldsAccessor.HeaderFieldsBuilder<RequestHeaderFields, RestResponseHandler>
-
withOpen
- Specified by:
withOpenin interfaceOpenable.OpenBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>- Throws:
IOException
-
withClose
- Specified by:
withClosein interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>- Throws:
IOException
-
withCloseQuietly
- Specified by:
withCloseQuietlyin interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>
-
withCloseIn
- Specified by:
withCloseInin interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<RestResponseHandler>>
-
toString
- Overrides:
toStringin classHttpClientRequest
-
build
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
-