org.refcodes.mixin.Disposable
, org.refcodes.mixin.Loggable
, org.refcodes.net.BaseLocatorAccessor
, org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<RestServer>
, org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator
, org.refcodes.net.BaseLocatorAccessor.BaseLocatorProperty
, org.refcodes.net.MediaTypeFactoryLookup
, org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
, org.refcodes.net.RealmAccessor
, org.refcodes.net.RealmAccessor.RealmBuilder<RestServer>
, org.refcodes.net.RealmAccessor.RealmMutator
, org.refcodes.net.RealmAccessor.RealmProperty
, org.refcodes.observer.Observable<RestEndpoint>
, org.refcodes.observer.Observers<RestEndpoint,RestServer>
, HttpExceptionHandlerAccessor
, HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<RestServer>
, HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator
, HttpExceptionHandlerAccessor.HttpExceptionHandlerProperty
, HttpExceptionHandlingAccessor
, HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<RestServer>
, HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator
, HttpExceptionHandlingAccessor.HttpExceptionHandlingProperty
, RestServer
, org.refcodes.runtime.RequestCorrelation<RestServer>
, org.refcodes.runtime.SessionCorrelation<RestServer>
HttpRestServerImpl
, LoopbackRestServerImpl
public abstract class AbstractRestServer extends org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest> implements RestServer
RestServer
interface
omitting the HTTP handling part being the foundation for various
RestServer
implementations such as HttpRestServerImpl
or
LoopbackRestServerImpl
.
The AbstractRestServer
is pre-configured with the following
MediaTypeFactory
instances:
ApplicationJsonFactory
ApplicationXmlFactory
TextPlainFactory
ApplicationFormFactory
initMedaTypeFactories()
,
therein calling addMediaTypeFactory(MediaTypeFactory)
to add (by
also invoking super's initMedaTypeFactories()
) or to set your own
(without invoking super's initMedaTypeFactories()
)
MediaTypeFactory
instances.org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<B extends org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<B>>, org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.net.BaseLocatorAccessor.BaseLocatorProperty
org.refcodes.mixin.Disposable.Disposedable
HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<B extends HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<B>>, HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator, HttpExceptionHandlerAccessor.HttpExceptionHandlerProperty
HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<B extends HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<B>>, HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator, HttpExceptionHandlingAccessor.HttpExceptionHandlingProperty
Modifier and Type | Field | Description |
---|---|---|
protected boolean |
_hasRequestCorrelation |
|
protected boolean |
_hasSessionCorrelation |
|
protected HttpExceptionHandler |
_httpExceptionHandler |
|
protected HttpExceptionHandling |
_httpExceptionHandling |
Constructor | Description |
---|---|
AbstractRestServer() |
Constructs a
AbstractRestServer pre-configured with
MediaTypeFactory instances for JSON and REST. |
AbstractRestServer(ExecutorService aExecutorService) |
CConstructs a
AbstractRestServer pre-configured with
MediaTypeFactory instances for JSON and REST. |
Modifier and Type | Method | Description |
---|---|---|
boolean |
addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory) |
|
void |
dispose() |
|
protected void |
doRequestCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
org.refcodes.net.HttpServerResponse aServerResponse) |
Do request correlation.
|
protected void |
doSessionCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
org.refcodes.net.HttpServerResponse aServerResponse) |
Do session correlation.
|
protected boolean |
fireEvent(org.refcodes.net.HttpRequest aEvent,
RestEndpoint aObserver,
org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy) |
|
String |
getBaseLocator() |
|
org.refcodes.net.MediaType[] |
getFactoryMediaTypes() |
|
HttpExceptionHandler |
getHttpExceptionHandler() |
Retrieves the
HttpExceptionHandler from the
HttpExceptionHandler property. |
HttpExceptionHandling |
getHttpExceptionHandling() |
Retrieves the
HttpExceptionHandling from the
HttpExceptionHandling property. |
String |
getRealm() |
|
boolean |
hasRequestCorrelation() |
|
boolean |
hasSessionCorrelation() |
|
protected void |
initMedaTypeFactories() |
Adds the default
MediaTypeFactory instances. |
boolean |
isObserversActive() |
|
Iterator<RestEndpoint> |
observers() |
|
protected void |
onHttpRequest(InetSocketAddress aLocalAddress,
InetSocketAddress aRemoteAddress,
org.refcodes.net.HttpMethod aHttpMethod,
org.refcodes.net.Url aUrl,
org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
InputStream aHttpInputStream,
org.refcodes.net.HttpServerResponse aHttpServerResponse) |
Extensions of this class disect an incoming request and pass it to this
method for doing the actual invocation of the registered
RestEndpoint instances. |
void |
setBaseLocator(String aBaseLocator) |
|
void |
setHttpExceptionHandler(HttpExceptionHandler aHttpErrorHandler) |
Sets the
HttpExceptionHandler for the
HttpExceptionHandler property. |
void |
setHttpExceptionHandling(HttpExceptionHandling aHttpErrorHandling) |
Sets the
HttpExceptionHandling for the
HttpExceptionHandling property. |
void |
setObserversActive(boolean isActive) |
|
void |
setRealm(String aRealm) |
|
void |
setRequestCorrelation(boolean hasRequestCorrelation) |
|
void |
setSessionCorrelation(boolean hasSessionCorrelation) |
|
boolean |
subscribeObserver(RestEndpoint aObserver) |
|
org.refcodes.net.MediaTypeFactory |
toMediaTypeFactory(org.refcodes.net.MediaType aMediaType) |
|
protected org.refcodes.net.ContentType |
toNegotiatedContenType(org.refcodes.net.RequestHeaderFields aRequestHeaderFields) |
Determines the best fitting respone's
ContentType . |
protected byte[] |
toResponseBody(Object aResponse,
org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
org.refcodes.net.ResponseHeaderFields aResponseHeaderFields) |
Creates a
String MediaType encoded as of the
HeaderField.CONTENT_TYPE from the response header or if not set
as of the HeaderField.ACCEPT from the request header or if not
set as of the HeaderField.CONTENT_TYPE from the request header. |
boolean |
unsubscribeObserver(RestEndpoint aObserver) |
clear, doHandleEventListenerException, fireEvent, getThreadPriority, hasObserverSubscription, isEmpty, setThreadPriority, size
withHttpExceptionHandler, withOnHttpException
onHttpException
withHttpExceptionHandling
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
disableRequestCorrelation, enableRequestCorrelation
onDelete, onGet, onPost, onPut, onRequest, onRequest, onRequest, withBaseLocator, withDisableObservers, withDisableRequestCorrelation, withDisableSessionCorrelation, withEnableObservers, withEnableRequestCorrelation, withEnableSessionCorrelation, withObserversActive, withRealm, withRequestCorrelation, withSessionCorrelation
protected boolean _hasRequestCorrelation
protected boolean _hasSessionCorrelation
protected HttpExceptionHandling _httpExceptionHandling
protected HttpExceptionHandler _httpExceptionHandler
public AbstractRestServer()
AbstractRestServer
pre-configured with
MediaTypeFactory
instances for JSON and REST.public AbstractRestServer(ExecutorService aExecutorService)
AbstractRestServer
pre-configured with
MediaTypeFactory
instances for JSON and REST.aExecutorService
- An executor service to be used when creating
Thread
s.protected void initMedaTypeFactories()
MediaTypeFactory
instances. Can be overridden.public HttpExceptionHandler getHttpExceptionHandler()
HttpExceptionHandler
from the
HttpExceptionHandler
property.getHttpExceptionHandler
in interface HttpExceptionHandlerAccessor
HttpExceptionHandler
stored by the
HttpExceptionHandler
property.public void setHttpExceptionHandler(HttpExceptionHandler aHttpErrorHandler)
HttpExceptionHandler
for the
HttpExceptionHandler
property.setHttpExceptionHandler
in interface HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator
aHttpErrorHandler
- The HttpExceptionHandler
to be
stored by the HttpExceptionHandler
property.public HttpExceptionHandling getHttpExceptionHandling()
HttpExceptionHandling
from the
HttpExceptionHandling
property.getHttpExceptionHandling
in interface HttpExceptionHandlingAccessor
HttpExceptionHandling
stored by the
HttpExceptionHandling
property.public void setHttpExceptionHandling(HttpExceptionHandling aHttpErrorHandling)
HttpExceptionHandling
for the
HttpExceptionHandling
property.setHttpExceptionHandling
in interface HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator
aHttpErrorHandling
- The HttpExceptionHandling
to be
stored by the HttpExceptionHandling
property.public void setObserversActive(boolean isActive)
setObserversActive
in interface org.refcodes.observer.Observers<RestEndpoint,RestServer>
setObserversActive
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
public boolean isObserversActive()
isObserversActive
in interface org.refcodes.observer.Observers<RestEndpoint,RestServer>
isObserversActive
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
public Iterator<RestEndpoint> observers()
observers
in interface org.refcodes.observer.Observers<RestEndpoint,RestServer>
observers
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
public void setRequestCorrelation(boolean hasRequestCorrelation)
setRequestCorrelation
in interface org.refcodes.runtime.RequestCorrelation<RestServer>
public boolean hasRequestCorrelation()
hasRequestCorrelation
in interface org.refcodes.runtime.RequestCorrelation<RestServer>
public void setSessionCorrelation(boolean hasSessionCorrelation)
setSessionCorrelation
in interface org.refcodes.runtime.SessionCorrelation<RestServer>
public boolean hasSessionCorrelation()
hasSessionCorrelation
in interface org.refcodes.runtime.SessionCorrelation<RestServer>
public String getRealm()
getRealm
in interface org.refcodes.net.RealmAccessor
public void setRealm(String aRealm)
setRealm
in interface org.refcodes.net.RealmAccessor.RealmMutator
public String getBaseLocator()
getBaseLocator
in interface org.refcodes.net.BaseLocatorAccessor
public void setBaseLocator(String aBaseLocator)
setBaseLocator
in interface org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator
public boolean subscribeObserver(RestEndpoint aObserver)
subscribeObserver
in interface org.refcodes.observer.Observable<RestEndpoint>
subscribeObserver
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
public boolean unsubscribeObserver(RestEndpoint aObserver)
unsubscribeObserver
in interface org.refcodes.observer.Observable<RestEndpoint>
unsubscribeObserver
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
public boolean addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
addMediaTypeFactory
in interface org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
public org.refcodes.net.MediaTypeFactory toMediaTypeFactory(org.refcodes.net.MediaType aMediaType)
toMediaTypeFactory
in interface org.refcodes.net.MediaTypeFactoryLookup
public org.refcodes.net.MediaType[] getFactoryMediaTypes()
getFactoryMediaTypes
in interface org.refcodes.net.MediaTypeFactoryLookup
public void dispose()
dispose
in interface org.refcodes.mixin.Disposable
dispose
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
protected void onHttpRequest(InetSocketAddress aLocalAddress, InetSocketAddress aRemoteAddress, org.refcodes.net.HttpMethod aHttpMethod, org.refcodes.net.Url aUrl, org.refcodes.net.RequestHeaderFields aRequestHeaderFields, InputStream aHttpInputStream, org.refcodes.net.HttpServerResponse aHttpServerResponse) throws org.refcodes.net.HttpStatusException
RestEndpoint
instances. An extension might call this method from
inside an event (request) handler.aLocalAddress
- The host and port of your REST service.aRemoteAddress
- The host and port for the caller.aHttpMethod
- The HttpMethod
of the request.aUrl
- The Url
from which to take the URL specific data.aRequestHeaderFields
- The Header-Fields (HeaderFields
)
belonging to the request.aHttpInputStream
- The body passed by the request.aHttpServerResponse
- A HttpServerResponse
instance to be
used by the extension to produce an according HTTP-Response.org.refcodes.net.HttpStatusException
- thrown in case of an RestEndpoint
responsible for the given request encountered a problem or none
RestEndpoint
felt responsible to produce a
HttpServerResponse
.protected org.refcodes.net.ContentType toNegotiatedContenType(org.refcodes.net.RequestHeaderFields aRequestHeaderFields)
ContentType
. The default
Content-Type-Negotiation implementation of this method makes use of the
RequestHeaderFields
and matches them against the supported
MediaType
types ( retrieved via getFactoryMediaTypes()
).
May be overwritten to enforce another Content-Type-Negotiation strategy.aRequestHeaderFields
- The request's HeaderField
instance to
use when determining the best fitting respone's
ContentType
.protected byte[] toResponseBody(Object aResponse, org.refcodes.net.RequestHeaderFields aRequestHeaderFields, org.refcodes.net.ResponseHeaderFields aResponseHeaderFields) throws org.refcodes.exception.MarshalException, org.refcodes.net.UnsupportedMediaTypeException
String
MediaType
encoded as of the
HeaderField.CONTENT_TYPE
from the response header or if not set
as of the HeaderField.ACCEPT
from the request header or if not
set as of the HeaderField.CONTENT_TYPE
from the request header.aResponse
- The response which to encode as of the detected
MediaType
s.aRequestHeaderFields
- The Header-Fields from the request.aResponseHeaderFields
- The Header-Fields from the response.org.refcodes.exception.MarshalException
- thrown when marshaling / serializing an object
failed.org.refcodes.net.UnsupportedMediaTypeException
- thrown in case none of the
identified media types is supported, e.g. no required
MediaTypeFactory
has been registered as of
addMediaTypeFactory(MediaTypeFactory)
.protected boolean fireEvent(org.refcodes.net.HttpRequest aEvent, RestEndpoint aObserver, org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy) throws org.refcodes.exception.VetoException
fireEvent
in class org.refcodes.observer.AbstractObservable<RestEndpoint,org.refcodes.net.HttpRequest>
org.refcodes.exception.VetoException
protected void doRequestCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields, org.refcodes.net.HttpServerResponse aServerResponse)
aRequestHeaderFields
- the request Header-FieldsaServerResponse
- the server responseprotected void doSessionCorrelation(org.refcodes.net.RequestHeaderFields aRequestHeaderFields, org.refcodes.net.HttpServerResponse aServerResponse)
aRequestHeaderFields
- the request Header-FieldsaServerResponse
- the server responseCopyright © 2018. All rights reserved.