org.refcodes.component.Closable
, org.refcodes.component.Closable.CloseBuilder<org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.net.HttpServerContext,HttpRestServer>>
, org.refcodes.component.ConnectionComponent<org.refcodes.net.HttpServerContext>
, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.net.HttpServerContext,HttpRestServer>
, org.refcodes.component.ConnectionOpenable<org.refcodes.net.HttpServerContext>
, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<org.refcodes.net.HttpServerContext,org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<org.refcodes.net.HttpServerContext,HttpRestServer>>
, org.refcodes.component.ConnectionStatusAccessor
, org.refcodes.component.LinkComponent
, org.refcodes.component.Openable
, org.refcodes.io.MaxConnectionsAccessor
, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<HttpRestServer>
, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator
, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsProperty
, org.refcodes.mixin.Disposable
, org.refcodes.mixin.Loggable
, org.refcodes.mixin.PortAccessor
, org.refcodes.mixin.PortAccessor.PortBuilder<HttpRestServer>
, 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<HttpRestServer>
, org.refcodes.net.HttpsConnectionRequestObservable<HttpRestServer>
, 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<HttpRestServer>
, org.refcodes.net.SchemeAccessor.SchemeMutator
, org.refcodes.net.SchemeAccessor.SchemeProperty
, 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
, HttpRestServer
, RestServer
, org.refcodes.runtime.RequestCorrelation<RestServer>
, org.refcodes.runtime.SessionCorrelation<RestServer>
, org.refcodes.security.KeyStoreDescriptorAccessor
, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<HttpRestServer>
, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator
, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorProperty
HttpRestServerSingleton
public 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:
ApplicationJsonFactory
ApplicationXmlFactory
TextPlainFactory
ApplicationFormFactory
HttpRestServerImpl
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.BaseLocatorProperty
org.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.ConnectionStatusProperty
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
org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<B extends org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorBuilder<B>>, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator, org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorProperty
org.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.MaxConnectionsProperty
org.refcodes.net.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
org.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, size
addMediaTypeFactory, 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, unsubscribeObserver
setBaseLocator
closeIn, closeQuietly, closeUnchecked
withOpenUnchecked
getHttpExceptionHandler
withOnHttpException
onHttpException, setHttpExceptionHandler
getHttpExceptionHandling
setHttpExceptionHandling
open, 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, withSessionCorrelation
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
getFactoryMediaTypes, hasMediaTypeFactory, toMediaTypeFactory
addMediaTypeFactory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hasObserverSubscription, subscribeObserver, unsubscribeObserver
disableObservers, enableObservers, isObserversActive, observers, setObserversActive
disableRequestCorrelation, enableRequestCorrelation, hasRequestCorrelation, setRequestCorrelation
onDelete, onGet, onPost, onPut, onRequest, onRequest, onRequest, withDisableObservers, withEnableObservers, withObserversActive
protected 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
Thread
s.public void close() throws org.refcodes.component.CloseException
close
in interface org.refcodes.component.Closable
org.refcodes.component.CloseException
public void open(String aProtocol, org.refcodes.security.KeyStoreDescriptor aStoreDescriptor, int aPort, int aMaxConnections) throws org.refcodes.component.OpenException
open
in interface HttpRestServer
aProtocol
- 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.ConnectionStatusAccessor
public HttpRestServer onConnectionRequest(org.refcodes.net.HttpsConnectionRequestObserver aObserver)
onConnectionRequest
in interface org.refcodes.net.HttpsConnectionRequestObservable<HttpRestServer>
public HttpRestServer onBasicAuthRequest(org.refcodes.net.BasicAuthObserver aBasicAuthObserver)
onBasicAuthRequest
in interface org.refcodes.net.BasicAuthObservable<HttpRestServer>
public HttpRestServer withRealm(String aRealm)
withRealm
in interface HttpRestServer
withRealm
in interface org.refcodes.net.RealmAccessor.RealmBuilder<RestServer>
withRealm
in interface RestServer
public void setPort(int aPort)
setPort
in interface org.refcodes.mixin.PortAccessor.PortMutator
public int getPort()
getPort
in interface org.refcodes.mixin.PortAccessor
public void setScheme(org.refcodes.data.Scheme aScheme)
setScheme
in interface org.refcodes.net.SchemeAccessor.SchemeMutator
public org.refcodes.data.Scheme getScheme()
getScheme
in interface org.refcodes.net.SchemeAccessor
public String toProtocol()
toProtocol
in interface org.refcodes.net.SchemeAccessor
public void setProtocol(String aProtocol)
setProtocol
in interface org.refcodes.net.SchemeAccessor.SchemeMutator
public org.refcodes.security.KeyStoreDescriptor getKeyStoreDescriptor()
getKeyStoreDescriptor
in interface org.refcodes.security.KeyStoreDescriptorAccessor
public void setKeyStoreDescriptor(org.refcodes.security.KeyStoreDescriptor aStoreDescriptor)
setKeyStoreDescriptor
in interface org.refcodes.security.KeyStoreDescriptorAccessor.KeyStoreDescriptorMutator
public int getMaxConnections()
getMaxConnections
in interface org.refcodes.io.MaxConnectionsAccessor
public void setMaxConnections(int aMaxConnections)
setMaxConnections
in interface org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator
protected 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.