org.refcodes.component.Closable, org.refcodes.component.Closable.CloseBuilder<RestServer>, org.refcodes.component.ConnectionComponent<RestServer>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<RestEndpoint,RestServer>, org.refcodes.component.ConnectionOpenable<RestServer>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<RestEndpoint,RestServer>, org.refcodes.component.ConnectionStatusAccessor, org.refcodes.component.LinkComponent, org.refcodes.component.Openable, org.refcodes.io.MaxConnectionsAccessor, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<RestServer>, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsProperty, org.refcodes.mixin.PortAccessor, org.refcodes.mixin.PortAccessor.PortBuilder<RestServer>, org.refcodes.mixin.PortAccessor.PortMutator, org.refcodes.mixin.PortAccessor.PortProperty, org.refcodes.net.BaseLocatorAccessor, org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<RestServer>, org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.net.BaseLocatorAccessor.BaseLocatorProperty, org.refcodes.net.BasicAuthObservable<RestServer>, org.refcodes.net.HttpsConnectionRequestObservable<RestServer>, 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.net.SchemeAccessor, org.refcodes.net.SchemeAccessor.SchemeBuilder<RestServer>, org.refcodes.net.SchemeAccessor.SchemeMutator, org.refcodes.net.SchemeAccessor.SchemeProperty, org.refcodes.observer.Observable<RestServer>, org.refcodes.observer.Observers<RestEndpoint,RestServer>, HttpExceptionHandlerAccessor, HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<RestServer>, HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator, HttpExceptionHandlerAccessor.HttpExceptionHandlerProperty, HttpExceptionHandlingAccessor, HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<RestServer>, HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator, HttpExceptionHandlingAccessor.HttpExceptionHandlingProperty, HttpRestServer, RestServer, org.refcodes.runtime.RequestCorrelation<RestServer>, org.refcodes.runtime.SessionCorrelation<RestServer>, org.refcodes.security.KeyStoreDescriptorAccessor, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<RestServer>, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorPropertyHttpRestServerSingletonpublic class HttpRestServerImpl extends AbstractRestServer implements HttpRestServer
HttpRestServer interface using the
HttpServer defined in the com.sun.net.httpserver
package.
The HttpRestServerImpl is being initialized with some common
MediaTypeFactory instances (as implemented by the
AbstractRestServer). At the time of writing this document the
MediaTypeFactory instances being pre-configured are:
ApplicationJsonFactoryApplicationXmlFactoryTextPlainFactoryApplicationFormFactoryHttpRestServerImpl supports HTTP as well as HTTPS protocols as
being based on the HttpServer as well as on the HttpsServer.
For opening up an HTTPS connection, refer to the methods such as
HttpRestServer.open(String, KeyStoreDescriptor, int) or
HttpRestServer.open(KeyStoreDescriptor, int) and the like.org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<B extends org.refcodes.net.BaseLocatorAccessor.BaseLocatorBuilder<B>>, org.refcodes.net.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.net.BaseLocatorAccessor.BaseLocatorPropertyorg.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>org.refcodes.component.ConnectionComponent.ConnectionAutomaton<CON extends Object>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON extends Object,B extends org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON,B>>org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<CON extends Object>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON extends Object,B extends org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON,B>>org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusPropertyorg.refcodes.mixin.Disposable.DisposedableHttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<B extends HttpExceptionHandlerAccessor.HttpExceptionHandlerBuilder<B>>, HttpExceptionHandlerAccessor.HttpExceptionHandlerMutator, HttpExceptionHandlerAccessor.HttpExceptionHandlerPropertyHttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<B extends HttpExceptionHandlingAccessor.HttpExceptionHandlingBuilder<B>>, HttpExceptionHandlingAccessor.HttpExceptionHandlingMutator, HttpExceptionHandlingAccessor.HttpExceptionHandlingPropertyorg.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<B extends org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<B>>, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorPropertyorg.refcodes.component.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<B extends org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<B>>, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsPropertyorg.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookuporg.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>org.refcodes.mixin.PortAccessor.PortBuilder<B extends org.refcodes.mixin.PortAccessor.PortBuilder<B>>, org.refcodes.mixin.PortAccessor.PortMutator, org.refcodes.mixin.PortAccessor.PortProperty| Modifier and Type | Field | Description |
|---|---|---|
protected static String |
CONTEXT_PATH |
_hasRequestCorrelation, _hasSessionCorrelation, _httpExceptionHandler, _httpExceptionHandling| Constructor | Description |
|---|---|
HttpRestServerImpl() |
Constructs a
HttpRestServerImpl. |
HttpRestServerImpl(ExecutorService aExecutorService) |
Constructs a
HttpRestServerImpl. |
HttpRestServerImpl(org.refcodes.controlflow.ThreadingModel aThreadingModel) |
Constructs a
HttpRestServerImpl. |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
org.refcodes.component.ConnectionStatus |
getConnectionStatus() |
|
protected com.sun.net.httpserver.HttpServer |
getHttpServer() |
Gets the http server.
|
org.refcodes.security.KeyStoreDescriptor |
getKeyStoreDescriptor() |
|
int |
getMaxConnections() |
|
int |
getPort() |
|
org.refcodes.data.Scheme |
getScheme() |
|
HttpRestServer |
onBasicAuthRequest(org.refcodes.net.BasicAuthObserver aBasicAuthObserver) |
|
HttpRestServer |
onConnectionRequest(org.refcodes.net.HttpsConnectionRequestObserver aObserver) |
|
protected void |
open(com.sun.net.httpserver.HttpServer aHttpServer) |
A hook to be used when using custom
HttpServer (
HttpsServer) by custom open(...) methods of sub-classes of this
HttpRestServerImpl. |
void |
open(String aProtocol,
org.refcodes.security.KeyStoreDescriptor aStoreDescriptor,
int aPort,
int aMaxConnections) |
Opens the HTTPS sever connection (socket) at the given port allowing the
given number of maximum connections at the same time using the provided
HTTPS configuration parameters.
|
void |
setKeyStoreDescriptor(org.refcodes.security.KeyStoreDescriptor aStoreDescriptor) |
|
void |
setMaxConnections(int aMaxConnections) |
|
void |
setPort(int aPort) |
|
void |
setProtocol(String aProtocol) |
|
void |
setScheme(org.refcodes.data.Scheme aScheme) |
|
String |
toProtocol() |
|
HttpRestServer |
withRealm(String aRealm) |
clear, doHandleEventListenerException, fireEvent, getThreadPriority, hasObserverSubscription, isEmpty, setThreadPriority, sizeaddMediaTypeFactory, dispose, doRequestCorrelation, doSessionCorrelation, fireEvent, getBaseLocator, getFactoryMediaTypes, getHttpExceptionHandler, getHttpExceptionHandling, getRealm, hasRequestCorrelation, hasSessionCorrelation, initMedaTypeFactories, isObserversActive, observers, onHttpRequest, setBaseLocator, setHttpExceptionHandler, setHttpExceptionHandling, setObserversActive, setRealm, setRequestCorrelation, setSessionCorrelation, subscribeObserver, toMediaTypeFactory, toNegotiatedContenType, toResponseBody, unsubscribeObserversetBaseLocatorcloseIn, closeQuietly, closeUncheckedwithOpenUncheckedgetHttpExceptionHandlerwithOnHttpExceptiononHttpException, setHttpExceptionHandlergetHttpExceptionHandlingsetHttpExceptionHandlingopen, open, open, open, open, open, open, open, open, open, open, open, withBaseLocator, withClose, withCloseIn, withCloseQuietly, withDisableRequestCorrelation, withDisableSessionCorrelation, withEnableRequestCorrelation, withEnableSessionCorrelation, withHttpExceptionHandler, withHttpExceptionHandling, withKeyStoreDescriptor, withMaxConnections, withOpen, withOpen, withPort, withProtocol, withRequestCorrelation, withScheme, withSessionCorrelationgetFactoryMediaTypes, hasMediaTypeFactory, toMediaTypeFactoryaddMediaTypeFactoryclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithasObserverSubscription, subscribeObserver, unsubscribeObserverdisableObservers, enableObservers, isObserversActive, observers, setObserversActivedisableRequestCorrelation, enableRequestCorrelation, hasRequestCorrelation, setRequestCorrelationonDelete, onGet, onPost, onPut, onRequest, onRequest, onRequest, withDisableObservers, withEnableObservers, withObserversActiveprotected static final String CONTEXT_PATH
public HttpRestServerImpl(org.refcodes.controlflow.ThreadingModel aThreadingModel)
HttpRestServerImpl. Use HttpRestServer.open(int) or
similar to make it listen on your port.
The provided ThreadingModel defines whether to use a
single-threaded or a multi-threaded threading model. Threads are created
as daemon threads. For more control on thread generation use the
constructor HttpRestServerImpl(ExecutorService).aThreadingModel - Specifies to either use a single-threaded
threading model (no ExecutorService) or a multi-threaded
threading model with a default ExecutorService as of
ControlFlowUtility.createCachedExecutorService(boolean).public HttpRestServerImpl()
HttpRestServerImpl. Use HttpRestServer.open(int) or
similar to make it listen on your port.
Uses a multi threaded threading model with a default
ExecutorService as of
ControlFlowUtility.createCachedExecutorService(boolean). Threads
are created as daemon threads. For more control on thread generation use
the constructor HttpRestServerImpl(ExecutorService).public HttpRestServerImpl(ExecutorService aExecutorService)
HttpRestServerImpl. Use HttpRestServer.open(int) or
similar to make it listen on your port.
Uses a multi threaded threading model.aExecutorService - An executor service to be used when creating
Threads.public void close()
throws org.refcodes.component.CloseException
close in interface org.refcodes.component.Closableorg.refcodes.component.CloseExceptionpublic void open(String aProtocol, org.refcodes.security.KeyStoreDescriptor aStoreDescriptor, int aPort, int aMaxConnections) throws org.refcodes.component.OpenException
open in interface HttpRestServeraProtocol - The protocol to use, e.g. "TLS".aStoreDescriptor - The store descriptor describing your
KeyStore required for HTTPS.aPort - The port on which to listen for requests.aMaxConnections - The number of maximum connections at the same
time.org.refcodes.component.OpenException - thrown in case something went wrong such as the
port being already in use.public org.refcodes.component.ConnectionStatus getConnectionStatus()
getConnectionStatus in interface org.refcodes.component.ConnectionStatusAccessorpublic HttpRestServer onConnectionRequest(org.refcodes.net.HttpsConnectionRequestObserver aObserver)
onConnectionRequest in interface org.refcodes.net.HttpsConnectionRequestObservable<RestServer>public HttpRestServer onBasicAuthRequest(org.refcodes.net.BasicAuthObserver aBasicAuthObserver)
onBasicAuthRequest in interface org.refcodes.net.BasicAuthObservable<RestServer>public HttpRestServer withRealm(String aRealm)
withRealm in interface HttpRestServerwithRealm in interface org.refcodes.net.RealmAccessor.RealmBuilder<RestServer>withRealm in interface RestServerpublic void setPort(int aPort)
setPort in interface org.refcodes.mixin.PortAccessor.PortMutatorpublic int getPort()
getPort in interface org.refcodes.mixin.PortAccessorpublic void setScheme(org.refcodes.data.Scheme aScheme)
setScheme in interface org.refcodes.net.SchemeAccessor.SchemeMutatorpublic org.refcodes.data.Scheme getScheme()
getScheme in interface org.refcodes.net.SchemeAccessorpublic String toProtocol()
toProtocol in interface org.refcodes.net.SchemeAccessorpublic void setProtocol(String aProtocol)
setProtocol in interface org.refcodes.net.SchemeAccessor.SchemeMutatorpublic org.refcodes.security.KeyStoreDescriptor getKeyStoreDescriptor()
getKeyStoreDescriptor in interface org.refcodes.security.KeyStoreDescriptorAccessorpublic void setKeyStoreDescriptor(org.refcodes.security.KeyStoreDescriptor aStoreDescriptor)
setKeyStoreDescriptor in interface org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutatorpublic int getMaxConnections()
getMaxConnections in interface org.refcodes.io.MaxConnectionsAccessorpublic void setMaxConnections(int aMaxConnections)
setMaxConnections in interface org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutatorprotected com.sun.net.httpserver.HttpServer getHttpServer()
protected void open(com.sun.net.httpserver.HttpServer aHttpServer)
throws IOException
HttpServer (
HttpsServer) by custom open(...) methods of sub-classes of this
HttpRestServerImpl. E.g HttpRestServerImpl uses this hook
to pre-configure a HttpsServer for HTTPS.
The passed HttpServer ( HttpsServer) must already be
bound to a port and enabled with the number of concurrent connections as
of HttpServer.bind(InetSocketAddress, int).aHttpServer - The HttpServer to be used. E.g. an
HttpsServer might be used to enable HTTPS.IOException - in case opening with the provided
HttpRestServer fails.Copyright © 2018. All rights reserved.