Package org.refcodes.rest
Class RestEndpointBuilderImpl
- java.lang.Object
-
- org.refcodes.rest.RestEndpointBuilderImpl
-
- All Implemented Interfaces:
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.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 java.lang.Object implements RestEndpointBuilder
The implementation of theRestEndpointBuilderinterface as good old POJO for use by differentRestServerimplementations.
-
-
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.net.HttpMethodAccessor
org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<B extends org.refcodes.net.HttpMethodAccessor.HttpMethodBuilder<B>>, org.refcodes.net.HttpMethodAccessor.HttpMethodMutator, org.refcodes.net.HttpMethodAccessor.HttpMethodProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected org.refcodes.component.ConnectionStatus_connectionStatusprotected org.refcodes.net.HttpMethod_httpMethodprotected java.lang.String_locatorPatternprotected RestRequestObserver_requestObserver
-
Constructor Summary
Constructors Constructor Description RestEndpointBuilderImpl()Constructs a plainRestEndpointBuilder, make sure to provide the least required attributes as demonstrated by the constructorRestEndpointBuilderImpl(HttpMethod, String, RestRequestObserver).RestEndpointBuilderImpl(org.refcodes.net.HttpMethod aHttpMethod, java.lang.String aLocatorPattern, RestRequestObserver aRequestObserver)Constructs anRestEndpointBuilderwith the least required attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()org.refcodes.component.ConnectionStatusgetConnectionStatus()org.refcodes.net.HttpMethodgetHttpMethod()java.lang.StringgetLocatorPattern()Retrieves the resource Locator-Pattern this endpoint has been registered to.RestRequestObservergetRequestObserver()Retrieves theRestRequestObserverto which any requests are delegated upon invocation of theRestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)method.voidonRequest(RestRequestEvent aRequest, org.refcodes.net.HttpServerResponse aResponse)The invoker provides a request context being aRestRequestEvent) describing the request and a response being aHttpServerResponseto be processed upon by yourlambda's code.voidopen()voidsetHttpMethod(org.refcodes.net.HttpMethod aHttpMethod)voidsetLocatorPattern(java.lang.String aLocatorPattern)Sets the resource locator.voidsetRequestObserver(RestRequestObserver aLambda)Sets theRestRequestObserverto which any requests are delegated upon invocation of theRestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)method.-
Methods inherited from interface org.refcodes.component.Closable
closeIn, closeQuietly, closeUnchecked
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.rest.RestEndpointBuilder
withClose, withCloseIn, withCloseQuietly, withHttpMethod, withLocatorPattern, withOpen, withRequestObserver
-
-
-
-
Field Detail
-
_requestObserver
protected RestRequestObserver _requestObserver
-
_httpMethod
protected org.refcodes.net.HttpMethod _httpMethod
-
_locatorPattern
protected java.lang.String _locatorPattern
-
_connectionStatus
protected org.refcodes.component.ConnectionStatus _connectionStatus
-
-
Constructor Detail
-
RestEndpointBuilderImpl
public RestEndpointBuilderImpl()
Constructs a plainRestEndpointBuilder, make sure to provide the least required attributes as demonstrated by the constructorRestEndpointBuilderImpl(HttpMethod, String, RestRequestObserver).
-
RestEndpointBuilderImpl
public RestEndpointBuilderImpl(org.refcodes.net.HttpMethod aHttpMethod, java.lang.String aLocatorPattern, RestRequestObserver aRequestObserver)Constructs anRestEndpointBuilderwith the least required attributes.- Parameters:
aHttpMethod- The HTTP-Method to which thisRestEndpointBuilderis bound.aLocatorPattern- The local host's locator patter to which thisRestEndpointBuilderis bound. SeesetLocatorPattern(String)on the syntax of the pattern.aRequestObserver- The listener processing requests targeted at thisRestEndpointBuilder.
-
-
Method Detail
-
setLocatorPattern
public void setLocatorPattern(java.lang.String aLocatorPattern)
Sets the resource locator. The locator may contain wildcards as known from file-systems as follows: A single asterisk ("*") matches zero or more characters within a locator name. A double asterisk ("**") matches zero or more characters across directory levels. A question mark ("?") matches exactly one character within a locator name. You may name a wildcard by prefixing it with "${someWildcardName}". For example a named wildcard may look as follows: "${arg1}=*" or "${arg2}=**" or "${arg3}=?". You can get the text substituting a named wildcard using the methodWildcardSubstitutes.getWildcardReplacement(String). For ease of use, a named wildcard with single asterisk ("*") such as "${arg1}=*" can be abbreviated as "${arg1}".- Specified by:
setLocatorPatternin interfaceRestEndpointBuilder- Parameters:
aLocatorPattern- the new locator pattern
-
setHttpMethod
public void setHttpMethod(org.refcodes.net.HttpMethod aHttpMethod)
- Specified by:
setHttpMethodin interfaceorg.refcodes.net.HttpMethodAccessor.HttpMethodMutator
-
setRequestObserver
public void setRequestObserver(RestRequestObserver aLambda)
Sets theRestRequestObserverto which any requests are delegated upon invocation of theRestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)method.- Specified by:
setRequestObserverin interfaceRestEndpointBuilder- Parameters:
aLambda- The (user defined)RestRequestObserverto handle requests, feel free to code it aslambdaexpression!
-
getRequestObserver
public RestRequestObserver getRequestObserver()
Retrieves theRestRequestObserverto which any requests are delegated upon invocation of theRestRequestObserver.onRequest(RestRequestEvent, org.refcodes.net.HttpServerResponse)method.- Specified by:
getRequestObserverin interfaceRestEndpointBuilder- Returns:
- The (user defined)
RestRequestObserverto handle requests.
-
onRequest
public void onRequest(RestRequestEvent aRequest, org.refcodes.net.HttpServerResponse aResponse) throws org.refcodes.net.HttpStatusException
The invoker provides a request context being aRestRequestEvent) describing the request and a response being aHttpServerResponseto be processed upon by yourlambda's code. The method works synchronously and waits (blocks the caller's thread) till it finishes execution.- Specified by:
onRequestin interfaceRestRequestObserver- Parameters:
aRequest- The request of typeRestRequestEventdescribing the request context. UseHttpServerRequest.getRequest(Class)to retrieve the caller's request body orHeaderFieldsAccessor.getHeaderFields()to retrieve the request's cookies and other Header-Fields.aResponse- The response of typeHttpServerResponsedo be processed upon by the method's implementation. UseHttpServerResponse.setResponse(Object)to provide a response for the client. UseHeaderFieldsAccessor.getHeaderFields()to set cookies or modify Header-Fields. Throw one of theHttpStatusExceptionsub-types to signal an according erroneous HTTP state.- Throws:
org.refcodes.net.HttpStatusException- to be thrown in case something went wrong.
-
getHttpMethod
public org.refcodes.net.HttpMethod getHttpMethod()
- Specified by:
getHttpMethodin interfaceorg.refcodes.net.HttpMethodAccessor
-
getLocatorPattern
public java.lang.String getLocatorPattern()
Retrieves the resource Locator-Pattern this endpoint has been registered to. The Locator-Pattern may contain wildcards as known from file-systems as follows: A single asterisk ("*") matches zero or more characters within a locator name. A double asterisk ("**") matches zero or more characters across directory levels. A question mark ("?") matches exactly one character within a locator name. The single asterisk ("*"), the double asterisk ("**") and the question mark ("?") we refer to as wildcard: You get an array with the substitutes of the wildcards using theRestRequestEvent's methodWildcardSubstitutes.getWildcardReplacements()inside theRestRequestObserver.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}?". TheRestRequestEventlets you access the wildcard substitutes either by index or by name.- Specified by:
getLocatorPatternin interfaceRestEndpoint
-
open
public void open() throws org.refcodes.component.OpenException- Specified by:
openin interfaceorg.refcodes.component.Openable- Throws:
org.refcodes.component.OpenException
-
close
public void close() throws org.refcodes.component.CloseException- Specified by:
closein interfaceorg.refcodes.component.Closable- Throws:
org.refcodes.component.CloseException
-
getConnectionStatus
public org.refcodes.component.ConnectionStatus getConnectionStatus()
- Specified by:
getConnectionStatusin interfaceorg.refcodes.component.ConnectionStatusAccessor
-
-