You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mario Splivalo <ma...@megafon.hr> on 2009/12/14 17:21:54 UTC

'Parametrizing' context.xml?

Is there a way to 'parametrize' context.xml, for instance, in a manner
one can 'parametrize' build.xml?

For some webapplication in context.xml one puts, for instance, JDBC
specific stuff. But, several developers can have different 'properties'
for the database (different user accounts, and so on).

Is there a way to parametrize those somehow, or each developer need to
have separate context.xml?

	Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ken,

On 12/14/2009 11:50 AM, Ken Bowen wrote:
> You can make use of ant's token filtering on copy.

This is exactly what we do to solve the OP's problem: we have a
revision-controlled context.xml file that has all this replacement stuff
in it. Running 'ant build' creates a user-specific context.xml file by
using properties defined in ~/.ant.properties. Our CVS version looks
like this:

<Context reloadable="true">
   <WatchedResource>WEB-INF/struts-config.xml</WatchedResource>
   <WatchedResource>META-INF/context.xml</WatchedResource>

   <Resource name="@DATASOURCE_REF@"
        description="..."
        auth="Container"
        type="javax.sql.DataSource"
        maxActive="1"
        maxIdle="1"
        maxWait="10000"
        url="@DATABASE_URL@"
        username="@DATABASE_USERNAME@"
        password="@DATABASE_PASSWORD@"
        driverClassName="@DATABASE_DRIVER@"
        removeAbandoned="true"
        removeAbandonedTimeout="30"
        logAbandoned="true"
        testOnBorrow="true"
        validationQuery="/* ping */ SELECT 1"
    />
</Context>

We happen to only use this parametric replacement for our <Resource>,
but you can certainly replace anything you want.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksmfCoACgkQ9CaO5/Lv0PCi8wCgj/WupPuKuUxfP0mLxMM/tRTW
b9sAn314U7NStwtp0b0HucCgqljM5xvT
=4xRC
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Ken Bowen <kb...@als.com>.
You can make use of ant's token filtering on copy.
You identify the parameters in your context.xml, and create a separate  
new context.xml with
those parameters identified.   For example, we have several such  
parameters occurring
in our web.xml, such as @BPVAL@ below:
........
<context-param>
     <param-name>baseprefix</param-name>
     <param-value>@BPVAL@</param-value>
  </context-param>
.........

You store the parameterized context.xml in some separate location in  
your tree
(we use WEB-INF/param_src).  Then for each of your users, you create  
an ant task which copies
the parameterized source file to the "real" source file, supplying the  
parameter values to use
for that particular user's task:

<target name="kens_root_setup">
     <copy file="${param.src}/web.xml" tofile="${web.inf}/web.xml"  
overwrite="true" >
         <filterset>
             <filter token="BPVAL" value="/" />
         </filterset>
     </copy>

The only gotcha is that when you have to make modifications to such a  
file, you must
remember to make the mods in the parameterized source file (in $ 
{param.src} ), not to
the "real" file it maps to.

--Ken


On Dec 14, 2009, at 11:21 AM, Mario Splivalo wrote:

> Is there a way to 'parametrize' context.xml, for instance, in a manner
> one can 'parametrize' build.xml?
>
> For some webapplication in context.xml one puts, for instance, JDBC
> specific stuff. But, several developers can have different  
> 'properties'
> for the database (different user accounts, and so on).
>
> Is there a way to parametrize those somehow, or each developer need to
> have separate context.xml?
>
> 	Mike
>
> ---------------------------------------------------------------------
> 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: 'Parametrizing' context.xml?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: pzwedhhs [mailto:pzwedhhs@guerrillamailblock.com] 
> Subject: Re: 'Parametrizing' context.xml?

> I still could not find out, how to access the variable in context.xml.

Are you sure that the context.xml you're modifying is the one being used?  If there's a <Context> element in conf/Catalina/[host]/[appName].xml, that will override the one in your webapp's META-INF/context.xml file.

 - 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 unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by pzwedhhs <pz...@guerrillamailblock.com>.
Ok, adding a line in catalina.properties seems to set the value at least. It
appears, when I call System.getProperties() inside the Java code. However, I
still could not find out, how to access the variable in context.xml.


Laicreparc_ wrote:
> 
> Ok, I have added the line
> 
> DBVAL=mydb_dev
> 
> to catalina.properties.
> 
> Now I define a Realm in my webabb's context.xml:
> 
> <Realm className="org.apache.catalina.realm.JDBCRealm"
> 		driverName="org.postgresql.Driver"
> 		connectionURL="jdbc:postgresql://myserver:5432/${DBVAL}"
> 		connectionName="xxx" connectionPassword="yyy"
> 		userTable="users" userRoleTable="roles"
> 		userNameCol="name" userCredCol="pw" roleNameCol="role"
> 		digest="MD5" />
> 
> However, in the logfiles I can find:
> org.postgresql.util.PSQLException: FATAL: database "${DBVAL}" does not
> exist
> 
> It seems, that the parameter value was not replaced.
> 
> What I would like to have is to define a Realm once in context.xml, that
> will be used both on a development and on a productive server. The servers
> define the actual name of the database (here "mydb_dev"), e.g. in
> catalina.properties.
> 
> 
> Christopher Schultz-2 wrote:
>> 
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> 
>> Laicreparc,
>> 
>> On 4/13/2011 11:38 AM, Laicreparc wrote:
>>> How can the variable (i.e. here BPVAL be set)? E.g. in server.xml?
>> 
>> Did you read the post? It says how to set those values.
>> 
>>> Is <context-param> really in context.xml? Looks more like web.xml to
>>> me.
>> 
>> I think it was just an example. Would you prefer <Resource
>> param="${BPVAL}" />?
>> 
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.10 (MingW32)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>> 
>> iEYEARECAAYFAk2mCvYACgkQ9CaO5/Lv0PAM/ACdHAmti7Wf11o5AUqivmk3iZtw
>> VpsAoLv7NToDVbVThrVCRgO1KTlX21nt
>> =g1qE
>> -----END PGP SIGNATURE-----
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%27Parametrizing%27-context.xml--tp26780552p31407341.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Laicreparc_ <a7...@jnxjn.com>.
Ok, I have added the line

DBVAL=mydb_dev

to catalina.properties.

Now I define a Realm in my webabb's context.xml:

<Realm className="org.apache.catalina.realm.JDBCRealm"
		driverName="org.postgresql.Driver"
		connectionURL="jdbc:postgresql://myserver:5432/${DBVAL}"
		connectionName="xxx" connectionPassword="yyy"
		userTable="users" userRoleTable="roles"
		userNameCol="name" userCredCol="pw" roleNameCol="role"
		digest="MD5" />

However, in the logfiles I can find:
org.postgresql.util.PSQLException: FATAL: database "${DBVAL}" does not exist

It seems, that the parameter value was not replaced.

What I would like to have is to define a Realm once in context.xml, that
will be used both on a development and on a productive server. The servers
define the actual name of the database (here "mydb_dev"), e.g. in
catalina.properties.


Christopher Schultz-2 wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Laicreparc,
> 
> On 4/13/2011 11:38 AM, Laicreparc wrote:
>> How can the variable (i.e. here BPVAL be set)? E.g. in server.xml?
> 
> Did you read the post? It says how to set those values.
> 
>> Is <context-param> really in context.xml? Looks more like web.xml to
>> me.
> 
> I think it was just an example. Would you prefer <Resource
> param="${BPVAL}" />?
> 
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk2mCvYACgkQ9CaO5/Lv0PAM/ACdHAmti7Wf11o5AUqivmk3iZtw
> VpsAoLv7NToDVbVThrVCRgO1KTlX21nt
> =g1qE
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%27Parametrizing%27-context.xml--tp26780552p31397140.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Laicreparc,

On 4/13/2011 11:38 AM, Laicreparc wrote:
> How can the variable (i.e. here BPVAL be set)? E.g. in server.xml?

Did you read the post? It says how to set those values.

> Is <context-param> really in context.xml? Looks more like web.xml to
> me.

I think it was just an example. Would you prefer <Resource
param="${BPVAL}" />?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2mCvYACgkQ9CaO5/Lv0PAM/ACdHAmti7Wf11o5AUqivmk3iZtw
VpsAoLv7NToDVbVThrVCRgO1KTlX21nt
=g1qE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Laicreparc <a5...@jnxjn.com>.
How can the variable (i.e. here BPVAL be set)? E.g. in server.xml? Is
<context-param> really in context.xml? Looks more like web.xml to me.



Bill Barker wrote:
> 
> 
> "Mario Splivalo" <ma...@megafon.hr> wrote in message 
> news:4B27994E.5080808@megafon.hr...
>> Bill Barker wrote:
>>> "Mario Splivalo" <ma...@megafon.hr> wrote in message
>>> news:4B266622.5060806@megafon.hr...
>>>
>>> Tomcat also supports ant-style variable replacement, so using that then
>>> Ken's example would look like:
>>>   <context-param>
>>>      <param-name>baseprefix</param-name>
>>>      <param-value>${BPVAL}</param-value>
>>>   </context-param>
>>>
>>> where BPVAL is a Java system property (that can be set in
>>> catalina.properties for example).
>>
>> And, those can be used also in apps context.xml?
>>
> 
> Yes, this should work in context.xml (and even server.xml).
> 
>>> Of course, this only works for Tomcat.  Ken's suggestion will work on
>>> any
>>> servlet container.
>>
>> Yes, in the long run I'll stick to those, but since we're only using
>> Tomcat for now it would be much easier not to fiddle with ant.
>>
>> Thank you all!
>>
>> Mike 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/%27Parametrizing%27-context.xml--tp26780552p31389193.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Mario Splivalo <ma...@megafon.hr>.
Bill Barker wrote:
> "Mario Splivalo" <ma...@megafon.hr> wrote in message 
> news:4B27994E.5080808@megafon.hr...
>> Bill Barker wrote:
>>> "Mario Splivalo" <ma...@megafon.hr> wrote in message
>>> news:4B266622.5060806@megafon.hr...
>>>
>>> Tomcat also supports ant-style variable replacement, so using that then
>>> Ken's example would look like:
>>>   <context-param>
>>>      <param-name>baseprefix</param-name>
>>>      <param-value>${BPVAL}</param-value>
>>>   </context-param>
>>>
>>> where BPVAL is a Java system property (that can be set in
>>> catalina.properties for example).
>> And, those can be used also in apps context.xml?
>>
> 
> Yes, this should work in context.xml (and even server.xml).

I'm having trouble finding that in documentation. Could you point me out
on where to find more info on this feature?
I can't put BPVAL you mention above in catalina.properties - I have
dozen of web applications, and each of them might have different
'parametars' I'd like to configure. Which means I would need to have
separate 'parametar' entries for each context file.

Thnx in advance,

	Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Bill Barker <bi...@verizon.net>.
"Mario Splivalo" <ma...@megafon.hr> wrote in message 
news:4B27994E.5080808@megafon.hr...
> Bill Barker wrote:
>> "Mario Splivalo" <ma...@megafon.hr> wrote in message
>> news:4B266622.5060806@megafon.hr...
>>
>> Tomcat also supports ant-style variable replacement, so using that then
>> Ken's example would look like:
>>   <context-param>
>>      <param-name>baseprefix</param-name>
>>      <param-value>${BPVAL}</param-value>
>>   </context-param>
>>
>> where BPVAL is a Java system property (that can be set in
>> catalina.properties for example).
>
> And, those can be used also in apps context.xml?
>

Yes, this should work in context.xml (and even server.xml).

>> Of course, this only works for Tomcat.  Ken's suggestion will work on any
>> servlet container.
>
> Yes, in the long run I'll stick to those, but since we're only using
> Tomcat for now it would be much easier not to fiddle with ant.
>
> Thank you all!
>
> Mike 




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Mario Splivalo <ma...@megafon.hr>.
Bill Barker wrote:
> "Mario Splivalo" <ma...@megafon.hr> wrote in message 
> news:4B266622.5060806@megafon.hr...
> 
> Tomcat also supports ant-style variable replacement, so using that then 
> Ken's example would look like:
>   <context-param>
>      <param-name>baseprefix</param-name>
>      <param-value>${BPVAL}</param-value>
>   </context-param>
> 
> where BPVAL is a Java system property (that can be set in 
> catalina.properties for example).

And, those can be used also in apps context.xml?

> Of course, this only works for Tomcat.  Ken's suggestion will work on any 
> servlet container. 

Yes, in the long run I'll stick to those, but since we're only using
Tomcat for now it would be much easier not to fiddle with ant.

Thank you all!

	Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Bill Barker <bi...@verizon.net>.
"Mario Splivalo" <ma...@megafon.hr> wrote in message 
news:4B266622.5060806@megafon.hr...
> Is there a way to 'parametrize' context.xml, for instance, in a manner
> one can 'parametrize' build.xml?
>
> For some webapplication in context.xml one puts, for instance, JDBC
> specific stuff. But, several developers can have different 'properties'
> for the database (different user accounts, and so on).
>
> Is there a way to parametrize those somehow, or each developer need to
> have separate context.xml?
>
> Mike

Tomcat also supports ant-style variable replacement, so using that then 
Ken's example would look like:
  <context-param>
     <param-name>baseprefix</param-name>
     <param-value>${BPVAL}</param-value>
  </context-param>

where BPVAL is a Java system property (that can be set in 
catalina.properties for example).

Of course, this only works for Tomcat.  Ken's suggestion will work on any 
servlet container. 




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Mario Splivalo <ma...@megafon.hr>.
Pid wrote:
> On 14/12/2009 16:21, Mario Splivalo wrote:
>> Is there a way to 'parametrize' context.xml, for instance, in a manner
>> one can 'parametrize' build.xml?
>>
>> For some webapplication in context.xml one puts, for instance, JDBC
>> specific stuff. But, several developers can have different 'properties'
>> for the database (different user accounts, and so on).
>>
>> Is there a way to parametrize those somehow, or each developer need to
>> have separate context.xml?
> 
> Despite the other helpful answers, I'm going to try a different tack.
> 
> If each developer needs the web app to behave differently, then each
> developer will need their own version.
> 
> In order to apply different settings, such as a DB user, one would need
> to restart the application - thus breaking it for other developers.

Actually, each developer has his own Tomcat installation as well as the
application we're all working on. It's just that some use different
Linux distros, some use Windows. I needed a way to include context.xml
in the SCM, but for each developer to have it's own personal version. I
have logger setup, database realm setup (among other thins) in
context.xml. Some developers use Debian with Postgres installed from
packages (so they use postgres system acount for database access on
their workstations), others use custom Postgres installation for Windows
(so they use different username/password for connection to the
database). Some have log files in /var/local/log/tomcatapps/app1/,
others have D:\Projects\WhereIPutMyStuff\ForToday.
Then, production server has Tomcat installed on Debian servers according
to the Debian Policy FSH.
I needed a way to have context.xml in scm, but with a way for each
developer to has his own 'settings'.

Using ant, as nice people described earlier, gives me just that (with a
little bit of overhead - one needs to know that context.xml definition
has changed, and issue 'ant reinitialize' (or whatever) task to build
proper context.xml.

So, I'm happy! :)

	Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: 'Parametrizing' context.xml?

Posted by Pid <pi...@pidster.com>.
On 14/12/2009 16:21, Mario Splivalo wrote:
> Is there a way to 'parametrize' context.xml, for instance, in a manner
> one can 'parametrize' build.xml?
>
> For some webapplication in context.xml one puts, for instance, JDBC
> specific stuff. But, several developers can have different 'properties'
> for the database (different user accounts, and so on).
>
> Is there a way to parametrize those somehow, or each developer need to
> have separate context.xml?

Despite the other helpful answers, I'm going to try a different tack.

If each developer needs the web app to behave differently, then each 
developer will need their own version.

In order to apply different settings, such as a DB user, one would need 
to restart the application - thus breaking it for other developers.


p


> ---------------------------------------------------------------------
> 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