You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Raymond Kleijngeld <ra...@iinet.net.au> on 2009/04/27 04:00:43 UTC
Dynamic Aliases and db connections?
Hello,
I'm writing an application to support multiple clients using the same
tomcat application. For security purposes I want each client to have
there own database schema and subsequently their own subdomain i.e.
sub1.domain.com, sub2.domain.com etc.
I know I can update the server.xml file and add extra resource tags and
extra alias tags for each new client but I don't want the tomcat server
to be restarted because this would interupt the service/application to
other clients.
So basically the question is how can I do this without having to stop
and start the tomcat service?
Is there a <Alias> wildcard option like: <Alias>*.domain.com</Alias>
that will automatically allow all subdomains to go through to this
tomcat application? Maybe there should be something similar as the
<Valve> option for RemoteHostValve and RemoteAddrValve?
I have been playing with the context.xml file in the
conf/[engine]/[host]/ROOT.xml file and I have been able to add more db
resources in there but the problem with this is that a client can also
unsubscribe from my application which would mean I would remove the
resource entry from the ROOT.xml file and then this is being undeployed
deleting all content from the docBase folder which is of course not what
I want.
Any help would be much appreciated.
Thanks
Ray
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Dynamic Aliases and db connections?
Posted by André Warnier <aw...@ice-sa.com>.
Hi.
There are two parts to your question, only one of which I can maybe
contribute to.
Regarding hostnames and aliases :
First, to have requests to "sub1.domain.com" even reach your Tomcat
server, it would have to be so of course that the DNS system recognises
"sub1.domain.com" and translates it to the IP address of your server.
That part does not happen automatically, you have to make it happen, first.
Then regarding hosts and aliases recognised by Tomcat :
As long as a request for, say, "sub3.domain.com" reaches Tomcat (see DNS
above), Tomcat will process the request.
Either it will find in its configuration a <Host> element with
a "name" attribute matching "sub3.domain.com", or a Host element
containing a matching <Alias> tag, or else it will handle the request
using its "default host" (the one named in the <Engine> tag).
Then, when it has selected the appropriate Host, it will process the
request using the configuration of that <Host>, meaning essentially what
it finds either between that Host's <Host> and </Host> tags, and
anything defined at a higher level.
So now your problem is just moved down a notch, to the additional
resources you seem to want to allocate per client.
Don't know if that really helps though.
Raymond Kleijngeld wrote:
> Hello,
>
> I'm writing an application to support multiple clients using the same
> tomcat application. For security purposes I want each client to have
> there own database schema and subsequently their own subdomain i.e.
> sub1.domain.com, sub2.domain.com etc.
>
> I know I can update the server.xml file and add extra resource tags and
> extra alias tags for each new client but I don't want the tomcat server
> to be restarted because this would interupt the service/application to
> other clients.
>
> So basically the question is how can I do this without having to stop
> and start the tomcat service?
>
> Is there a <Alias> wildcard option like: <Alias>*.domain.com</Alias>
> that will automatically allow all subdomains to go through to this
> tomcat application? Maybe there should be something similar as the
> <Valve> option for RemoteHostValve and RemoteAddrValve?
>
> I have been playing with the context.xml file in the
> conf/[engine]/[host]/ROOT.xml file and I have been able to add more db
> resources in there but the problem with this is that a client can also
> unsubscribe from my application which would mean I would remove the
> resource entry from the ROOT.xml file and then this is being undeployed
> deleting all content from the docBase folder which is of course not what
> I want.
>
> Any help would be much appreciated.
>
> Thanks
>
> Ray
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Dynamic Aliases and db connections?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ray,
On 4/26/2009 10:00 PM, Raymond Kleijngeld wrote:
> I'm writing an application to support multiple clients using the same
> tomcat application. For security purposes I want each client to have
> there own database schema and subsequently their own subdomain i.e.
> sub1.domain.com, sub2.domain.com etc.
>
> I know I can update the server.xml file and add extra resource tags and
> extra alias tags for each new client but I don't want the tomcat server
> to be restarted because this would interupt the service/application to
> other clients.
The hostnames must be configured in server.xml. See André's post for
more information on that.
You can configure your database resources in your webapp's
META-INF/context.xml file. Something like this:
<Context>
<Resource name="jdbc/MyDataSource"
description="My JDBC connection"
auth="Container"
type="javax.sql.DataSource"
maxActive="1"
maxIdle="1"
maxWait="10000"
url="jdbc:mysql://localhost:3306/mydatabase"
username="scott"
password="tiger"
driverClassName="com.mysql.jdbc.Driver"
removeAbandoned="true"
removeAbandonedTimeout="30"
logAbandoned="true"
testOnBorrow="true"
validationQuery="SELECT 1"
/>
</Context>
When these resources are configured within the webapp, re-deploying the
webapp is enough to update the configuration. There appears to be a bug
in Tomcat where application-defined DataSources are not shut down when
the application is undeployed. I suspect a re-deploy will replace the
configuration, but if you find that you are running out of db
connections on the server-side, you may want to look into this as a
possibility.
Good luck,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkn1yY0ACgkQ9CaO5/Lv0PDu9QCfVepWutXbMttUvzBvoiYNACDy
wCoAn0i5iMQchRykPzUcsqiZfSwg81fg
=TMgr
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org