Deploying a servlet from a module

Hello again,

was reading another post and an idea came up. The driver I’m developing listens for HTTP connections. At the moment I’m embedding the Jetty server.

However it would also make sense to just add a servlet to the Tomcat server that Ignition runs on.

Is it possible to deploy a servlet programatically?

Could this have any negative impact on the performance of the Ignition server?

The current approach of using a separate server means that the module runs quite separate with little risk of affecting the Tomcat thread pool, and other pooled resources. However, it means more jars and more thread pools need to be allocated… Also, I’d expect Tomcat would manage separate servlets well, each with a separate sandbox…

Any thoughts on the matter are appreciated.

Ivan

Hey,

This isn’t exactly my area of expertise, but it seems pretty easy. GatewayContext has a [tt]addServlet[/tt] function that lets you register your own.

Here’s a thread with a tiny bit more info.

I’d say that’s probably a better way to go than embedding a second web server.

Regards,

So I’ve created a servlet, the current implementation just returns a “202 Accepted” to any post request. In addition, it creates a logger and logs a message when init() is called.

I am calling context.addServlet(“servletName”, myServlet.class) on startup

However, it seems that the servlet never gets instantiated and started.

Is there a step missing somewhere?

PS: any way to know in advance what the deploy path will be?

Hi,

With what you did, you should be able to access it at:
http://localhost:8088/main/system/servletName
and see init get called on first access.

The programmatically added servlets get mapped through the “Map” servlet, which is mapped to “system/" in the web.xml file. It takes the "” and looks up a registered servlet by that name, and calls it.

Hope this helps,

You were right, it was deployed, but didn’t get instantiated until the first call. Log entry shows after the first access.

Thanks again!
Ivan