public class GenericWebServer extends java.lang.Object implements HttpConfigurationConstants
Modifier and Type | Field and Description |
---|---|
private BootstrapConfig |
config
The bootstrap configuration
|
private java.lang.String |
contextPath
Context path
|
private boolean |
enableConscrypt
Whether Conscrypt SSL provider will be enabled
|
private org.eclipse.jetty.server.handler.HandlerCollection |
handlerCollection
Context Handlers
|
private java.lang.String |
host
Server host name
|
private org.eclipse.jetty.server.HttpConfiguration |
httpConfiguration
The common http configuration settings
|
protected static java.util.logging.Logger |
LOG
Logger.
|
private org.eclipse.jetty.util.thread.QueuedThreadPool |
pool
The thread pool.
|
private int |
port
Server port
|
private static edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger |
SCHEDULER_ID
ScheduledExecutorScheduler ID generator
|
private org.eclipse.jetty.server.Server |
server
Embedded jetty server
|
private ServerKeyStore |
serverKeyStore
Exported server key store
|
MAX_HTTP_IDLE_TIMEOUT, OUTPUT_AGGREGATION_SIZE, OUTPUT_BUFFER_SIZE, REQUEST_HEADER_SIZE, RESPONSE_HEADER_SIZE
Constructor and Description |
---|
GenericWebServer()
Create a new server.
|
GenericWebServer(boolean enableConscrypt)
Create a new server.
|
Modifier and Type | Method and Description |
---|---|
void |
addHandler(org.eclipse.jetty.server.Handler handler)
Register a new handler.
|
void |
addHandler(org.eclipse.jetty.server.Handler[] handlers)
Register a list of handlers.
|
void |
addWebSocketHandler(java.lang.String target,
java.lang.Class<?> webSocket)
Register a new WebSocket.
|
void |
addWebSocketHandler(java.lang.String target,
org.eclipse.jetty.websocket.servlet.WebSocketCreator creator)
Register a new WebSocket by hand using a custom WebSocket creator.
|
private static org.eclipse.jetty.server.ServerConnector |
configSslConnector(org.eclipse.jetty.server.Server server,
java.lang.String host,
int port,
org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
Create and configure a SSL server connector.
|
private static org.eclipse.jetty.server.ServerConnector |
configSslConnector(org.eclipse.jetty.server.Server server,
java.lang.String host,
int port,
org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory,
org.eclipse.jetty.server.HttpConfiguration httpConfig)
Create and configure a SSL server connector.
|
java.lang.String |
getContextPath()
Get the server context path root.
|
java.lang.String |
getHost()
Get the server runtime host.
|
private java.lang.String |
getHostLocalAddress()
Get host site local address.
|
org.eclipse.jetty.server.HttpConfiguration |
getHttpConfiguration()
Returns the common http configuration.
|
int |
getPort()
Get server runtime port number.
|
private void |
getRuntimeParams()
Get the server runtime host and port number.
|
org.eclipse.jetty.server.Server |
getServer()
Get the
jetty server instance. |
private java.net.InetAddress |
getSiteLocalAddress()
Search on the network interfaces of this machine for
InetAddress which is a site local address. |
protected org.eclipse.jetty.util.ssl.SslContextFactory |
getSslContextFactory()
Construct a SSL Context Factory for HTTPS.
|
static java.io.File |
getWarFile(java.lang.String warName)
Resolve the WAR file with the given name - this will be a file relative to the current class
location.
|
static org.eclipse.jetty.server.ServerConnector[] |
getWebAppConnectors(java.lang.String name,
org.eclipse.jetty.server.Server server)
Get the HTTP and HTTPS connectors to run the specified web application, embedded in the specified Jetty
server.
|
static GenericWebServer |
initializeWebApp(java.lang.String name,
java.lang.String defaultWar,
java.lang.String servletName)
Initialize a WEB app, from a specified WAR file.
|
boolean |
isRunning()
Find out if server is running.
|
void |
join()
Waits for server thread pool to die.
|
void |
removeHandler(org.eclipse.jetty.server.Handler handler)
Removes the handler from the list of handlers.
|
void |
setBootstrapConfig(BootstrapConfig config)
Set the bootstrap configuration structure if any.
|
void |
setContextPath(java.lang.String contextPath)
Set the server context path root.
|
void |
setKeyStore(ServerKeyStore keyStore)
Set imported key store
|
void |
shutdown()
Shutdown server.
|
void |
startup()
Startup the embedded server.
|
void |
startup(java.lang.String host,
int port)
Startup server.
|
void |
startup(java.lang.String host,
int securePort,
int insecurePort)
Startup server.
|
protected static final java.util.logging.Logger LOG
private final org.eclipse.jetty.server.HttpConfiguration httpConfiguration
private ServerKeyStore serverKeyStore
private BootstrapConfig config
private org.eclipse.jetty.server.Server server
private org.eclipse.jetty.server.handler.HandlerCollection handlerCollection
private java.lang.String contextPath
private int port
private java.lang.String host
private org.eclipse.jetty.util.thread.QueuedThreadPool pool
private boolean enableConscrypt
private static final edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger SCHEDULER_ID
public GenericWebServer()
public GenericWebServer(boolean enableConscrypt)
enableConscrypt
- A flag to enable Conscrypt SSL provider.public static java.io.File getWarFile(java.lang.String warName)
warName
- The WAR file name (including extension).File
referencing this resource.public static org.eclipse.jetty.server.ServerConnector[] getWebAppConnectors(java.lang.String name, org.eclipse.jetty.server.Server server) throws java.lang.Exception
name
- The web application name. The directory configuration is found in the [name]WebApp
node - this includes the port, secure port, and host.server
- The Jetty server.java.lang.Exception
- In case of configuration problems.public static GenericWebServer initializeWebApp(java.lang.String name, java.lang.String defaultWar, java.lang.String servletName)
Web application's configuration will be read from the directory, using the
name + "WebApp"
node, with these settings:
port
, with the insecure port. Optional.secureport
, with the secure port. Optional. If secure port is set, then:
keyStore
, the store with the FWD process private-key and
certificate, to authenticate to FWD server.storePassword
, the password for the private-key.entryPassword
, the password for the certificate.basepath
, with the base path serving this web app.warfile
, the WAR file name, relative to FWD server's working dir.
Defaults to defaultWar
name
- The WEB app name.defaultWar
- The default WAR file name.servletName
- The servlet name serving this WEB app.GenericWebServer
instance.public void startup() throws java.lang.Exception
java.lang.Exception
- If an error condition occur during the server startup.public void startup(java.lang.String host, int port) throws java.lang.Exception
host
- Host name or IP address. If null server will listen on
all interfaces.port
- Port number to listen. If 0 the port is OS dynamically
allocated.java.lang.Exception
- If an error condition occur during the server startup.public void startup(java.lang.String host, int securePort, int insecurePort) throws java.lang.Exception
host
- Host name or IP address. If null server will listen on
all interfaces.securePort
- Port number to listen securely. If 0 the port is OS dynamically
allocated.insecurePort
- Port number to listen insecurely. This is optional, set to a positive value to
use it.java.lang.Exception
- If an error condition occur during the server startup.public void shutdown() throws java.lang.Exception
java.lang.Exception
- If the server cannot be stopped.public void join() throws java.lang.Exception
java.lang.Exception
- If any error condition occur.public org.eclipse.jetty.server.Server getServer()
jetty server
instance.public boolean isRunning()
true
if server is running false
otherwise.public void setBootstrapConfig(BootstrapConfig config)
config
- The BootstrapConfig
instance or null.private void getRuntimeParams()
public void addHandler(org.eclipse.jetty.server.Handler[] handlers)
handlers
- A list of handlers to be registered.public void addHandler(org.eclipse.jetty.server.Handler handler)
handler
- A Handler instance.public void removeHandler(org.eclipse.jetty.server.Handler handler)
handler
- The handler to remove.public void addWebSocketHandler(java.lang.String target, java.lang.Class<?> webSocket)
target
- The WebSocket target.webSocket
- A POJO decorated with @WebSocket
annotation.public void addWebSocketHandler(java.lang.String target, org.eclipse.jetty.websocket.servlet.WebSocketCreator creator)
target
- The WebSocket target.creator
- A custom WebSocketCreator
instance.public org.eclipse.jetty.server.HttpConfiguration getHttpConfiguration()
protected org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory() throws java.lang.Exception
SslContextFactory
instance.java.lang.Exception
- If any error conditions occur.private static org.eclipse.jetty.server.ServerConnector configSslConnector(org.eclipse.jetty.server.Server server, java.lang.String host, int port, org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
server
- The server instance.host
- The server host name or IP address.port
- The port number to listen.sslContextFactory
- The SslContextFactory
instance.private static org.eclipse.jetty.server.ServerConnector configSslConnector(org.eclipse.jetty.server.Server server, java.lang.String host, int port, org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, org.eclipse.jetty.server.HttpConfiguration httpConfig)
server
- The server instance.host
- The server host name or IP address.port
- The port number to listen.sslContextFactory
- The SslContextFactory
instance.httpConfig
- The common http configuration settingsprivate java.lang.String getHostLocalAddress()
private java.net.InetAddress getSiteLocalAddress() throws java.lang.Exception
InetAddress
which is a site local address.java.lang.Exception
- If an error condition occur.public void setContextPath(java.lang.String contextPath)
contextPath
- A string representing the context path root.public java.lang.String getContextPath()
public int getPort()
public java.lang.String getHost()
public void setKeyStore(ServerKeyStore keyStore)
keyStore
- Imported key store if any or null