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.component.OpenedAccessor
, 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.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.KeyStoreDescriptorProperty
, org.refcodes.web.BaseLocatorAccessor
, org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<RestServer>
, org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator
, org.refcodes.web.BaseLocatorAccessor.BaseLocatorProperty
, org.refcodes.web.BasicAuthObservable<RestServer>
, org.refcodes.web.HttpsConnectionRequestObservable<RestServer>
, org.refcodes.web.MediaTypeFactoryLookup
, org.refcodes.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
, org.refcodes.web.RealmAccessor
, org.refcodes.web.RealmAccessor.RealmBuilder<RestServer>
, org.refcodes.web.RealmAccessor.RealmMutator
, org.refcodes.web.RealmAccessor.RealmProperty
, org.refcodes.web.SchemeAccessor
, org.refcodes.web.SchemeAccessor.SchemeBuilder<RestServer>
, org.refcodes.web.SchemeAccessor.SchemeMutator
, org.refcodes.web.SchemeAccessor.SchemeProperty
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:
JsonMediaTypeFactory
XmlMediaTypeFactory
TextMediaTypeFactory
FormMediaTypeFactory
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.web.BaseLocatorAccessor.BaseLocatorBuilder<B extends org.refcodes.web.BaseLocatorAccessor.BaseLocatorBuilder<B>>, org.refcodes.web.BaseLocatorAccessor.BaseLocatorMutator, org.refcodes.web.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.web.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>
org.refcodes.component.OpenedAccessor.OpenedMutator, org.refcodes.component.OpenedAccessor.OpenedProperty
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 HttpServer |
getHttpServer() |
Gets the http server.
|
org.refcodes.security.KeyStoreDescriptor |
getKeyStoreDescriptor() |
|
int |
getMaxConnections() |
|
int |
getPort() |
|
org.refcodes.data.Scheme |
getScheme() |
|
HttpRestServer |
onBasicAuthRequest(org.refcodes.web.BasicAuthObserver aBasicAuthObserver) |
|
HttpRestServer |
onConnectionRequest(org.refcodes.web.HttpsConnectionRequestObserver aObserver) |
|
protected void |
open(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
letBaseLocator
closeIn, closeQuietly, closeUnchecked
withOpenUnchecked
getHttpExceptionHandler
withOnHttpException
onHttpException, setHttpExceptionHandler
letHttpExceptionHandler
getHttpExceptionHandling
setHttpExceptionHandling
letHttpExceptionHandling
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
letKeyStoreDescriptor
alert, alert, critical, critical, debug, error, info, notice, panic, trace, warn, warn
letMaxConnections
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, onDelete, onGet, onGet, onPost, onPost, onPut, onPut, onRequest, onRequest, 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 IOException
close
in interface org.refcodes.component.Closable
IOException
public void open(String aProtocol, org.refcodes.security.KeyStoreDescriptor aStoreDescriptor, int aPort, int aMaxConnections) throws IOException
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.IOException
- 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.web.HttpsConnectionRequestObserver aObserver)
onConnectionRequest
in interface org.refcodes.web.HttpsConnectionRequestObservable<RestServer>
public HttpRestServer onBasicAuthRequest(org.refcodes.web.BasicAuthObserver aBasicAuthObserver)
onBasicAuthRequest
in interface org.refcodes.web.BasicAuthObservable<RestServer>
public HttpRestServer withRealm(String aRealm)
withRealm
in interface HttpRestServer
withRealm
in interface org.refcodes.web.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.web.SchemeAccessor.SchemeMutator
public org.refcodes.data.Scheme getScheme()
getScheme
in interface org.refcodes.web.SchemeAccessor
public String toProtocol()
toProtocol
in interface org.refcodes.web.SchemeAccessor
public void setProtocol(String aProtocol)
setProtocol
in interface org.refcodes.web.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 HttpServer getHttpServer()
protected void open(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 © 2021. All rights reserved.