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 2007/01/25 15:06:28 UTC
Storing webapp startup parameters
I know of two built-in methods of storing preferences for a webapp, but
need one with characteristics which combine both of them.
Using the java Preferences class allows changes to be made while the app
is running, but AFAICS they will apply to all instances of tomcat
running on a given machine, since they are based on the class retreiving
their values. Putting parameters in the web.xml or server.xml allows
different settings for each instance of tomcat running on a given
machine, but requires bouncing the server to put changes into effect.
Is there a built-in method of having different settings for each
instance of tomcat, but which won't require bouncing tomcat to put the
changes into effect? I know I could roll my own with a disk file (like
a windows .ini file), but would rather not have to do that if I can
avoid it.
Thanks!
Dave
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave,
David Kerber wrote:
> Christopher Schultz wrote:
>> Take a look at <env-entry> in the web.xml: i think you can just put it
>> there and not put anything in server.xml, which would be better, I think.
>>
> Doesn't seem to work - my app isn't finding the variable name at all. I
> think it's because at the point I need the value, the servlet section of
> my app hasn't initialized yet;
<env-entry> elements (in web.xml) ought to be processed before any
servlets are brought into service. I've never actually used <env-entry>,
so make sure that you read all the documentation about it. For instance,
it may or may not automatically add the "java:comp/env" prefix to your
variables.
> just some stuff that I start as soon as the context loads at TC
> startup. This is for looking for files on disk, which I check every
> minute whether or not anybody has hit my app through the browser.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFulKT9CaO5/Lv0PARAgChAJ9YJV0QyFWVYmwal4PozOPBipKfigCaA36B
kESzwR9omdKYNRI3OuL6JvE=
=eI8b
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by David Kerber <dc...@verizon.net>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> David,
>
> David Kerber wrote:
>
>> Christopher Schultz wrote:
>>
>>> Aah, okay. That's the same thing as <env-entry> in web.xml, I think.
>>>
>>>
>>>
>> I think I need to look at that; I'd like to eliminate the entry in
>> server.xml if possible...
>>
>
> Take a look at <env-entry> in the web.xml: i think you can just put it
> there and not put anything in server.xml, which would be better, I think.
>
Doesn't seem to work - my app isn't finding the variable name at all. I
think it's because at the point I need the value, the servlet section of
my app hasn't initialized yet; just some stuff that I start as soon as
the context loads at TC startup. This is for looking for files on disk,
which I check every minute whether or not anybody has hit my app through
the browser.
...
>> (Or is that no 'tribble' at all <GGG>??).
>>
>
> Ooh. -1 for bad Star Trek humor ;)
>
Too bad I can't type with a Scottish accent!
Dave
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David,
David Kerber wrote:
> Christopher Schultz wrote:
>> Aah, okay. That's the same thing as <env-entry> in web.xml, I think.
>>
>>
> I think I need to look at that; I'd like to eliminate the entry in
> server.xml if possible...
Take a look at <env-entry> in the web.xml: i think you can just put it
there and not put anything in server.xml, which would be better, I think.
>> A JNDI browser might simplify this for you if you can either deploy it
>> into your existing application, or if you can somehow connect to it from
>> the outside. Otherwise, you can write some quickie preference editor
>> yourself.
>
> Very cool; Thanks, Chris! I didn't know I could do that.
Well, like I said... I haven't done it myself. There was a question on
this list this week about mutability of the JNDI values through Tomcat.
It's possible that Tomcat provides a read-only view of the directory, so
you might be hosed in that case. Perhaps there is a way around that.
> I guess that's what happens when I just copy some code from a web
> page, without really understanding where it's coming from.. I have
> already done some preference editors that use the java Preferences
> class, so modifying them to use this should be no trouble at all.
In fact, you might be able to write a class that looks like a
Preferences object and really delegates all calls to JNDI.
> (Or is that no 'tribble' at all <GGG>??).
Ooh. -1 for bad Star Trek humor ;)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFuQMb9CaO5/Lv0PARApH0AJ0Ygr9fPcGnl3gpaz5da9k9NClodgCgwe9x
m8gQJDQUnExIPQataRIopWY=
=ll0S
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by David Kerber <dc...@verizon.net>.
Christopher Schultz wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Dave,
>
>David Kerber wrote:
>
>
>>No, I'm using <env-entry>, with this in server.xml:
>>
>> <Environment name="fileImportInterval" type="java.lang.String"
>>value="60"/>
>>
>>This in web.xml:
>> <resource-env-ref>
>> <resource-env-ref-name>fileImportInterval</resource-env-ref-name>
>> <resource-env-ref-type>java.lang.string</resource-env-ref-type>
>> </resource-env-ref>
>>
>>
>
>Aah, okay. That's the same thing as <env-entry> in web.xml, I think.
>
>
I think I need to look at that; I'd like to eliminate the entry in
server.xml if possible...
>
>
>>public static String getEnvironmentVariable( ... )
>> InitialContext initCtx = new InitialContext();
>> Context envCtx = (Context) initCtx.lookup("java:comp/env" );
>> envCtx.lookup( envVarName );
>>
>>
>
>That looks good.
>
>
>
>>Is that what the above method does? Or is there another way? Remember,
>>my ultimate goal here is to be able to change these settings without
>>bouncing my webapp.
>>
>>
>
>Right. Since you are getting those values from JNDI, you can simply
>replace them in JNDI. Instead of using envCtx.lookup(varName), use
>envCtx.bind(varName, newValue) to change it.
>
>Instance preference change.
>
>A JNDI browser might simplify this for you if you can either deploy it
>into your existing application, or if you can somehow connect to it from
>the outside. Otherwise, you can write some quickie preference editor
>yourself.
>
>
Very cool; Thanks, Chris! I didn't know I could do that. I guess
that's what happens when I just copy some code from a web page, without
really understanding where it's coming from.. I have already done some
preference editors that use the java Preferences class, so modifying
them to use this should be no trouble at all. (Or is that no 'tribble'
at all <GGG>??).
Dave
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Pid <p...@pidster.com>.
Caldarale, Charles R wrote:
>> From: David Kerber [mailto:dckerber@verizon.net]
>> Subject: Re: Storing webapp startup parameters
>>
>> I thought the webapp had to be bounced for this to take
>> effect, but I'd love to be proven wrong about that!
>
> You're right, it does appear that even a new InitialContext object does
> not pick up changes made on the fly by the admin app, so the webapp
> would have to be restarted. Also, the admin Commit Changes button
> doesn't rewrite the target app's web.xml (at least in 5.5.20), so any
> environment or resource values have to be in the context.xml for the
> webapp to do this at all.
what about a WatchedResource in the context.xml? I think that causes the
context to reload, which may not be a good thing...
> It looks like Chris' suggestion of using a real JNDI browser will be
> required.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Storing webapp startup parameters
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Kerber [mailto:dckerber@verizon.net]
> Subject: Re: Storing webapp startup parameters
>
> I thought the webapp had to be bounced for this to take
> effect, but I'd love to be proven wrong about that!
You're right, it does appear that even a new InitialContext object does
not pick up changes made on the fly by the admin app, so the webapp
would have to be restarted. Also, the admin Commit Changes button
doesn't rewrite the target app's web.xml (at least in 5.5.20), so any
environment or resource values have to be in the context.xml for the
webapp to do this at all.
It looks like Chris' suggestion of using a real JNDI browser will be
required.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by David Kerber <dc...@verizon.net>.
Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net]
>> Subject: Re: Storing webapp startup parameters
>>
>> A JNDI browser might simplify this for you if you can either deploy it
>> into your existing application, or if you can somehow connect
>> to it from the outside.
>>
>
> Doesn't Tomcat's admin app have this capability, including handling
> <Environment> entries specified in server.xml? The default server.xml
> contains this sample:
>
> <Environment name="simpleValue" type="java.lang.Integer"
> value="30"/>
>
> By using admin -> Resources -> Environment Entries -> simpleValue, you
> can change the 30 to any desired integer on the fly. The result should
> be immediately visible to any code looking it up. Using the Commit
> button preserves the value across Tomcat restarts by rewriting
> server.xml.
>
I thought the webapp had to be bounced for this to take effect, but I'd
love to be proven wrong about that! I'll play with it a bit.
Dave.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Storing webapp startup parameters
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: Storing webapp startup parameters
>
> A JNDI browser might simplify this for you if you can either deploy it
> into your existing application, or if you can somehow connect
> to it from the outside.
Doesn't Tomcat's admin app have this capability, including handling
<Environment> entries specified in server.xml? The default server.xml
contains this sample:
<Environment name="simpleValue" type="java.lang.Integer"
value="30"/>
By using admin -> Resources -> Environment Entries -> simpleValue, you
can change the 30 to any desired integer on the fly. The result should
be immediately visible to any code looking it up. Using the Commit
button preserves the value across Tomcat restarts by rewriting
server.xml.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave,
David Kerber wrote:
> No, I'm using <env-entry>, with this in server.xml:
>
> <Environment name="fileImportInterval" type="java.lang.String"
> value="60"/>
>
> This in web.xml:
> <resource-env-ref>
> <resource-env-ref-name>fileImportInterval</resource-env-ref-name>
> <resource-env-ref-type>java.lang.string</resource-env-ref-type>
> </resource-env-ref>
Aah, okay. That's the same thing as <env-entry> in web.xml, I think.
> public static String getEnvironmentVariable( ... )
> InitialContext initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env" );
> envCtx.lookup( envVarName );
That looks good.
> Is that what the above method does? Or is there another way? Remember,
> my ultimate goal here is to be able to change these settings without
> bouncing my webapp.
Right. Since you are getting those values from JNDI, you can simply
replace them in JNDI. Instead of using envCtx.lookup(varName), use
envCtx.bind(varName, newValue) to change it.
Instance preference change.
A JNDI browser might simplify this for you if you can either deploy it
into your existing application, or if you can somehow connect to it from
the outside. Otherwise, you can write some quickie preference editor
yourself.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFuPPC9CaO5/Lv0PARAqc4AKCwXw6l6DUdFnp16dqDX3i21yM0PwCfaaid
j6doWZ3B+KZcG0/uIgLTyKM=
=fLpv
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by David Kerber <dc...@verizon.net>.
Christopher Schultz wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Dave,
>
>David Kerber wrote:
>
>
>>Christopher Schultz wrote:
>>
>>
>>>You could store your preferences in a JNDI context.
>>>
>>>If you use <env-entry> in your web.xml instead of using <context-param>
>>>or something else, then they will be automatically loaded into the
>>>directory on startup, so you get your default values.
>>>
>>>
>>Yes, that's how I'm doing it, but changing the values in the <env-entry>
>>requires bouncing tomcat for my webapp to see the changes, unless
>>there's something I'm missing there.
>>
>>
>
>You are using <context-param>? Right: don't do that. Instead, use
>
>
No, I'm using <env-entry>, with this in server.xml:
<Environment name="fileImportInterval" type="java.lang.String"
value="60"/>
This in web.xml:
<resource-env-ref>
<resource-env-ref-name>fileImportInterval</resource-env-ref-name>
<resource-env-ref-type>java.lang.string</resource-env-ref-type>
</resource-env-ref>
and retrieving it with this method:
public static String getEnvironmentVariable( String envVarName, String varDefault) {
String parm;
try {
InitialContext initCtx = new InitialContext();
if (initCtx == null) throw new Exception( "No Context for database setting" );
Context envCtx = (Context) initCtx.lookup( "java:comp/env" );
parm = (String) envCtx.lookup( envVarName );
} catch(Exception e) {
parm = varDefault;
}
return parm;
}
><env-entry> and use JNDI to get your preferences. Don't cache them
>anywhere... always get them from JNDI.
>
>
Is that what the above method does? Or is there another way? Remember,
my ultimate goal here is to be able to change these settings without
bouncing my webapp.
Dave
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dave,
David Kerber wrote:
> Christopher Schultz wrote:
>> You could store your preferences in a JNDI context.
>>
>> If you use <env-entry> in your web.xml instead of using <context-param>
>> or something else, then they will be automatically loaded into the
>> directory on startup, so you get your default values.
>
> Yes, that's how I'm doing it, but changing the values in the <env-entry>
> requires bouncing tomcat for my webapp to see the changes, unless
> there's something I'm missing there.
You are using <context-param>? Right: don't do that. Instead, use
<env-entry> and use JNDI to get your preferences. Don't cache them
anywhere... always get them from JNDI.
Using a JNDI browser (or something quick you write yourself), you can
change the values in the JNDI context which should affect the operation
of your webapp. No restart required, as long as you don't cache those
preferences anywhere.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFuM0o9CaO5/Lv0PARAscqAJ4k9nHG4gpecbFhqjOjphYEe72TagCeKD9B
nht4SGPeJSF+8BJQx5LOPd8=
=LDLe
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by David Kerber <dc...@verizon.net>.
Christopher Schultz wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>David,
>
>David Kerber wrote:
>
>
>>Is there a built-in method of having different settings for each
>>instance of tomcat, but which won't require bouncing tomcat to put the
>>changes into effect? I know I could roll my own with a disk file (like
>>a windows .ini file), but would rather not have to do that if I can
>>avoid it.
>>
>>
>
>You could store your preferences in a JNDI context.
>
>If you use <env-entry> in your web.xml instead of using <context-param>
>or something else, then they will be automatically loaded into the
>directory on startup, so you get your default values.
>
>
Yes, that's how I'm doing it, but changing the values in the <env-entry>
requires bouncing tomcat for my webapp to see the changes, unless
there's something I'm missing there.
>You should be able to use an off-the-shelf JNDI browser to navigate your
>preferences and perhaps even change them. You can always write your own
>code to change them, of course. (There's a parallel thread on the list
>right now about the immutability of JNDI information, so you might want
>to pay attention to what's going on, there).
>
>
I've never touched JNDI, so I'll have to look into that.
>I've never done this myself but it sounds feasible.
>
>Another option would be to just use a properties file on the disk and
>monitor it for changes, similar to how TC's reloadable contexts monitor
>files. It's kinda messy, but it'll work.
>
>
Yeah, that's what I was referring to when I mentioned rolling my own,
which I'd rather not do unless I get stuck
Thanks!
Dave
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Storing webapp startup parameters
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David,
David Kerber wrote:
> Is there a built-in method of having different settings for each
> instance of tomcat, but which won't require bouncing tomcat to put the
> changes into effect? I know I could roll my own with a disk file (like
> a windows .ini file), but would rather not have to do that if I can
> avoid it.
You could store your preferences in a JNDI context.
If you use <env-entry> in your web.xml instead of using <context-param>
or something else, then they will be automatically loaded into the
directory on startup, so you get your default values.
You should be able to use an off-the-shelf JNDI browser to navigate your
preferences and perhaps even change them. You can always write your own
code to change them, of course. (There's a parallel thread on the list
right now about the immutability of JNDI information, so you might want
to pay attention to what's going on, there).
I've never done this myself but it sounds feasible.
Another option would be to just use a properties file on the disk and
monitor it for changes, similar to how TC's reloadable contexts monitor
files. It's kinda messy, but it'll work.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFuL0d9CaO5/Lv0PARAiuyAJ4ya3m0r9AEbxNZ0BQhA8TZkrGVMACgjkuR
NzLMzOE3ElBYP2tt4ChHTOI=
=ji7Y
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org