2

We run about 30 webapps on various Tomcat instances behind load balancers and Apache reverse proxies using mod_jk. The public URL of each application is configured into the Apache mod_jk config which proxies to the backend Tomcats. The backend Tomcat runs the application on a context path which matches the public URL.

e.g.

domain.com/foo/bar/webapp -- mod_jk --> tomcat/foo/bar/webapp

This is because the applications build links in the JSPs using ${pageContext.request.contextPath}, e.g.

<script src="${pageContext.request.contextPath}/resources/js/image-manipulation.js" >     </script>

I'd like to make this more loosly coupled, and "containerise" the webapps, so they each run in their own Tomcat container, on the default context, i.e. / without needing to know what their public URL is. This would simplify managing the Tomcat configuration and mod_jk mappings.

The problem is how can the application build absolute links to within itself, without knowing what it's final public URL is? Is there a way to pass the URL in the mod_jk request, and have Tomcat override calls to ${pageContext.request.contextPath} with this URL?

Or is it better to use something like mod_substitute in Apache to replace a fixed string in the page with the URL when it's heading out of Apache? This seems inefficient as Apache has to then scan all the pages doing this find & replace..

Or is it best just to leave it all as it is, and use the context path as currently?

Mark
  • 1,754
  • 3
  • 26
  • 43

1 Answers1

0

The only solution I can think of would be something like:

  • configuring mod_jk to send the wanted contextPath as a variable through JkEnvVar (will be available in tomcat as a request param)
  • have a filter in your webapp wrapping the request and using that variable to override getContextPath()
  • wrap your response too to handle sendRedirect() and other similar methods correctly (might not be that easy).

Of course, if tomcat could do all of that for you...

Xavier Dury
  • 1,530
  • 1
  • 16
  • 23