Is there any easy way to deploy a servlets web application with undertow embbeded?
For example, with jetty, I can deploy like this:
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setDescriptor("src/main/webapp/web.xml");
context.setResourceBase("src/main/webapp/");
server.setHandler(context);
server.start();
Is there a similar way of doing this with undertow? I saw a example here: https://github.com/undertow-io/undertow/blob/master/examples/src/main/java/io/undertow/examples/servlet/ServletServer.java, but it's not exaclty what I want, it registers the servlets one by one...
The basic process is to create a DeploymentInfo structure (this can be done use the io.undertow.servlets.Servlets utility method), add any Servlets and other information to this structure, and then deploy it to a Servlet container.
This allows you to add a handler that is run before all other Servlet handlers. If this handler does not delegate to the next handler in the chain it can effectively bypass the Servlet deployment. This handler is run after the servlet request context has been setup, but before any other handlers.
Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO. To have more information about the Undertow servlet container library you can visit the Undertow homepage at undertow.io
Thread setup actions can be added using the addThreadSetupAction () method, these actions will be run before a request is dispatched to a thread, so any thread local data can be setup. The ResourceManager is used by the default servlet to serve all static resources.
Not at the moment.
Undertow just provides a builder API, that another application can use to build up a Servlet. This was a deliberate design choice as it gives the embedding application full control of the deployment.
We may eventually add support for this in a different module (most likely by ripping the relevant code out of Wildfly), but it is not high on the priority list at the moment.
I think the new wildfly swarm project provides a good workaround for that as you can deploy any webapp just with the undertow module picked from wildfly and packaged in a single fat jar. A good example is here: https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/servlet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With