org.refcodes.component.Closable
, org.refcodes.component.Closable.CloseBuilder<RestEndpointBuilder>
, org.refcodes.component.ConnectionStatusAccessor
, org.refcodes.component.LinkComponent
, org.refcodes.component.LinkComponent.LinkComponentBuilder<RestEndpointBuilder>
, org.refcodes.component.Openable
, org.refcodes.component.Openable.OpenBuilder<RestEndpointBuilder>
, org.refcodes.component.OpenedAccessor
, RestEndpoint
, RestEndpointBuilder
, RestRequestConsumer
, org.refcodes.web.HttpMethodAccessor
, org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<RestEndpointBuilder>
, org.refcodes.web.HttpMethodAccessor.HttpMethodMutator
, org.refcodes.web.HttpMethodAccessor.HttpMethodProperty
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.web.HttpMethodAccessor.HttpMethodBuilder<B extends org.refcodes.web.HttpMethodAccessor.HttpMethodBuilder<B>>, org.refcodes.web.HttpMethodAccessor.HttpMethodMutator, org.refcodes.web.HttpMethodAccessor.HttpMethodProperty
org.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>
Modifier and Type | Field | Description |
---|---|---|
protected org.refcodes.component.ConnectionStatus |
_connectionStatus |
|
protected org.refcodes.web.HttpMethod |
_httpMethod |
|
protected String |
_locatorPathPattern |
|
protected Pattern |
_locatorRegExp |
|
protected RestRequestConsumer |
_requestObserver |
Constructor | Description |
---|---|
RestEndpointBuilderImpl() |
Constructs a plain
RestEndpointBuilder , make sure to provide the
least required attributes as demonstrated by the constructor
RestEndpointBuilderImpl(HttpMethod, String, RestRequestConsumer) . |
RestEndpointBuilderImpl(org.refcodes.web.HttpMethod aHttpMethod,
String aLocatorPathPattern,
RestRequestConsumer aRequestConsumer) |
Constructs an
RestEndpointBuilder with the least required
attributes. |
RestEndpointBuilderImpl(org.refcodes.web.HttpMethod aHttpMethod,
Pattern aLocatorRegExp,
RestRequestConsumer aRequestConsumer) |
Constructs an
RestEndpointBuilder with the least required
attributes. |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
|
org.refcodes.component.ConnectionStatus |
getConnectionStatus() |
|
org.refcodes.web.HttpMethod |
getHttpMethod() |
|
String |
getLocatorPathPattern() |
Retrieves the resource Locator-Pattern this endpoint has been registered
to.
|
Pattern |
getLocatorRegExp() |
Retrieves the resource locator (regular expression) pattern this endpoint
has been registered to.
|
RestRequestConsumer |
getRequestObserver() |
Retrieves the
RestRequestConsumer to which any requests are
delegated upon invocation of the
RestRequestConsumer.onRequest(RestRequestEvent, org.refcodes.web.HttpServerResponse)
method. |
void |
onRequest(RestRequestEvent aRequest,
org.refcodes.web.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.web.HttpMethod aHttpMethod) |
|
void |
setLocatorPathPattern(String aLocatorPathPattern) |
Sets the resource locator pattern.
|
void |
setLocatorRegExp(Pattern aLocatorRegExp) |
Sets the resource locator (regular expression) pattern.
|
void |
setRequestObserver(RestRequestConsumer aLambda) |
Sets the
RestRequestConsumer to which any requests are delegated
upon invocation of the
RestRequestConsumer.onRequest(RestRequestEvent, org.refcodes.web.HttpServerResponse)
method. |
closeIn, closeQuietly, closeUnchecked
letHttpMethod
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
build, withClose, withCloseIn, withCloseQuietly, withHttpMethod, withLocatorPathPattern, withLocatorRegExp, withOpen, withRequestObserver
protected RestRequestConsumer _requestObserver
protected org.refcodes.web.HttpMethod _httpMethod
protected String _locatorPathPattern
protected Pattern _locatorRegExp
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, RestRequestConsumer)
.public RestEndpointBuilderImpl(org.refcodes.web.HttpMethod aHttpMethod, String aLocatorPathPattern, RestRequestConsumer aRequestConsumer)
RestEndpointBuilder
with the least required
attributes.aHttpMethod
- The HTTP-Method to which this
RestEndpointBuilder
is bound.aLocatorPathPattern
- The local host's locator pattern to which this
RestEndpointBuilder
is bound. See
setLocatorPathPattern(String)
on the syntax of the
pattern.aRequestConsumer
- The listener processing requests targeted at this
RestEndpointBuilder
.public RestEndpointBuilderImpl(org.refcodes.web.HttpMethod aHttpMethod, Pattern aLocatorRegExp, RestRequestConsumer aRequestConsumer)
RestEndpointBuilder
with the least required
attributes.aHttpMethod
- The HTTP-Method to which this
RestEndpointBuilder
is bound.aLocatorRegExp
- The local host's locator (regular expression)
pattern to which this RestEndpointBuilder
is bound. See
setLocatorPathPattern(String)
on the syntax of the
pattern.aRequestConsumer
- The listener processing requests targeted at this
RestEndpointBuilder
.public void setLocatorPathPattern(String aLocatorPathPattern)
RestRequestEvent.getWildcardReplacement(String)
. For ease of use,
a named wildcard with single asterisk ("*") such as "${arg1}=*" can be
abbreviated as "${arg1}".setLocatorPathPattern
in interface RestEndpointBuilder
aLocatorPathPattern
- the new locator patternpublic void setLocatorRegExp(Pattern aLocatorRegExp)
setLocatorRegExp
in interface RestEndpointBuilder
aLocatorRegExp
- the new locator (regular expression) patternpublic void setHttpMethod(org.refcodes.web.HttpMethod aHttpMethod)
setHttpMethod
in interface org.refcodes.web.HttpMethodAccessor.HttpMethodMutator
public void setRequestObserver(RestRequestConsumer aLambda)
RestRequestConsumer
to which any requests are delegated
upon invocation of the
RestRequestConsumer.onRequest(RestRequestEvent, org.refcodes.web.HttpServerResponse)
method.setRequestObserver
in interface RestEndpointBuilder
aLambda
- The (user defined) RestRequestConsumer
to handle
requests, feel free to code it as lambda
expression!public RestRequestConsumer getRequestObserver()
RestRequestConsumer
to which any requests are
delegated upon invocation of the
RestRequestConsumer.onRequest(RestRequestEvent, org.refcodes.web.HttpServerResponse)
method.getRequestObserver
in interface RestEndpointBuilder
RestRequestConsumer
to handle
requests.public void onRequest(RestRequestEvent aRequest, org.refcodes.web.HttpServerResponse aResponse) throws org.refcodes.web.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 RestRequestConsumer
aRequest
- The request of type RestRequestEvent
describing
the request context. Use
HttpServerRequestImpl.getRequest(Class)
to retrieve the
caller's request body or
HttpRequestImpl.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.web.HttpStatusException
- to be thrown in case something went wrong.public org.refcodes.web.HttpMethod getHttpMethod()
getHttpMethod
in interface org.refcodes.web.HttpMethodAccessor
public String getLocatorPathPattern()
RestRequestEvent
's method
RestRequestEvent.getWildcardReplacements()
inside the
RestRequestConsumer.onRequest(RestRequestEvent, org.refcodes.web.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.
getLocatorPathPattern
in interface RestEndpoint
public Pattern getLocatorRegExp()
RestRequestEvent
lets you access the
matching regular expression groups either by index or by name.
getLocatorRegExp
in interface RestEndpoint
public void open() throws IOException
open
in interface org.refcodes.component.Openable
IOException
public void close() throws IOException
close
in interface org.refcodes.component.Closable
IOException
public org.refcodes.component.ConnectionStatus getConnectionStatus()
getConnectionStatus
in interface org.refcodes.component.ConnectionStatusAccessor
Copyright © 2021. All rights reserved.