public abstract class AbstractRestService extends org.refcodes.observer.impls.AbstractObservable<Endpoint,org.refcodes.net.HttpRequest> implements RestService
RestService
interface using the
HttpServer
defined in com.sun.net.httpserver package.Constructor and Description |
---|
AbstractRestService()
Constructs a
AbstractRestService pre-configured with
MediaTypeFactory instances for JSON and REST. |
AbstractRestService(ExecutorService aExecutorService)
CConstructs a
AbstractRestService pre-configured with
MediaTypeFactory instances for JSON and REST. |
Modifier and Type | Method and Description |
---|---|
boolean |
addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
Registers a
MediaTypeFactory for marshaling and unmarshaling a
HTTP request's body of the according MediaType . |
void |
dispose() |
protected boolean |
fireEvent(org.refcodes.net.HttpRequest aEvent,
Endpoint aObserver,
org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy) |
protected void |
initMedaTypeFactories()
Adds the default
MediaTypeFactory instances. |
protected org.refcodes.net.HttpServerResponse |
onHttpRequest(org.refcodes.net.HttpMethod aHttpMethod,
String aLocator,
String aQueryString,
org.refcodes.net.RequestHeaderFields aRequestHeaderFields,
String aRequestBody)
Extensions of this class disect an incoming request and pass it to this
method for doing the actual invocation of the registered
Endpoint
instances. |
boolean |
subscribeObserver(Endpoint aObserver) |
EndpointBuilder |
subscribeObserver(org.refcodes.net.HttpMethod aHttpMethod,
String aLocatorPattern,
RequestObserver aRequestObserver)
Registers a pre-configured
EndpointBuilder with the least
required attributes. and returns its instance. |
org.refcodes.net.MediaTypeFactory |
toMediaTypeFactory(org.refcodes.net.MediaType aMediaType) |
boolean |
unsubscribeObserver(Endpoint aObserver) |
clear, doHandleEventListenerException, fireEvent, getThreadPriority, hasObserverSubscription, isEmpty, setThreadPriority, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onDelete, onGet, onPost, onPut
public AbstractRestService()
AbstractRestService
pre-configured with
MediaTypeFactory
instances for JSON and REST.public AbstractRestService(ExecutorService aExecutorService)
AbstractRestService
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 boolean subscribeObserver(Endpoint aObserver)
public EndpointBuilder subscribeObserver(org.refcodes.net.HttpMethod aHttpMethod, String aLocatorPattern, RequestObserver aRequestObserver)
RestService
EndpointBuilder
with the least
required attributes. and returns its instance. To unsubscribe via
#unsubscribeObserver(EndpointBuilder)
, use the returned instance.subscribeObserver
in interface RestService
aHttpMethod
- The HTTP method to which this EndpointBuilder
is bound.aLocatorPattern
- The local locator pattern to which this
EndpointBuilder
is bound.aRequestObserver
- The Command
processing a request targeted
at this EndpointBuilder
.EndpointBuilder
which acts as handle
to unsubscribe the EndpointBuilder
.public boolean unsubscribeObserver(Endpoint aObserver)
public boolean addMediaTypeFactory(org.refcodes.net.MediaTypeFactory aMediaTypeFactory)
RestService
MediaTypeFactory
for marshaling and unmarshaling a
HTTP request's body of the according MediaType
. A
MediaTypeFactory
is responsible for exactly one MediaType
, declared via the MediaTypeAccessor.getMediaType()
method. .addMediaTypeFactory
in interface RestService
aMediaTypeFactory
- The MediaTypeFactory
to be registered.MediaTypeFactory
has successfully been
registered, false in case there has already a
MediaTypeFactory
been registered which is responsible for
the provided MediaTypeFactory
's MediaType
.public org.refcodes.net.MediaTypeFactory toMediaTypeFactory(org.refcodes.net.MediaType aMediaType)
toMediaTypeFactory
in interface org.refcodes.net.MediaTypeFactoryLookup
public void dispose()
dispose
in interface org.refcodes.mixin.Disposable
dispose
in class org.refcodes.observer.impls.AbstractObservable<Endpoint,org.refcodes.net.HttpRequest>
protected org.refcodes.net.HttpServerResponse onHttpRequest(org.refcodes.net.HttpMethod aHttpMethod, String aLocator, String aQueryString, org.refcodes.net.RequestHeaderFields aRequestHeaderFields, String aRequestBody) throws org.refcodes.net.HttpException
Endpoint
instances. An extension might call this method from inside an event
(request) handler.aHttpMethod
- The HttpMethod
of the request.aLocator
- The locator (URL) targeted by the request (without the
query string).aQueryString
- The query string part of the request.aRequestHeaderFields
- The header fields (HeaderFields
)
belonging to the request.aRequestBody
- The body passed by the request.HttpServerResponse
instance to by used by the extension
to produce an according HTTP response.org.refcodes.net.HttpException
- thrown in case of an Endpoint
responsible
for the given request encountered a problem or none
Endpoint
felt responsible to produce a
HttpServerResponse
.protected boolean fireEvent(org.refcodes.net.HttpRequest aEvent, Endpoint aObserver, org.refcodes.controlflow.ExecutionStrategy aExecutionStrategy) throws org.refcodes.exception.VetoException
fireEvent
in class org.refcodes.observer.impls.AbstractObservable<Endpoint,org.refcodes.net.HttpRequest>
org.refcodes.exception.VetoException
Copyright © 2016. All rights reserved.