Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying servlets webapp in embedded undertow

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...

like image 661
Chico Sokol Avatar asked Mar 10 '14 17:03

Chico Sokol


People also ask

How do I deploy a servlet to a container?

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.

How do I bypass the deployment of a servlet?

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.

What is UnderTow?

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

How do I setup a thread in a servlet?

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.


2 Answers

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.

like image 159
Stuart Douglas Avatar answered Oct 18 '22 10:10

Stuart Douglas


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

like image 42
Guillaume D. Avatar answered Oct 18 '22 09:10

Guillaume D.