public class WebServer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
WebServer.UploadHandler |
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 |
protected org.eclipse.jetty.server.handler.HandlerCollection |
handlerCollection |
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 |
protected java.util.Map<java.lang.String,org.eclipse.jetty.server.handler.ContextHandler> |
staticContexts |
Modifier | Constructor and Description |
---|---|
protected |
WebServer(int port) |
protected |
WebServer(int port,
java.lang.String ip) |
Modifier and Type | Method and Description |
---|---|
void |
add(org.eclipse.jetty.server.handler.ContextHandler handler)
Adds a context handler to the server.
|
void |
add(java.lang.String context,
java.io.File dir)
Adds a context to serve static documents.
|
void |
add(java.lang.String context,
java.io.File dir,
java.lang.String cacheControl)
Adds a context to serve static documents.
|
void |
add(java.lang.String context,
java.io.File dir,
WebServer.WebServerOptions options)
Adds a context to serve static documents.
|
void |
add(java.lang.String context,
java.lang.String resource)
Adds a context to serve static documents.
|
void |
add(java.lang.String context,
java.lang.String resource,
java.lang.String cacheControl)
Adds a context to serve static documents.
|
void |
add(java.lang.String context,
java.lang.String resource,
WebServer.WebServerOptions options)
Adds a context to serve static documents.
|
void |
addRule(org.eclipse.jetty.rewrite.handler.Rule rule)
Adds a rule to rewrite handler.
|
void |
addUpload(java.lang.String context,
java.io.File dir)
Adds a context to upload files to.
|
void |
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 |
hasContext(java.lang.String context)
Checks if a context is already configured to serve documents.
|
static boolean |
hasInstance(int port)
Checks if an instance of a web server is running on the specified port.
|
void |
remove(org.eclipse.jetty.server.handler.ContextHandler handler)
Removes a context handler.
|
void |
remove(java.lang.String context)
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 java.util.Map<java.lang.String,org.eclipse.jetty.server.handler.ContextHandler> staticContexts
protected org.eclipse.jetty.server.handler.HandlerCollection handlerCollection
protected boolean started
protected int port
protected WebServer(int port)
protected WebServer(int port, java.lang.String ip)
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 void add(org.eclipse.jetty.server.handler.ContextHandler handler)
handler
- context handler.public void remove(org.eclipse.jetty.server.handler.ContextHandler handler)
handler
- context handler to remove.public void add(java.lang.String context, java.lang.String resource, WebServer.WebServerOptions options)
context
- context path.resource
- resource path.options
- WebServerOptions object.public void add(java.lang.String context, java.lang.String resource, java.lang.String cacheControl)
context
- context path.resource
- resource path.cacheControl
- cache control header.public void add(java.lang.String context, java.lang.String resource)
context
- context path.resource
- resource path.public void add(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 void add(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 void add(java.lang.String context, java.io.File dir)
context
- context path.dir
- filesystem path of directory to serve files from.public void addUpload(java.lang.String context, java.io.File dir)
context
- context path.dir
- filesystem path of directory to upload files to.public void 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 void remove(java.lang.String context)
context
- context path.public boolean hasContext(java.lang.String context)
context
- context path.public void addRule(org.eclipse.jetty.rewrite.handler.Rule rule)
rule
- rewrite rule.