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.MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
org.refcodes.net.RealmAccessor.RealmBuilder<B extends org.refcodes.net.RealmAccessor.RealmBuilder<B>>, org.refcodes.net.RealmAccessor.RealmMutator, org.refcodes.net.RealmAccessor.RealmProperty
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.LinkComponent.LinkAutomaton, org.refcodes.component.LinkComponent.LinkComponentBuilder<B extends org.refcodes.component.LinkComponent.LinkComponentBuilder<B>>
org.refcodes.component.Openable.OpenAutomaton, org.refcodes.component.Openable.OpenBuilder<B extends org.refcodes.component.Openable.OpenBuilder<B>>
org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusMutator, org.refcodes.component.ConnectionStatusAccessor.ConnectionStatusProperty
org.refcodes.component.ConnectionComponent.ConnectionAutomaton<CON>, org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON,B extends org.refcodes.component.ConnectionComponent.ConnectionComponentBuilder<CON,B>>
org.refcodes.component.ConnectionOpenable.ConnectionOpenAutomaton<CON>, org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON,B extends org.refcodes.component.ConnectionOpenable.ConnectionOpenBuilder<CON,B>>
org.refcodes.component.Closable.CloseAutomaton, org.refcodes.component.Closable.CloseBuilder<B extends org.refcodes.component.Closable.CloseBuilder<B>>
org.refcodes.mixin.PortAccessor.PortBuilder<B extends org.refcodes.mixin.PortAccessor.PortBuilder<B>>, org.refcodes.mixin.PortAccessor.PortMutator, org.refcodes.mixin.PortAccessor.PortProperty
org.refcodes.net.SchemeAccessor.SchemeBuilder<B extends org.refcodes.net.SchemeAccessor.SchemeBuilder<B>>, org.refcodes.net.SchemeAccessor.SchemeMutator, org.refcodes.net.SchemeAccessor.SchemeProperty
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.io.MaxConnectionsAccessor.MaxConnectionsBuilder<B extends org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsBuilder<B>>, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsMutator, org.refcodes.io.MaxConnectionsAccessor.MaxConnectionsProperty
Modifier and Type | Field and Description |
---|---|
protected static String |
CONTEXT_PATH |
_hasRequestCorrelation, _hasSessionCorrelation
Constructor and Description |
---|
HttpRestServerImpl()
Constructs a
HttpRestServerImpl . |
HttpRestServerImpl(ExecutorService aExecutorService)
Constructs a
HttpRestServerImpl . |
Modifier and Type | Method and 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) |
addMediaTypeFactory, dispose, doRequestCorrelation, doSessionCorrelation, fireEvent, getBaseLocator, getFactoryMediaTypes, getRealm, hasRequestCorrelation, hasSessionCorrelation, initMedaTypeFactories, isObserversActive, observers, onHttpRequest, setBaseLocator, setObserversActive, setRealm, setRequestCorrelation, setSessionCorrelation, subscribeObserver, toMediaTypeFactory, toNegotiatedContenType, toResponseBody, unsubscribeObserver
clear, doHandleEventListenerException, fireEvent, getThreadPriority, hasObserverSubscription, isEmpty, setThreadPriority, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
open, open, open, open, open, open, open, open, open, open, open, open, withBaseLocator, withClose, withCloseIn, withCloseQuietly, withDisableRequestCorrelation, withDisableSessionCorrelation, withEnableRequestCorrelation, withEnableSessionCorrelation, withKeyStoreDescriptor, withMaxConnections, withOpen, withPort, withProtocol, withRequestCorrelation, withScheme, withSessionCorrelation
onDelete, onGet, onPost, onPut, onRequest, onRequest, onRequest, withDisableObservers, withEnableObservers, withObserversActive
hasObserverSubscription, subscribeObserver, unsubscribeObserver
disableObservers, enableObservers, isObserversActive, observers, setObserversActive
addMediaTypeFactory
getFactoryMediaTypes, hasMediaTypeFactory, toMediaTypeFactory
setBaseLocator
disableRequestCorrelation, enableRequestCorrelation, hasRequestCorrelation, setRequestCorrelation
disableSessionCorrelation, enableSessionCorrelation, hasSessionCorrelation, setSessionCorrelation
closeIn, closeQuietly, closeUnchecked
protected static final String CONTEXT_PATH
public HttpRestServerImpl()
HttpRestServerImpl
. Use HttpRestServer.open(int)
or
similar to make it listen on your port.public HttpRestServerImpl(ExecutorService aExecutorService)
HttpRestServerImpl
. Use HttpRestServer.open(int)
or
similar to make it listen on your port.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 org.refcodes.net.RealmAccessor.RealmBuilder<RestServer>
withRealm
in interface HttpRestServer
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.