You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Kerber <dc...@verizon.net> on 2005/10/03 02:04:21 UTC
Getting tomcat instance information into webapp
This question is part tomcat and part java; I'm running on a Windows
2000 server.
I have a situation where I am going to need to run multiple instances of
tomcat on a single machine, listening on different ports, but running
the same application and hitting a different instance of an identical
database (same schema, but on a different server). So what I will need
to do is be able to tell each instance of the application on its
respective instance of tomcat which database to hit.
Can I pass a parameter into tomcat from a conf file based on what port
that instance of tomcat is listening on, and then get that parameter
into my application? If so, how?
Another option is for my application to grab the machine name and port
that it is handling, and hit a "common" database to get the information
on what copy of the production to use. But again, I need my app to be
able to find port information from tomcat, and I don't know how to do that.
It seems like a 3rd option might be to run each instance of tomcat as a
service, logged on with different accounts, and use a user DSN instead
of a system DSN, with the same DSN name, but different connection info.
Is that possible?
If necessary, I could install multiple instances of my app at different
context paths, but I still don't know how to tell them to pick up the
correct database connection info. I guess I could make a code change in
the first page they hit, the logon.jsp, for each instance, but I'd
rather not have to do that unless there really is no other way, because
that would be easy to screw up when making changes later on...
Any suggestions as to which of the above approaches would be the best,
or another one I haven't thought of?
Thanks!
DAve
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Getting tomcat instance information into webapp
Posted by David Kerber <dc...@verizon.net>.
Thanks for the suggestions, Kyle! I think either one of those
suggestions would be workable; I'll have to do some reading and testing
to see which I like better. The only reason I wanted them to run on
different ports is so that I don't have to change the url's they connect
to during this server migration. The only mandatory difference between
the apps is the different back-end databases.
I think I've got enough to work with now; thanks again.
Kyle wrote:
>
>
> David Kerber wrote:
>
>>
>> Then how do I isolate the instances of tomcat (and their respective
>> server.xml's? Do I need multiple installations of tomcat on my disk?
>>
> Start each 'instance' of tomcat with separate CATALINA_BASE env. vars.
> This enables a different server.xml for each instance thereby allowing a
> different connector port for each instance. As for the webapp, you can
> still re-use the same code via the docBase and appBase variables by
> specifiying absolute paths. (read RUNNING.TXT with your install)
>
> Does that work?
>
> Alternatively, IF you can use the scenario where the users are
> connecting to the same app, but under different sub-directories of your
> domain, e.g.;
>
> www.example.com/appA
> www.example.com/appB
> www.example.com/appC
>
> Then, you can still have different contexts and/or realms (if
> necessary). But in this scenario, you wouldn't need multiple instances
> running on different ports would you? Just the one instance listening on
> the one port, with TC (as far as TC is concerned) serving up different
> webapps which all happen to point to the same absolute docBase/appBase,
> just with different jdbc connection params in their respective contexts
> connecting them to their relevant database. Surely, that's an acceptable
> solution if the only difference in your scenario is to have them
> connecting on different ports. This way there are also less ports open
> if in a secure environment.
>
>
> USUAL DISCLAIMER: etc. etc. etc. i.e. I may not have the faintest idea
> of what I'm talking about and everything written above should be taken
> with a pinch of salt until proven to work AND perform in your environment.
You don't claim to be an expert, but you definitely know more of what
you're talking about than I do, and I appreciate the time you've taken
to help me out.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Getting tomcat instance information into webapp
Posted by Kyle <kl...@attitia.com>.
David Kerber wrote:
>
> Then how do I isolate the instances of tomcat (and their respective
> server.xml's? Do I need multiple installations of tomcat on my disk?
>
Start each 'instance' of tomcat with separate CATALINA_BASE env. vars.
This enables a different server.xml for each instance thereby allowing a
different connector port for each instance. As for the webapp, you can
still re-use the same code via the docBase and appBase variables by
specifiying absolute paths. (read RUNNING.TXT with your install)
Does that work?
Alternatively, IF you can use the scenario where the users are
connecting to the same app, but under different sub-directories of your
domain, e.g.;
www.example.com/appA
www.example.com/appB
www.example.com/appC
Then, you can still have different contexts and/or realms (if
necessary). But in this scenario, you wouldn't need multiple instances
running on different ports would you? Just the one instance listening on
the one port, with TC (as far as TC is concerned) serving up different
webapps which all happen to point to the same absolute docBase/appBase,
just with different jdbc connection params in their respective contexts
connecting them to their relevant database. Surely, that's an acceptable
solution if the only difference in your scenario is to have them
connecting on different ports. This way there are also less ports open
if in a secure environment.
USUAL DISCLAIMER: etc. etc. etc. i.e. I may not have the faintest idea
of what I'm talking about and everything written above should be taken
with a pinch of salt until proven to work AND perform in your environment.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Getting tomcat instance information into webapp
Posted by Kyle <kl...@attitia.com>.
Ah! Yes.
See! I did mention I wasn't an expert. :) Yes, multiple instances, in
my outlaid scenario equates to multiple installs. Whereas, multiple
running instances doesn't necessarily. Sorry.
Let me have a think about that for an hour or 4.
How do you tell tomcat which port to listen on unless you have separate
server.xml's (with defined connectors) each mentioning the port on which
TC should listen?
K
David Kerber wrote:
> You have multiple instances of tamcat running. This means you will
> have multiple server.xml's (meaning multiple "Engine"s in which you
> can set up your multiple realms and direct each different realm to
> whichever db you want to direct it to. As server.xml is unique (in
> std. format config.) to a tomcat instance, you have complete control
> over which port-instance looks at which db.
>
> Then how do I isolate the instances of tomcat (and their respective
> server.xml's? Do I need multiple installations of tomcat on my disk?
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Getting tomcat instance information into webapp
Posted by David Kerber <dc...@verizon.net>.
Kyle wrote:
> I may be misunderstanding the question, but it seems to me that this
> shouldn't really be an issue.
It's more likely that I don't know enought about tomcat to ask an
intelligent question!
>
> You have multiple instances of tamcat running. This means you will
> have multiple server.xml's (meaning multiple "Engine"s in which you
> can set up your multiple realms and direct each different realm to
> whichever db you want to direct it to. As server.xml is unique (in
> std. format config.) to a tomcat instance, you have complete control
> over which port-instance looks at which db.
Then how do I isolate the instances of tomcat (and their respective
server.xml's? Do I need multiple installations of tomcat on my disk?
>
> Again, because you have multiple instances, you will (should) have
> multiple contexts/context.xml's (dependent upon your tomcat version)
> in which you can set up your jdbc resources and the various connect
> criteria for the different db's.
Ok, I didn't know that. Right now, my jdbc connection criteria is
hard-coded in the application (I didn't write it; just inherited it).
It is set up to look for a specific ODBC DSN. I can easily change the
app to look for a configurable DSN, but don't know how to get that
config info into the application.
>
> I may be mistaken, but if the app. is written correctly _and_ the
> different resources in the different contexts are all set up with the
> same names, you could even then get away with just having the one
> context root/appbase with the one jdbcURL context-param in web.xml. In
> this way, the same code would hit and serve up the different data
> dependent upon which port-instance of tomcat it was hitting.
I'll have to do some more careful reading about my context and
server.xml entries.
>
> DISCLAIMER: I haven't tried this and I'm no tomcat expert, but I
> personally, at my lvl of expertise, am unaware of any reason why this
> wouldn't work.
>
> Hopefully, someone more knowledgeable will jump in and correct me if
> I'm way off base.
>
> K.
Thanks for the response!
Dave
>
>
> David Kerber wrote:
>
>> This question is part tomcat and part java; I'm running on a Windows
>> 2000 server.
>>
>> I have a situation where I am going to need to run multiple instances
>> of tomcat on a single machine, listening on different ports, but
>> running the same application and hitting a different instance of an
>> identical database (same schema, but on a different server). So what
>> I will need to do is be able to tell each instance of the application
>> on its respective instance of tomcat which database to hit.
>> Can I pass a parameter into tomcat from a conf file based on what
>> port that instance of tomcat is listening on, and then get that
>> parameter into my application? If so, how?
>>
>> Another option is for my application to grab the machine name and
>> port that it is handling, and hit a "common" database to get the
>> information on what copy of the production to use. But again, I need
>> my app to be able to find port information from tomcat, and I don't
>> know how to do that.
>>
>> It seems like a 3rd option might be to run each instance of tomcat as
>> a service, logged on with different accounts, and use a user DSN
>> instead of a system DSN, with the same DSN name, but different
>> connection info. Is that possible?
>>
>> If necessary, I could install multiple instances of my app at
>> different context paths, but I still don't know how to tell them to
>> pick up the correct database connection info. I guess I could make a
>> code change in the first page they hit, the logon.jsp, for each
>> instance, but I'd rather not have to do that unless there really is
>> no other way, because that would be easy to screw up when making
>> changes later on...
>>
>> Any suggestions as to which of the above approaches would be the
>> best, or another one I haven't thought of?
>>
>> Thanks!
>> DAve
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Getting tomcat instance information into webapp
Posted by Kyle <kl...@attitia.com>.
I may be misunderstanding the question, but it seems to me that this
shouldn't really be an issue.
You have multiple instances of tamcat running. This means you will have
multiple server.xml's (meaning multiple "Engine"s in which you can set
up your multiple realms and direct each different realm to whichever db
you want to direct it to. As server.xml is unique (in std. format
config.) to a tomcat instance, you have complete control over which
port-instance looks at which db.
Again, because you have multiple instances, you will (should) have
multiple contexts/context.xml's (dependent upon your tomcat version) in
which you can set up your jdbc resources and the various connect
criteria for the different db's.
I may be mistaken, but if the app. is written correctly _and_ the
different resources in the different contexts are all set up with the
same names, you could even then get away with just having the one
context root/appbase with the one jdbcURL context-param in web.xml. In
this way, the same code would hit and serve up the different data
dependent upon which port-instance of tomcat it was hitting.
DISCLAIMER: I haven't tried this and I'm no tomcat expert, but I
personally, at my lvl of expertise, am unaware of any reason why this
wouldn't work.
Hopefully, someone more knowledgeable will jump in and correct me if I'm
way off base.
K.
David Kerber wrote:
> This question is part tomcat and part java; I'm running on a Windows
> 2000 server.
>
> I have a situation where I am going to need to run multiple instances
> of tomcat on a single machine, listening on different ports, but
> running the same application and hitting a different instance of an
> identical database (same schema, but on a different server). So what
> I will need to do is be able to tell each instance of the application
> on its respective instance of tomcat which database to hit.
> Can I pass a parameter into tomcat from a conf file based on what port
> that instance of tomcat is listening on, and then get that parameter
> into my application? If so, how?
>
> Another option is for my application to grab the machine name and port
> that it is handling, and hit a "common" database to get the
> information on what copy of the production to use. But again, I need
> my app to be able to find port information from tomcat, and I don't
> know how to do that.
>
> It seems like a 3rd option might be to run each instance of tomcat as
> a service, logged on with different accounts, and use a user DSN
> instead of a system DSN, with the same DSN name, but different
> connection info. Is that possible?
>
> If necessary, I could install multiple instances of my app at
> different context paths, but I still don't know how to tell them to
> pick up the correct database connection info. I guess I could make a
> code change in the first page they hit, the logon.jsp, for each
> instance, but I'd rather not have to do that unless there really is no
> other way, because that would be easy to screw up when making changes
> later on...
>
> Any suggestions as to which of the above approaches would be the best,
> or another one I haven't thought of?
>
> Thanks!
> DAve
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org