This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Dynamic URIs Using one Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Dynamic URIs Using one Context" Watch "Dynamic URIs Using one Context" New topic

Dynamic URIs Using one Context

Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
This question was also posted on the Tomcat Mailing List. Sorry if you're reading this twice...

We've been given a difficult problem to solve and I'm hoping that some help/insight is available on this mailing list.

We are an Application Service Provider (ASP) that has numerous clients with the number of clients increasing rapidly. All our clients use the same application but each client needs/wants a distinguishing element in the url to identify them to their users.

Here is our current setup:

Apache 2.2 with mod_jk sending requests to Tomcat 5.5. Struts 1.3.8 is our current web framework.

In our httpd.conf we have a different domain name for each client:

<VirtualHost *:80>
ServerName <client name 1>.<server name>.com
DocumentRoot <some directory>/<client name 1>.<server name>.com

<VirtualHost *:80>
ServerName <client name 2>.<server name>.com
DocumentRoot <some directory>/<client name 2>.<server name>.com

Then in our server.xml config file for Tomcat we only declare one Host element with a Context that has many Alias':

<Host name="<client name 1>.<server name>.com" appBase="webapps">
<Context path="/app" >
<Alias><client name 2>.<server name>.com</Alias>
<Alias><client name 3>.<server name>.com</Alias>
...etc for each of our clients...

So, what is the problem? Well, when we add a new customer we have to edit the httpd.conf, the server.xml, restart both applications, and add the new <customer>.<server name>.com to DNS (Usually, we have to wait until late into the evening to do these tasks). Our Client Services team want the ability to add customers without having to wait until we can restart our servers.

Is it possible to do the following with an Apache 2.2 and Tomcat 5.5 combination while having only ONE instance of the application only once loaded in Tomcat? (Meaning we do NOT want the application loaded by Tomcat x times, with x being the number of clients we have.)

<base name>.<server name>.com/<client name 1>/app
<base name>.<server name>.com/<client name 2>/app
<base name>.<server name>.com/<client name 3>/app

I'm not really the best with how the Context attribute works outside of having it placed in the server.xml. I've tried reading the documentation on Contexts at:
But, I find what is explained a tad bit confusing.

Here is one thread from the archives that explained our problem pretty well, but there never really was an answer on how to accomplish the task except "you're getting the right behavior with a 400 response":

Finally, through some other research, it seems as though someone was trying to use mod_vhost_alias to accomplish the same thing.

Any thoughts or suggestions are welcome.

Thank you for your time.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41155
Instead of
<base name>.<server name>.com/<client name 1>/app
<base name>.<server name>.com/<client name 2>/app

I would do
<base name>.<server name>.com/app/<client name 1>
<base name>.<server name>.com/app/<client name 2>

That way nothing needs to be configured in httpd, nothing needs to be configured in Tomcat, and you have just a single web app. Everything related to keeping customer apart can be done inside of the web app. Case closed

Ping & DNS - my free Android networking tools app
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
Ok. So far, I'm really liking the way you think.

How would we get our application then to do our different mappings with Struts (1.3.8) then?

Please consider the following example...

<base name>.<server name>.com/app/<client name 1>/
<base name>.<server name>.com/app/<client name 2>/

What would a mapping like this in Struts look like?

Would we need to use filters to manipulate the request?

Thank you for the response. Your idea is a nice was of looking at the problem.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41155
I'm not too familiar with Struts, but usually it's configured to act on *.do URLs, no? So does it matter what comes before that? (I really don't know.)

Another way to handle the problem would be to have URLs like

<base name>.<server name>.com/app/?client=<client name>

You'd only need to do this for the start/login page, because after that you can remember the clientID in the server session (and you really need logins/passwords, or clients WILL hack their way into other clients app). Then all the *.do URLs that come after that don't need the client parameter - they look the same for all clients.
I agree. Here's the link:
subject: Dynamic URIs Using one Context
Similar Threads
Apache 1.3 / Tomcat 4.0 Configuration Problem
problem with virtual host
After I've configured Apache+Tomcat, WEB-INF cannot be accessed from JSP
warp conn prevents apache redirect
Virtual Hosts with Tomcat/Apache