public class WebServer
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
WebServer.WebServerOptions
Builder style class for configuring web server options.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CACHE |
protected org.eclipse.jetty.server.handler.ContextHandlerCollection |
contexts |
static java.lang.String |
NOCACHE |
protected int |
port |
protected org.eclipse.jetty.rewrite.handler.RewriteHandler |
rewrite |
protected org.eclipse.jetty.server.Server |
server |
protected boolean |
started |
| Modifier | Constructor and Description |
|---|---|
protected |
WebServer(int port) |
protected |
WebServer(int port,
java.lang.String ip)
Creates a new web server instance.
|
| Modifier and Type | Method and Description |
|---|---|
org.eclipse.jetty.server.handler.ContextHandler |
addHandler(java.lang.String context,
org.eclipse.jetty.server.handler.AbstractHandler handler)
Add a handler to the server at the specified context.
|
boolean |
addRule(org.eclipse.jetty.rewrite.handler.Rule rule)
Adds a rule to rewrite handler.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.io.File dir)
Adds a context to serve static documents.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.io.File dir,
java.lang.String cacheControl)
Adds a context to serve static documents.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.io.File dir,
WebServer.WebServerOptions options)
Adds a context to serve static documents.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.lang.String resource)
Adds a context to serve static documents.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.lang.String resource,
java.lang.String cacheControl)
Adds a context to serve static documents.
|
java.util.List<org.eclipse.jetty.server.handler.ContextHandler> |
addStatic(java.lang.String context,
java.lang.String resource,
WebServer.WebServerOptions options)
Adds a context to serve static documents.
|
boolean |
addUpload(java.lang.String context,
java.io.File dir)
Adds a context to upload files to.
|
boolean |
addUpload(java.lang.String context,
java.io.File dir,
long maxFileSize,
long maxRequestSize,
int fileSizeThreshold)
Adds a context to upload files to.
|
static WebServer |
getInstance(int port)
Gets an instance of a web server running on the specified port.
|
static WebServer |
getInstance(int port,
java.lang.String ip)
Gets an instance of a web server running on the specified port.
|
static WebServer[] |
getInstances()
Gets all web server instances running.
|
int |
getPort()
Gets the port number that the web server is running on.
|
boolean |
hasHandler(java.lang.String context)
Checks if a handler is already registered for the specified context.
|
static boolean |
hasInstance(int port)
Checks if an instance of a web server is running on the specified port.
|
boolean |
hasStatic(java.lang.String context)
Checks is there's already a context serving static documents.
|
boolean |
removeHandler(org.eclipse.jetty.server.handler.ContextHandler handler)
Removes a ContextHandler from the server.
|
boolean |
removeStatic(org.eclipse.jetty.server.handler.ContextHandler handler)
Removes a context serving static documents.
|
static void |
shutdown()
Shutdown all web servers.
|
void |
start()
Starts the web server.
|
void |
stop()
Stops the web server.
|
public static final java.lang.String NOCACHE
public static final java.lang.String CACHE
protected org.eclipse.jetty.server.Server server
protected org.eclipse.jetty.server.handler.ContextHandlerCollection contexts
protected org.eclipse.jetty.rewrite.handler.RewriteHandler rewrite
protected boolean started
protected int port
protected WebServer(int port)
protected WebServer(int port,
java.lang.String ip)
GzipHandler -> RewriteHandler -> ContextHandlerCollection[ contexts[] , DefaultHandler]
port - HTTP port number.ip - IP address to bind HTTP server to.public static WebServer getInstance(int port)
port - HTTP port number.public static WebServer getInstance(int port, java.lang.String ip)
port - HTTP port number.ip - IP address to bind HTTP server to.public static boolean hasInstance(int port)
port - HTTP port number.public static WebServer[] getInstances()
public static void shutdown()
public int getPort()
public void start()
public void stop()
public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.lang.String resource,
WebServer.WebServerOptions options)
context - context path.resource - resource path.options - WebServerOptions object.public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.lang.String resource,
java.lang.String cacheControl)
context - context path.resource - resource path.cacheControl - cache control header.public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.lang.String resource)
context - context path.resource - resource path.public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.io.File dir,
WebServer.WebServerOptions options)
context - context path.dir - filesystem path of directory to serve files from.options - WebServerOptions object.public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.io.File dir,
java.lang.String cacheControl)
context - context path.dir - filesystem path of directory to serve files from.cacheControl - cache control header.public java.util.List<org.eclipse.jetty.server.handler.ContextHandler> addStatic(java.lang.String context,
java.io.File dir)
context - context path.dir - filesystem path of directory to serve files from.public boolean removeStatic(org.eclipse.jetty.server.handler.ContextHandler handler)
handler - context handler to remove.public boolean hasStatic(java.lang.String context)
context - context path.public boolean addUpload(java.lang.String context,
java.io.File dir)
context - context path.dir - filesystem path of directory to upload files to.public boolean addUpload(java.lang.String context,
java.io.File dir,
long maxFileSize,
long maxRequestSize,
int fileSizeThreshold)
context - context path.dir - filesystem path of directory to upload files to.maxFileSize - maximum size of a file. @see javax.servlet.MultipartConfigElementmaxRequestSize - maximum size of a request. @see javax.servlet.MultipartConfigElementfileSizeThreshold - size threshold after which files will be written to disk. @see javax.servlet.MultipartConfigElementpublic org.eclipse.jetty.server.handler.ContextHandler addHandler(java.lang.String context,
org.eclipse.jetty.server.handler.AbstractHandler handler)
context - context path.handler - handler to add.public boolean hasHandler(java.lang.String context)
context - context path.public boolean removeHandler(org.eclipse.jetty.server.handler.ContextHandler handler)
handler - handler to remove.public boolean addRule(org.eclipse.jetty.rewrite.handler.Rule rule)
NOTE: Rules cannot be added after the server is started.
rule - rewrite rule.