Apache Tomcat – Multi-Service Manager App

By | June 29, 2012

Ok, more things I don’t like about Apache Tomcat๐Ÿ˜‰ We have a web application which wants to be installed into the root context. But that means that the normal /manager webapp would either show up in it’s `directory-space’ or we would not be able to use it at all ๐Ÿ™ We have an Apache web server in front of the Tomcat so we could try to filter certain paths, but that creates extra interdependencies which I would like to avoid in `security critical’ areas.

The normal setup, which works for things like zapcat or Jolokia, is to create a new service in the same server, which listens on a different port and use that. Unfortunately, the default ManagerServlet class can not handle such a setup.

So I took the org.apache.catalina.manager.ManagerServlet as base and extended it so that it understands two additional request parameter service & host. If just one of them is used, the other uses a sensible default. I could not really sub-class the original class, because the changes were all over the place ๐Ÿ™

So with a server.xml specifying two services “Catalina, listening on 8080” and “Management, listening on 8081”, I can list the deployed applications on both from the “Management” service:

root@box:/tmp# curl 'http://root:root@box:8081/manager/list         
OK - Listed applications for virtual host localhost
/manager:running:0:manager
/j4p:running:0:j4p
/host-manager:running:0:host-manager
root@box:/tmp# curl 'http://root:root@box:8081/manager/list?service=Catalina
OK - Listed applications for virtual host localhost
/:running:0:ROOT
root@box:/tmp# curl 'http://root:root@box:8081/manager/list?service=Management
OK - Listed applications for virtual host localhost
/manager:running:0:manager
/j4p:running:0:j4p
/host-manager:running:0:host-manager

That works the same way for deploy & undeploy as well ๐Ÿ˜‰ So now my root context application is happy and all the `management apps’ can be accessed on a different port with differentย  access parameters ๐Ÿ˜‰

The source & class for Tomcat 6.0.35 is here, in this littleย  mw-manager.jar. After reading the source ๐Ÿ˜‰ , just drop it into your tomcat lib directory, adapt your manager-application’s web.xml to use the AllManagerServlet instead of the default ManagerServlet, and have fun ๐Ÿ˜‰

The manager application allows to control the tomcat installation. So please be careful!! While I think, the little new servlet works for me, make sure it does the things you expect!! Or use it as example for your own excursions into the Tomcat code ๐Ÿ˜‰

As always, have fun exploring ๐Ÿ˜‰

— Marco

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.