tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garret Wilson <>
Subject efficient redirect map with embedded Tomcat
Date Fri, 11 Oct 2019 14:06:52 GMT
This is a question for Tomcat experts before I get started implementing 
a new feature.

Let's say I'm embedding Tomcat to serve static files. At the time of 
creation I know that certain paths, such as `foo/bar.txt`, should 
redirect to other paths, such as `some/other.txt`. What's the best way 
to configure Tomcat to do those redirects? I'm comfortable with 
extending the source code.

Here are a couple of ideas that come to mind:

  * I could create a redirect servlet and map different instances of it
    to different targets in the context when I configure everything. But
    in Tomcat's routing engine, is the most efficient way to do things?
    (I assume that the servlet mappings can be placed "over" the default
    servlet's path space, that is, cherry-pick paths for redirection,
    falling back to the default file-serving servlet for non-redirect
  * I thought of patching into the default file servlet, overriding
    `org.apache.catalina.WebResource`, and creating virtual
    `RedirectResource` resources that don't correspond to any physical
    file. However it's not obvious to me where I would create a
    redirect. Maybe throw some redirect exception inside
    `WebResource.getInputStream()`? (This is probably not correct. I'm
    just brainstorming. The idea is sound if I knew where to put it.)
  * Should I install a configured rewrite valve when I'm setting up
    embedded Tomcat?
  * Is there some other routing logic in Tomcat I could tap into most
    efficiently, providing a known set of redirects?

Thanks for any guidance. I'm want to figure out the best way to attack 
this before getting very deep in an implementation.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message