PDA

View Full Version : Both hosts have the same root-directory!


jpalmisa
10-05-2010, 12:48 AM
I am trying to set up two hosts that use the same code base. I want to set up a different database for a single webapp running under each host. Basically I want to use the same source code/skin to serve up different sets of data.

The problem I run into is when I define this in resin.xml like so:

<host id="host1.localhost" root-directory="my/common/root">
<web-app id="/" root-directory=".">
<database jndi-name="jdbc/host1">
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://localhost:3306/host1</url>
<user>host1-username</user>
<password>host1-pass</password>
</driver>
</database>
....
</host>

<host id="host2.localhost" root-directory="my/common/root">
<web-app id="/" root-directory=".">
<database jndi-name="jdbc/host2">
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://localhost:3306/host2</url>
<user>host2-username</user>
<password>host2-pass</password>
</driver>
</database>
....
</host>


I receive a com.caucho.config.ConfigException that says "Both hosts have the same root-directory." The problem is that this is what I want it to do! I wonder if there is a simple way to accomplish this that I am unaware of?

Thanks in advance for any input on this...

emil
10-06-2010, 04:28 PM
Hi,

The organization that you're trying to use is different from Resin's internal model -- it thinks of the applications for each host as being completely separate. There are two approaches that you could use to get around this:


Copy the application to two different directories. The problems with this are that you have two copies using up space and that you have to update the application twice whenever you change it.
Use host aliasing. The configuration would change to the following:


<host id="host1.localhost" root-directory="my/common/root">
<host-alias>host2.localhost</host-alias>
<web-app id="/" root-directory=".">
<database jndi-name="jdbc/host1">
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://localhost:3306/host1</url>
<user>host1-username</user>
<password>host1-pass</password>
</driver>
</database>

<database jndi-name="jdbc/host2">
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://localhost:3306/host2</url>
<user>host2-username</user>
<password>host2-pass</password>
</driver>
</database>
....
</web-app>
</host>

With this approach, you'd only have one copy of the application on the file system. The problem with this is that now you have to change the application so that it chooses the correct database based on the hostname requested. You can use ServletRequest.getServerName() to do this.


Hope that helps,
Emil

jpalmisa
10-19-2010, 05:01 PM
Emil,

Thanks for outlining those two approaches. I think I will end up changing the application so I can keep only one copy of the code.

I wonder if you could offer some insight on "Resin's internal model," which you mention in your reply and that makes the way I was trying to set this up not possible. I am the curious type and so if you can offer any further insight regarding the Resin's internal model or point me to somewhere on the internet that I could read up on this I would very much appreciate it.

Thanks!