Class WebServer
- All Implemented Interfaces:
EventListener,org.eclipse.jetty.util.component.LifeCycle,org.eclipse.jetty.util.component.LifeCycle.Listener
This server loads HttpServlets registered as
HttpServlet service providers and annotated with
the WebServlet annotation. It also loads the
registered WebServerConfiguration objects to get
configuration for file handling, redirection, and denial of access to
resources.
When there is a conflict over how a path should be handled, denials take precedence, followed by servlets, redirections, and lastly direct access to files.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Constructor Summary
ConstructorsConstructorDescriptionCreate a WebServer instance with the default preferences.WebServer(WebServerPreferences preferences) Create a WebServer instance with the specified preferences. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLifeCycleListener(org.eclipse.jetty.util.component.LifeCycle.Listener ll) static WebServerGet the default web server instance.intgetPort()booleanisFailed()booleanbooleanbooleanbooleanbooleanvoidlifeCycleFailure(org.eclipse.jetty.util.component.LifeCycle lc, Throwable thrwbl) voidlifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle lc) voidlifeCycleStarting(org.eclipse.jetty.util.component.LifeCycle lc) voidlifeCycleStopped(org.eclipse.jetty.util.component.LifeCycle lc) voidlifeCycleStopping(org.eclipse.jetty.util.component.LifeCycle lc) static StringportablePathToURI(String path) Get the public URI for a portable path.voidregisterDenial(String urlPattern) Register a URL pattern to be denied access.voidregisterRedirection(String urlPattern, String redirection) Register a URL pattern to be redirected to another resource.voidregisterResource(String urlPattern, String filePath) Register a URL pattern to return resources from the file system.voidregisterServlet(Class<? extends javax.servlet.http.HttpServlet> type) Register aHttpServletthat is annotated with theWebServletannotation.voidregisterServlet(Class<? extends javax.servlet.http.HttpServlet> type, javax.servlet.http.HttpServlet instance) Register aHttpServletthat is annotated with theWebServletannotation.voidremoveLifeCycleListener(org.eclipse.jetty.util.component.LifeCycle.Listener ll) voidstart()Start the web server.voidstop()Stop the server.
-
Constructor Details
-
WebServer
public WebServer()Create a WebServer instance with the default preferences. -
WebServer
Create a WebServer instance with the specified preferences.- Parameters:
preferences- the preferences
-
-
Method Details
-
getDefault
Get the default web server instance.- Returns:
- a WebServer instance, either the existing instance or a new instance created with the default constructor.
-
start
Start the web server.- Specified by:
startin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
stop
Stop the server.- Specified by:
stopin interfaceorg.eclipse.jetty.util.component.LifeCycle- Throws:
Exception- if there is an error stopping the server; defined by Jetty superclass
-
portablePathToURI
Get the public URI for a portable path. This method returns public URIs for only some portable paths, and does not check that the portable path is actually sane. Note that this refuses to return portable paths that are outside ofFileUtil.PREFERENCES,FileUtil.PROFILE,FileUtil.SETTINGS, orFileUtil.PROGRAM.- Parameters:
path- the JMRI portable path- Returns:
- The servable URI or null
- See Also:
-
getPort
-
getPreferences
-
registerDenial
Register a URL pattern to be denied access.- Parameters:
urlPattern- the pattern to deny access to
-
registerResource
Register a URL pattern to return resources from the file system. The filePath may start with any of the following: Note that the filePath can be overridden by an otherwise identical filePath starting with any of the portable paths above it in the preceding list.- Parameters:
urlPattern- the pattern to get resources forfilePath- the portable path for the resources- Throws:
IllegalArgumentException- if urlPattern is already registered to deny access or for a servlet or if filePath is not allowed
-
registerRedirection
Register a URL pattern to be redirected to another resource.- Parameters:
urlPattern- the pattern to be redirectedredirection- the path to which the pattern is redirected- Throws:
IllegalArgumentException- if urlPattern is already registered for any other purpose
-
registerServlet
Register aHttpServletthat is annotated with theWebServletannotation.This method calls
registerServlet(java.lang.Class, javax.servlet.http.HttpServlet)with a null HttpServlet.- Parameters:
type- The actual class of the servlet.
-
registerServlet
public void registerServlet(Class<? extends javax.servlet.http.HttpServlet> type, javax.servlet.http.HttpServlet instance) Register aHttpServletthat is annotated with theWebServletannotation.Registration reads the WebServlet annotation to get the list of paths the servlet should handle and creates instances of the Servlet to handle each path.
Note that all HttpServlets registered using this mechanism must have a default constructor.
- Parameters:
type- The actual class of the servlet.instance- An un-initialized, un-registered instance of the servlet.
-
lifeCycleStarting
- Specified by:
lifeCycleStartingin interfaceorg.eclipse.jetty.util.component.LifeCycle.Listener
-
lifeCycleStarted
- Specified by:
lifeCycleStartedin interfaceorg.eclipse.jetty.util.component.LifeCycle.Listener
-
lifeCycleFailure
- Specified by:
lifeCycleFailurein interfaceorg.eclipse.jetty.util.component.LifeCycle.Listener
-
lifeCycleStopping
- Specified by:
lifeCycleStoppingin interfaceorg.eclipse.jetty.util.component.LifeCycle.Listener
-
lifeCycleStopped
- Specified by:
lifeCycleStoppedin interfaceorg.eclipse.jetty.util.component.LifeCycle.Listener
-
isRunning
- Specified by:
isRunningin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStarted
- Specified by:
isStartedin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStarting
- Specified by:
isStartingin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStopping
- Specified by:
isStoppingin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStopped
- Specified by:
isStoppedin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isFailed
- Specified by:
isFailedin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
addLifeCycleListener
- Specified by:
addLifeCycleListenerin interfaceorg.eclipse.jetty.util.component.LifeCycle
-
removeLifeCycleListener
- Specified by:
removeLifeCycleListenerin interfaceorg.eclipse.jetty.util.component.LifeCycle
-