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(File, String, Integer)
or
HttpRestServer.open(String, File, String, String, String, Integer)
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.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>>
Modifier and Type | Field and Description |
---|---|
protected static String |
CONTEXT_PATH |
_hasRequestCorrelation, _hasSessionCorrelation
DEFAULT_KEYSTORE_FORMAT, DEFAULT_SSL_PROTOCOL
Constructor and Description |
---|
HttpRestServerImpl()
Constructs a
HttpRestServerImpl listening to the given
localhost's port for HTTP-Requests. |
HttpRestServerImpl(ExecutorService aExecutorService)
Constructs a
HttpRestServerImpl listening to the given
localhost's port for HTTP-Requests. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected com.sun.net.httpserver.HttpServer |
getHttpServer()
Gets the http server.
|
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(Integer aPort) |
void |
open(Integer aPort,
int aMaxConnections)
Opens the HTTP sever connection (socket) at the given port allowing the
given number of maximum connections at the same time.
|
void |
open(String aSecureSocketProtocol,
File aKeyStoreFile,
String aKeyStoreType,
String aKeyStorePassword,
String aKeyPassword,
Integer 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.
|
HttpRestServer |
withRealm(String aRealm) |
addMediaTypeFactory, dispose, doRequestCorrelation, doSessionCorrelation, fireEvent, getBaseLocator, getFactoryMediaTypes, getRealm, hasRequestCorrelation, hasSessionCorrelation, initMedaTypeFactories, onHttpRequest, onRequest, setBaseLocator, 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, withBaseLocator, withClose, withCloseIn, withCloseQuietly, withDisableRequestCorrelation, withDisableSessionCorrelation, withEnableRequestCorrelation, withEnableSessionCorrelation, withOpen, withRequestCorrelation, withSessionCorrelation
onDelete, onGet, onPost, onPut, onRequest, onRequest, onRequest
hasObserverSubscription, subscribeObserver, unsubscribeObserver
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
listening to the given
localhost's port for HTTP-Requests.public HttpRestServerImpl(ExecutorService aExecutorService)
HttpRestServerImpl
listening to the given
localhost's port for HTTP-Requests.aExecutorService
- An executor service to be used when creating
Thread
s.public void open(Integer aPort) throws org.refcodes.component.OpenException
open
in interface org.refcodes.component.ConnectionOpenable<Integer>
org.refcodes.component.OpenException
public void open(Integer aPort, int aMaxConnections) throws org.refcodes.component.OpenException
open
in interface HttpRestServer
aPort
- The port on which to listen for requests.aMaxConnections
- The number of maximum connections at the same timeorg.refcodes.component.OpenException
- thrown in case something went wrong such as the
port being already in use.public void close() throws org.refcodes.component.CloseException
close
in interface org.refcodes.component.Closable
org.refcodes.component.CloseException
public void open(String aSecureSocketProtocol, File aKeyStoreFile, String aKeyStoreType, String aKeyStorePassword, String aKeyPassword, Integer aPort, int aMaxConnections) throws org.refcodes.component.OpenException
open
in interface HttpRestServer
aSecureSocketProtocol
- The protocol to use, e.g. "TLS".aKeyStoreFile
- The file pointing to your KeyStore
.aKeyStoreType
- The type of KeyStore
, e.g. "JKS" format.aKeyStorePassword
- The password for the KeyStore
.aKeyPassword
- The password for the KeyStore
's key.aPort
- The port on which to listen for requests.aMaxConnections
- The number of maximum connections at the same timeorg.refcodes.component.OpenException
- thrown in case something went wrong such as the
port being already in use.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
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 © 2017. All rights reserved.