public abstract class AbstractHttpServer extends Object implements HttpServer, HttpServerStats
HttpServer
implementations.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractHttpServer.SimpleSecurityContext
Simple implementation of the SecurityContext interface.
|
Modifier and Type | Field and Description |
---|---|
static String |
ATTR_SUBJECT
Attribute name that should be used to store Subject for the request.
|
static String |
AUTH_BASIC
HTTP basic authentication.
|
static String |
AUTH_CERT
Certificate authentication.
|
static String |
AUTH_CERT_BASIC
Certificate authentication.
|
static String |
AUTH_NONE
No authentication.
|
static String |
DEFAULT_ADDRESS
Default HTTP server address.
|
static IdentityAsserter |
DEFAULT_IDENTITY_ASSERTER
Default identity asserter.
|
static int |
DEFAULT_PORT
Default HTTP server port.
|
static String |
HEADER_AUTHORIZATION
Authorization header.
|
protected static String |
HEADER_WWW_AUTHENTICATE
WWW-Authenticate header.
|
static String |
HTTP_BASIC_REALM
Realm for HTTP basic authentication.
|
protected boolean |
m_fStarted
Flag specifying whether the server is already started.
|
protected IdentityAsserter |
m_identityAsserter
Identity asserter to use with HTTP basic authentication.
|
protected Map<String,org.glassfish.jersey.server.ResourceConfig> |
m_mapResourceConfig
Map of context names to Jersey resource configurations.
|
protected int |
m_nPort
Port number server should listen on.
|
protected String |
m_sAddr
Address server should listen on.
|
protected String |
m_sAuthMethod
Authentication method.
|
protected Service |
m_serviceParent
Parent service.
|
protected Session |
m_session
Coherence session.
|
protected com.oracle.common.net.SocketProvider |
m_socketProvider
SocketProvider used by the server.
|
Constructor and Description |
---|
AbstractHttpServer() |
Modifier and Type | Method and Description |
---|---|
protected Subject |
authenticate(String sAuth)
Perform HTTP Basic authentication and return authenticated Subject.
|
protected Object |
createContainer(org.glassfish.jersey.server.ResourceConfig resourceConfig)
Create and configure a Jersey container that will process HTTP requests.
|
protected void |
dumpStats()
Helper to dump current stats.
|
float |
getAverageRequestTime()
Return the average processing time in milliseconds.
|
long |
getErrorCount()
Return the number of requests that caused errors.
|
long |
getHttpStatusCount(int nPrefix)
Return the count of Http status codes with the given prefix.
|
IdentityAsserter |
getIdentityAsserter()
Return identity asserter to use for HTTP basic authentication.
|
String |
getLocalAddress()
Return the address the server should listen on.
|
int |
getLocalPort()
Return the port number the server should listen on.
|
Service |
getParentService()
Return the service that is embedding this server.
|
long |
getRequestCount()
Return the number of requests serviced since the HTTP server was started or the statistics were reset.
|
float |
getRequestsPerSecond()
Return the number of requests per second since the statistics were reset.
|
Map<String,org.glassfish.jersey.server.ResourceConfig> |
getResourceConfig()
Return map of context names to Jersey resource configurations.
|
Session |
getSession()
Return the Coherence
Session to use. |
com.oracle.common.net.SocketProvider |
getSocketProvider()
Return the SocketProvider to use.
|
SSLContext |
getSSLContext()
Return the SSLContext to use.
|
SSLParameters |
getSSLParameters()
Return the SSLParameters to use.
|
protected Subject |
getSubjectFromSession(SSLSession session)
Creates Subject instance using principal and credentials from the SSL session.
|
protected void |
handleRequest(org.glassfish.jersey.server.ApplicationHandler app, org.glassfish.jersey.server.ContainerRequest request, Subject subject)
Handle HTTP(S) request.
|
protected void |
incrementErrors()
Increment the number of errors.
|
protected void |
incrementRequestCount()
Increment the request count.
|
protected abstract Object |
instantiateContainer(org.glassfish.jersey.server.ResourceConfig config, org.glassfish.hk2.api.ServiceLocator locator)
Factory method for Jersey container instances.
|
protected boolean |
isAuthMethodBasic()
Return true if this server should use HTTP basic authentication.
|
protected boolean |
isAuthMethodCert()
Return true if this server should use client certificates for authentication.
|
protected boolean |
isAuthMethodNone()
Return true if this server should not require client authentication.
|
protected boolean |
isSecure()
Return true if this server uses SSL to secure communication.
|
protected void |
logRequestTime(long ltdStartTime)
Add to the total request time.
|
protected void |
logStatusCount(int nStatusCode)
Add to the total of status codes.
|
void |
resetStats()
Reset the statistics.
|
void |
setAuthMethod(String sMethod)
Set the client authentication method to use.
|
protected void |
setIdentityAsserter(IdentityAsserter asserter)
Configure the identity asserter to use for HTTP basic authentication.
|
void |
setLocalAddress(String sAddr)
Set the address server should listen on.
|
void |
setLocalPort(int nPort)
Set the port number server should listen on.
|
void |
setParentService(Service service)
Set the Service that is embedding this HttpServer.
|
void |
setResourceConfig(Map<String,org.glassfish.jersey.server.ResourceConfig> mapConfig)
Set the map of Jersey ResourceConfig to use.
|
void |
setResourceConfig(org.glassfish.jersey.server.ResourceConfig config)
Set the Jersey ResourceConfig to use.
|
void |
setSession(Session session)
Set Coherence session to use.
|
void |
setSocketProvider(com.oracle.common.net.SocketProvider provider)
Set the SocketProvider to use.
|
void |
start()
Start the server.
|
protected abstract void |
startInternal()
Start the server.
|
void |
stop()
Stop the server.
|
protected abstract void |
stopInternal()
Stop the server.
|
String |
toString() |
protected String m_sAuthMethod
protected Session m_session
protected String m_sAddr
protected int m_nPort
protected Service m_serviceParent
protected Map<String,org.glassfish.jersey.server.ResourceConfig> m_mapResourceConfig
protected com.oracle.common.net.SocketProvider m_socketProvider
protected IdentityAsserter m_identityAsserter
protected boolean m_fStarted
public static final String DEFAULT_ADDRESS
public static final int DEFAULT_PORT
public static final IdentityAsserter DEFAULT_IDENTITY_ASSERTER
public static final String AUTH_BASIC
public static final String AUTH_CERT
public static final String AUTH_CERT_BASIC
public static final String AUTH_NONE
public static final String HTTP_BASIC_REALM
public static final String ATTR_SUBJECT
public static final String HEADER_AUTHORIZATION
protected static final String HEADER_WWW_AUTHENTICATE
public void setAuthMethod(String sMethod)
Valid values basic for HTTP basic authentication, cert for client certificate authentication, cert+basic for both client certificate and HTTP basic authentication, and none for no authentication.
setAuthMethod
in interface HttpServer
sMethod
- the authentication method to usepublic void setSession(Session session)
setSession
in interface HttpServer
session
- the Coherence sessionpublic void setLocalAddress(String sAddr)
setLocalAddress
in interface HttpServer
sAddr
- the addresspublic void setLocalPort(int nPort)
setLocalPort
in interface HttpServer
nPort
- the port numberpublic void setParentService(Service service)
setParentService
in interface HttpServer
service
- the parent servicepublic void setResourceConfig(org.glassfish.jersey.server.ResourceConfig config)
This method will register specified application under the root context, which is equivalent to: setResourceConfig(Collections.singletonMap("/", config));
setResourceConfig
in interface HttpServer
config
- the resource config for a Jersey web applicationpublic void setResourceConfig(Map<String,org.glassfish.jersey.server.ResourceConfig> mapConfig)
setResourceConfig
in interface HttpServer
mapConfig
- the map of context names to corresponding Jersey resource configs to usepublic void setSocketProvider(com.oracle.common.net.SocketProvider provider)
setSocketProvider
in interface HttpServer
provider
- the SocketProviderpublic void start() throws IOException
start
in interface HttpServer
IOException
- if an error occurspublic void stop() throws IOException
stop
in interface HttpServer
IOException
- if an error occurspublic long getRequestCount()
HttpServerStats
getRequestCount
in interface HttpServerStats
public float getAverageRequestTime()
HttpServerStats
getAverageRequestTime
in interface HttpServerStats
public float getRequestsPerSecond()
HttpServerStats
getRequestsPerSecond
in interface HttpServerStats
public long getErrorCount()
HttpServerStats
getErrorCount
in interface HttpServerStats
public long getHttpStatusCount(int nPrefix)
HttpServerStats
getHttpStatusCount
in interface HttpServerStats
nPrefix
- the prefix to return count forpublic void resetStats()
HttpServerStats
resetStats
in interface HttpServerStats
protected void incrementRequestCount()
protected void logRequestTime(long ltdStartTime)
ltdStartTime
- the start of the requestprotected void incrementErrors()
protected void logStatusCount(int nStatusCode)
nStatusCode
- the status code to addprotected void dumpStats()
protected abstract void startInternal() throws IOException
IOException
- if an error occursprotected abstract void stopInternal() throws IOException
IOException
- if an error occursprotected abstract Object instantiateContainer(org.glassfish.jersey.server.ResourceConfig config, org.glassfish.hk2.api.ServiceLocator locator)
config
- the resource configurationlocator
- the parent service locatorprotected Object createContainer(org.glassfish.jersey.server.ResourceConfig resourceConfig)
resourceConfig
- resource configurationprotected Subject authenticate(String sAuth)
sAuth
- the value of Authorization header from the requestprotected Subject getSubjectFromSession(SSLSession session) throws SSLPeerUnverifiedException
session
- SSL sessionSSLPeerUnverifiedException
- if the client is not authenticatedprotected void handleRequest(org.glassfish.jersey.server.ApplicationHandler app, org.glassfish.jersey.server.ContainerRequest request, Subject subject) throws IOException
app
- web application that should handle requestrequest
- the requestsubject
- the subject, can be nullIOException
- if an error occurspublic String getLocalAddress()
public int getLocalPort()
public Service getParentService()
public com.oracle.common.net.SocketProvider getSocketProvider()
public SSLContext getSSLContext()
public SSLParameters getSSLParameters()
public Map<String,org.glassfish.jersey.server.ResourceConfig> getResourceConfig()
public IdentityAsserter getIdentityAsserter()
protected void setIdentityAsserter(IdentityAsserter asserter)
asserter
- the identity asserter to useprotected boolean isAuthMethodBasic()
protected boolean isAuthMethodCert()
protected boolean isAuthMethodNone()
protected boolean isSecure()