org.refcodes.component.Closable
, org.refcodes.component.Closable.CloseBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestEndpointBuilder>>
, org.refcodes.component.ConnectionStatusAccessor
, org.refcodes.component.LinkComponent
, org.refcodes.component.LinkComponent.LinkComponentBuilder<RestEndpointBuilder>
, org.refcodes.component.Openable
, org.refcodes.component.Openable.OpenBuilder<org.refcodes.component.LinkComponent.LinkComponentBuilder<RestEndpointBuilder>>
, org.refcodes.net.HttpMethodAccessor
, org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<RestEndpointBuilder>
, org.refcodes.net.HttpMethodAccessor.HttpMethodMutator
, org.refcodes.net.HttpMethodAccessor.HttpMethodProperty
, RestEndpoint
, RestEndpointBuilder
, RestRequestObserver
public class RestEndpointBuilderImpl extends Object implements RestEndpointBuilder
RestEndpointBuilder
interface as good old
POJO for use by different RestServer
implementations.org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<B extends org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<B>>, org.refcodes.net.HttpMethodAccessor.HttpMethodMutator, org.refcodes.net.HttpMethodAccessor.HttpMethodProperty
Modifier and Type | Field | Description |
---|---|---|
protected org.refcodes.component.ConnectionStatus |
_connectionStatus |
|
protected org.refcodes.net.HttpMethod |
_httpMethod |
|
protected String |
_locatorPattern |
|
protected RestRequestObserver |
_requestObserver |
Constructor | Description |
---|---|
RestEndpointBuilderImpl() |
Constructs a plain
RestEndpointBuilder , make sure to provide the
least required attributes as demonstrated by the constructor
RestEndpointBuilderImpl(HttpMethod, String, RestRequestObserver) . |
RestEndpointBuilderImpl(org.refcodes.net.HttpMethod aHttpMethod,
String aLocatorPattern,
RestRequestObserver aRequestObserver) |
Constructs an
RestEndpointBuilder with the least required
attributes. |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
org.refcodes.component.ConnectionStatus |
getConnectionStatus() |
|
org.refcodes.net.HttpMethod |
getHttpMethod() |
|
String |
getLocatorPattern() |
Retrieves the resource Locator-Pattern this endpoint has been registered
to.
|
RestRequestObserver |
getRequestObserver() |
Retrieves the
RestRequestObserver to which any requests are
delegated upon invocation of the
RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)
method. |
void |
onRequest(RestRequestEvent aRequest,
org.refcodes.net.HttpServerResponse aResponse) |
The invoker provides a request context being a
RestRequestEvent )
describing the request and a response being a HttpServerResponse
to be processed upon by your lambda 's code. |
void |
open() |
|
void |
setHttpMethod(org.refcodes.net.HttpMethod aHttpMethod) |
|
void |
setLocatorPattern(String aLocatorPattern) |
Sets the resource locator.
|
void |
setRequestObserver(RestRequestObserver aLambda) |
Sets the
RestRequestObserver to which any requests are delegated
upon invocation of the
RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)
method. |
closeIn, closeQuietly, closeUnchecked
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
withClose, withCloseIn, withCloseQuietly, withHttpMethod, withLocatorPattern, withOpen, withRequestObserver
protected RestRequestObserver _requestObserver
protected org.refcodes.net.HttpMethod _httpMethod
protected String _locatorPattern
protected org.refcodes.component.ConnectionStatus _connectionStatus
public RestEndpointBuilderImpl()
RestEndpointBuilder
, make sure to provide the
least required attributes as demonstrated by the constructor
RestEndpointBuilderImpl(HttpMethod, String, RestRequestObserver)
.public RestEndpointBuilderImpl(org.refcodes.net.HttpMethod aHttpMethod, String aLocatorPattern, RestRequestObserver aRequestObserver)
RestEndpointBuilder
with the least required
attributes.aHttpMethod
- The HTTP-Method to which this
RestEndpointBuilder
is bound.aLocatorPattern
- The local host's locator patter to which this
RestEndpointBuilder
is bound. See
setLocatorPattern(String)
on the syntax of the pattern.aRequestObserver
- The listener processing requests targeted at this
RestEndpointBuilder
.public void setLocatorPattern(String aLocatorPattern)
WildcardSubstitutes.getWildcardReplacement(String)
.
For ease of use, a named wildcard with single asterisk ("*") such as
"${arg1}=*" can be abbreviated as "${arg1}".setLocatorPattern
in interface RestEndpointBuilder
aLocatorPattern
- the new locator patternpublic void setHttpMethod(org.refcodes.net.HttpMethod aHttpMethod)
setHttpMethod
in interface org.refcodes.net.HttpMethodAccessor.HttpMethodMutator
public void setRequestObserver(RestRequestObserver aLambda)
RestRequestObserver
to which any requests are delegated
upon invocation of the
RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)
method.setRequestObserver
in interface RestEndpointBuilder
aLambda
- The (user defined) RestRequestObserver
to handle
requests, feel free to code it as lambda
expression!public RestRequestObserver getRequestObserver()
RestRequestObserver
to which any requests are
delegated upon invocation of the
RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)
method.getRequestObserver
in interface RestEndpointBuilder
RestRequestObserver
to handle
requests.public void onRequest(RestRequestEvent aRequest, org.refcodes.net.HttpServerResponse aResponse) throws org.refcodes.net.HttpStatusException
RestRequestEvent
)
describing the request and a response being a HttpServerResponse
to be processed upon by your lambda
's code. The method works
synchronously and waits (blocks the caller's thread) till it finishes
execution.onRequest
in interface RestRequestObserver
aRequest
- The request of type RestRequestEvent
describing
the request context. Use
HttpServerRequest.getRequest(Class)
to retrieve the
caller's request body or
HeaderFieldsAccessor.getHeaderFields()
to retrieve the
request's cookies and other Header-Fields.aResponse
- The response of type HttpServerResponse
do be
processed upon by the method's implementation. Use
HttpServerResponse.setResponse(Object)
to provide a
response for the client. Use
HeaderFieldsAccessor.getHeaderFields()
to set cookies or
modify Header-Fields. Throw one of the HttpStatusException
sub-types to signal an according erroneous HTTP state.org.refcodes.net.HttpStatusException
- to be thrown in case something went wrong.public org.refcodes.net.HttpMethod getHttpMethod()
getHttpMethod
in interface org.refcodes.net.HttpMethodAccessor
public String getLocatorPattern()
RestRequestEvent
's method
WildcardSubstitutes.getWildcardReplacements()
inside the
RestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)
method.
You may name a wildcard by prefixing it with "{someWildcardName}". For
example a named wildcard may look as follows: "{arg1}*" or "{arg2}**" or
"{arg3}?".
The RestRequestEvent
lets you access the wildcard substitutes
either by index or by name.
getLocatorPattern
in interface RestEndpoint
public void open() throws org.refcodes.component.OpenException
open
in interface org.refcodes.component.Openable
org.refcodes.component.OpenException
public void close() throws org.refcodes.component.CloseException
close
in interface org.refcodes.component.Closable
org.refcodes.component.CloseException
public org.refcodes.component.ConnectionStatus getConnectionStatus()
getConnectionStatus
in interface org.refcodes.component.ConnectionStatusAccessor
Copyright © 2018. All rights reserved.