public class GenericWebServer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private BootstrapConfig |
config
The bootstrap configuration
|
private java.lang.String |
contextPath
Context path
|
private org.eclipse.jetty.server.handler.HandlerCollection |
handlerCollection
Context Handlers
|
private java.lang.String |
host
Server host name
|
protected static java.util.logging.Logger |
LOG
Logger.
|
private int |
port
Server port
|
private org.eclipse.jetty.server.Server |
server
Embedded jetty server
|
private ServerKeyStore |
serverKeyStore
Exported server key store
|
Constructor and Description |
---|
GenericWebServer() |
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 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.
|
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.
|
int |
getPort()
Get server runtime port number.
|
private void |
getRuntimeParams()
Get the server runtime host and port number.
|
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.
|
boolean |
isRunning()
Find out if server is running.
|
void |
join()
Waits for server thread pool to die.
|
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.
|
protected static final java.util.logging.Logger LOG
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
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 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 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 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.protected org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory() throws java.lang.Exception
SslContextFactory
instance.java.lang.Exception
- If any error conditions occur.private 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 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