Search code examples
javatomcatpathwarcontextpath

Tomcat - nested webapp pathing without using Apache HTTPD


I'm again trying things I probably shouldn't... but... usually I get the feeling it's possible. This time, I'm really crossing my fingers.

I have a Tomcat 8 instance. On this instance, I have:

  • AppA (WAR) - Primary web application
  • AppB (WAR) - Secondary sub-application (more of a feature really) but people will access using an special path (like "service").

I don't want to run Apache HTTPD (or any other additional service layers). I also want to make this seemless at the tomcat level instead of trying to fake it via ingress networking/waf/etc or through the application itself (allow developer to work on other needed coding).

What I really want is to configure Tomcat in a way that will handle this by itself:

  • A user can visit https://host.com/AppA
  • A user can use the feature if they go to https://host.com/AppA/service (which points to AppB, but the user should never see the WAR name of "AppB" - changing the WAR name to "service" is perfectly acceptable if that saves some sanity)

Now I tried following the Virtual Host configuration (https://tomcat.apache.org/tomcat-8.0-doc/virtual-hosting-howto.html) with little changes here to see if I can make this fit what I need... and... it's failing, but I think that if tomcat can do this, I can get it there.

What I've tried so far:

  • Updated [tomcat]/conf/server.xml with an added entry.
  • Added a new "webapps"-like folder called [tomcat]/AppBapp (AppB.war sits here)
  • Added a [tomcat]/conf/Catalina/localhost/AppB.xml context file.

I've seen a few posts where they kind of do this, but in the opposite direction (root web directory points to some custom server path). I think I can get this config figured out, but I have to ask... will this strategy even work for what I'm trying to do with tomcat? Or am I in the wrong ballpark completely?

Thanks a bunch for your time. Always Appreciated!


Solution

  • In fact, you want nested contexts by Tomcat configuration only.

    This was talked about on the Tomcat User's List and you can have a look at this archived thread about nested contexts.

    From my understanding, the solution given relies on two contexts configuration :

    $TOMCAT_BASE/conf/Catalina/localhost/A.xml
    $TOMCAT_BASE/conf/Catalina/localhost/A#service.xml
    

    with directories webapps/A and webapps/A#service (this one containing the deployed appB content).