Package net.optionfactory.undertow
Class WebServer
java.lang.Object
net.optionfactory.undertow.WebServer
- All Implemented Interfaces:
Closeable,AutoCloseable
Undertow embedded web server running a single web application.
If web resources have to be fetched from the filesystem (e.g. while developing the web UI), the web server should be initialized with:
Given one or more classes that implement the Spring Web
WebApplicationInitializer interface, the embedded web server can be
instantiated with:
new WebServer("0.0.0.0", 8080, Deployment.springSelfContained(OurWebApplication.class))
If web resources have to be fetched from the filesystem (e.g. while developing the web UI), the web server should be initialized with:
new WebServer("0.0.0.0", 8080, Deployment.springWithExternalWebResources("src/main/webapp/", OurWebApplication.class))
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWebServer(String listeningAddress, int listeningPort, Deployment deployment) Creates the embedded web server. -
Method Summary
-
Field Details
-
ROOT_PATH
- See Also:
-
-
Constructor Details
-
WebServer
Creates the embedded web server. Deployment configuration can be built using helper methods inDeployment.- Parameters:
listeningAddress- the address this server is bound tolisteningPort- the port number where the server accepts connectionsdeployment- deployment configuration
-
-
Method Details
-
start
public void start() throws javax.servlet.ServletExceptionLoads the servlet deployment and starts the embedded web server.- Throws:
javax.servlet.ServletException- if the web server cannot be started
-
close
public void close()Gracefully undeploys the web application and stops the embedded web server.If the web server instance is a Spring-managed bean, this method will be automatically called on context teardown. Otherwise a shutdown hook can be configured with:
WebServer webServer = ... Runtime.getRuntime().addShutdownHook(new Thread(webServer::close));- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-