# Deploying a servlet from a module

**URL:** <https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368>\
**Category:** Module Development\
**Created:** [April 27, 2012, 4:37pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368 "2012-04-27T16:37:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![idelamer](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@idelamer](https://forum.inductiveautomation.com/u/idelamer)\
**Post date:** [April 27, 2012, 4:37pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368/1 "2012-04-27T16:37:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [April 27, 2012, 11:59pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368/2 "2012-04-27T23:59:16Z")

</div>

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](http://www.inductiveautomation.com/forum/viewtopic.php?f=74&t=6573&p=19215&hilit=servlet#p19215) with a tiny bit more info.

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

Regards,

---

<div class="post-metadata">

**Author:** ![idelamer](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@idelamer](https://forum.inductiveautomation.com/u/idelamer)\
**Post date:** [April 30, 2012, 7:19pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368/3 "2012-04-30T19:19:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [April 30, 2012, 8:22pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368/4 "2012-04-30T20:22:37Z")

</div>

Hi,

With what you did, you should be able to access it at:  
[http://localhost:8088/main/system/servletName](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,

---

<div class="post-metadata">

**Author:** ![idelamer](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@idelamer](https://forum.inductiveautomation.com/u/idelamer)\
**Post date:** [April 30, 2012, 8:46pm UTC](https://forum.inductiveautomation.com/t/deploying-a-servlet-from-a-module/4368/5 "2012-04-30T20:46:19Z")

</div>

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
