Re: AW: Basic question about application configuration

2019-10-24 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Mathieu,

On 10/24/19 14:26, Mathieu Dubois wrote:
> Dear Christopher,
> 
> Le 24/10/2019 à 00:36, Christopher Schultz a écrit :
>> -BEGIN PGP SIGNED MESSAGE- Hash: SHA256
>> 
>> Mathieu,
>> 
>> On 10/23/19 17:23, Mathieu Dubois wrote:
>>> I noticed that the application also need to access to a
>>> directory to store the result of some computation usually
>>> outside the location of tomcat (the results can be rather
>>> large). As for the DB this depends on each instance of the
>>> application. Is there a similar mechanism for such a case ?
>> It's not exactly clear what you are asking, but it sounds like
>> you are looking for a configuration similar to the JNDI binding
>> that can be split between conf/server.xml and
>> META-INF/context.xml for connecting to a database.
>> 
>> You have some choices, here, and the "right one" probably will
>> require you to make a decision based upon your requirements.
>> 
>> In WEB-INF/web.xml, there are some optional configuration data
>> called "context parameters". They look something like this:
>> 
>>  > xmlns="http://java.sun.com/xml/ns/javaee; 
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
>> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd; version="3.0" 
>> metadata-complete="true">   You can
>> put whatever you want in here. It's just documentation for human
>> readers.  
>> my-configuration-property-name 
>> my value  ... 
>> 
>> 
>> If you want to put, for example, a directory path in here for
>> storing temporary files, you could do it like this:
>> 
>>   Path to the temporary file
>> directory where we write filed. 
>> fr.cns.genoscope.appname.tmpfiledir 
>> /tmp/app/temp-files  
>> ... 
>> 
>> In order to use these configuration values, your code needs to
>> read them explicitly, so you'll need to make some code changes in
>> order to put your configuration into WEB-INF/web.xml. Something
>> like this in your servlet:
>> 
>> String tmpDir = 
>> getServletContext().getInitParam("fr.cns.genoscope.appname.tmpfiledir
");
>>
>> 
// ... use the tmpDir for all your file-writing needs
>> 
>> Now, WEB-INF/web.xml is bundled inside your WAR file and, as
>> you've mentioned, it's not very flexible with your builds. So,
>> here's what you can do:
>> 
>> The file META-INF/context.xml (also bundled within your
>> application's WAR file -- hold that thought for a minute) can be
>> used to override the values of your context-param values, like
>> this:
>> 
>>   > name="fr.cns.genoscope.appname.tmpfiledir" 
>> value="/usr/local/other/location/for/client/X" override="true"/> 
>> ... 
>> 
>> More info can be found at: 
>> http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_P
ara
>>
>> 
meters
>> 
>> So, you could put the right value into WEB-INF/web.xml (which is 
>> inconvenient) or into META-INF/context.xml (which is also 
>> inconvenient) or -- and here's where things get a little
>> interesting - -- you can copy the file META-INF/context.xml from
>> the WAR file and put it into Tomcat's configuration directory
>> structure like this:
>> 
>> conf/[enginename]/[hostname]/[appname].xml
>> 
>> ...and it will *override* the file supplied by the WAR file in 
>> META-INF/context.xml. So you get to use the same WAR file
>> everywhere and customize those XML files on a per-client basis.
>> 
>> Above, the [enginename] is almost always "Catalina" and matches
>> the "name" attribute of the  in your conf/server.xml
>> file. By default, it's name="Catalina" and pretty much nobody
>> ever changes it. Your [hostname] comes from the "name" attribute
>> of the  in which your context/webapp is defined, and is
>> often just "localhost" although it would be anything depending
>> upon your environment. The [appname] is whatever you want it to
>> be: the [appname] sets the context-path of the application. But
>> the [appname].xml must match your [appname].war file name.
>> 
>> So if you don't mind modifying your code a little, this can get
>> your a lot of flexibility.
>> 
>> This feature goes back to Tomcat 5.5, so you should be able to
>> use it. I'd of course encourage you to look at upgrading to at
>> least Tomcat 8.5 in the near-term. You may find that you can just
>> drop-in the latest Tomcat 8.5.x in place of your Tomcat 5.5 and
>> everything still works. (You will have to re-write your
>> conf/server.xml file from scratch, as those files are not
>> compatible between major releases.)
> 
> Thanks for your in-depth explanation, it really helps. If I
> summarize, I can use conf/[enginename]/[hostname]/[appname].xml to
> configure both the DB connection (with a Resource) and the
> directory where to write files (with a param). That sounds exactly
> like what we need.

You can do exactly that.

In order to use context-params, though, you will probably need to
modify your code to pick-up that configuration. Hopefully, it's not
too much trouble to do 

Re: AW: Basic question about application configuration

2019-10-24 Thread Mathieu Dubois

Dear Christopher,

Le 24/10/2019 à 00:36, Christopher Schultz a écrit :

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Mathieu,

On 10/23/19 17:23, Mathieu Dubois wrote:

I noticed that the application also need to access to a directory
to store the result of some computation usually outside the
location of tomcat (the results can be rather large). As for the DB
this depends on each instance of the application. Is there a
similar mechanism for such a case ?

It's not exactly clear what you are asking, but it sounds like you are
looking for a configuration similar to the JNDI binding that can be
split between conf/server.xml and META-INF/context.xml for connecting
to a database.

You have some choices, here, and the "right one" probably will require
you to make a decision based upon your requirements.

In WEB-INF/web.xml, there are some optional configuration data called
"context parameters". They look something like this:


http://java.sun.com/xml/ns/javaee;
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd;
  version="3.0"
  metadata-complete="true">
   
 
   You can put whatever you want in here. It's just documentation
   for human readers.
 
 my-configuration-property-name
 my value
   
   ...


If you want to put, for example, a directory path in here for storing
temporary files, you could do it like this:


   
 Path to the temporary file directory where we write
filed.
 fr.cns.genoscope.appname.tmpfiledir
 /tmp/app/temp-files
   
   ...


In order to use these configuration values, your code needs to read
them explicitly, so you'll need to make some code changes in order to
put your configuration into WEB-INF/web.xml. Something like this in
your servlet:

 String tmpDir =
getServletContext().getInitParam("fr.cns.genoscope.appname.tmpfiledir");
 // ... use the tmpDir for all your file-writing needs

Now, WEB-INF/web.xml is bundled inside your WAR file and, as you've
mentioned, it's not very flexible with your builds. So, here's what
you can do:

The file META-INF/context.xml (also bundled within your application's
WAR file -- hold that thought for a minute) can be used to override
the values of your context-param values, like this:



   
  ...


More info can be found at:
http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_Para
meters

So, you could put the right value into WEB-INF/web.xml (which is
inconvenient) or into META-INF/context.xml (which is also
inconvenient) or -- and here's where things get a little interesting
- -- you can copy the file META-INF/context.xml from the WAR file and
put it into Tomcat's configuration directory structure like this:

conf/[enginename]/[hostname]/[appname].xml

...and it will *override* the file supplied by the WAR file in
META-INF/context.xml. So you get to use the same WAR file everywhere
and customize those XML files on a per-client basis.

Above, the [enginename] is almost always "Catalina" and matches the
"name" attribute of the  in your conf/server.xml file. By
default, it's name="Catalina" and pretty much nobody ever changes it.
Your [hostname] comes from the "name" attribute of the  in which
your context/webapp is defined, and is often just "localhost" although
it would be anything depending upon your environment. The [appname] is
whatever you want it to be: the [appname] sets the context-path of the
application. But the [appname].xml must match your [appname].war file
name.

So if you don't mind modifying your code a little, this can get your a
lot of flexibility.

This feature goes back to Tomcat 5.5, so you should be able to use it.
I'd of course encourage you to look at upgrading to at least Tomcat
8.5 in the near-term. You may find that you can just drop-in the
latest Tomcat 8.5.x in place of your Tomcat 5.5 and everything still
works. (You will have to re-write your conf/server.xml file from
scratch, as those files are not compatible between major releases.)


Thanks for your in-depth explanation, it really helps. If I summarize, I 
can use conf/[enginename]/[hostname]/[appname].xml to configure bith the 
DB connection (with a Resource) and the directory where to write files 
(with a param). That sounds exactly like what we need.


Thanks again,
Mathieu

--
Mathieu Dubois - IR - UMR 8030 équipe LABGeM
CEA - Genoscope. 2 rue Gaston Crémieux. 91057 Evry Cedex France.
Bureau B07
+33 1 60 87 53 35


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



Re: AW: Basic question about application configuration

2019-10-23 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Mathieu,

On 10/23/19 17:23, Mathieu Dubois wrote:
> I noticed that the application also need to access to a directory
> to store the result of some computation usually outside the
> location of tomcat (the results can be rather large). As for the DB
> this depends on each instance of the application. Is there a
> similar mechanism for such a case ?

It's not exactly clear what you are asking, but it sounds like you are
looking for a configuration similar to the JNDI binding that can be
split between conf/server.xml and META-INF/context.xml for connecting
to a database.

You have some choices, here, and the "right one" probably will require
you to make a decision based upon your requirements.

In WEB-INF/web.xml, there are some optional configuration data called
"context parameters". They look something like this:


http://java.sun.com/xml/ns/javaee;
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd;
 version="3.0"
 metadata-complete="true">
  

  You can put whatever you want in here. It's just documentation
  for human readers.

my-configuration-property-name
my value
  
  ...


If you want to put, for example, a directory path in here for storing
temporary files, you could do it like this:


  
Path to the temporary file directory where we write
filed.
fr.cns.genoscope.appname.tmpfiledir
/tmp/app/temp-files
  
  ...


In order to use these configuration values, your code needs to read
them explicitly, so you'll need to make some code changes in order to
put your configuration into WEB-INF/web.xml. Something like this in
your servlet:

String tmpDir =
getServletContext().getInitParam("fr.cns.genoscope.appname.tmpfiledir");
// ... use the tmpDir for all your file-writing needs

Now, WEB-INF/web.xml is bundled inside your WAR file and, as you've
mentioned, it's not very flexible with your builds. So, here's what
you can do:

The file META-INF/context.xml (also bundled within your application's
WAR file -- hold that thought for a minute) can be used to override
the values of your context-param values, like this:



  
 ...


More info can be found at:
http://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_Para
meters

So, you could put the right value into WEB-INF/web.xml (which is
inconvenient) or into META-INF/context.xml (which is also
inconvenient) or -- and here's where things get a little interesting
- -- you can copy the file META-INF/context.xml from the WAR file and
put it into Tomcat's configuration directory structure like this:

conf/[enginename]/[hostname]/[appname].xml

...and it will *override* the file supplied by the WAR file in
META-INF/context.xml. So you get to use the same WAR file everywhere
and customize those XML files on a per-client basis.

Above, the [enginename] is almost always "Catalina" and matches the
"name" attribute of the  in your conf/server.xml file. By
default, it's name="Catalina" and pretty much nobody ever changes it.
Your [hostname] comes from the "name" attribute of the  in which
your context/webapp is defined, and is often just "localhost" although
it would be anything depending upon your environment. The [appname] is
whatever you want it to be: the [appname] sets the context-path of the
application. But the [appname].xml must match your [appname].war file
name.

So if you don't mind modifying your code a little, this can get your a
lot of flexibility.

This feature goes back to Tomcat 5.5, so you should be able to use it.
I'd of course encourage you to look at upgrading to at least Tomcat
8.5 in the near-term. You may find that you can just drop-in the
latest Tomcat 8.5.x in place of your Tomcat 5.5 and everything still
works. (You will have to re-write your conf/server.xml file from
scratch, as those files are not compatible between major releases.)

Hope that helps,
- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl2w1gAACgkQHPApP6U8
pFit/g/9EXtTvtvhpbnPxZnObyg+sUjhoFuZI7/Dmczhq03ZzLi+H51KoplM9F3Q
8xDLtunDZrkGQfb2g95Uh7fI4K0rthRzE2UQ6uS7jkodDKNwHuH+dKibUADIDEoF
1DYqHhEzN7v5yZg9ohERs9fI0hzqNutcNqmfquFdnZ7sN9LWh3SOxdkUa1dYooZj
xRNbkZ7/xjULyYEHTEljzQ4n541UDE05qNYQPf+UKCduUcUeTlaS3sJIp8YNa+uT
lnFASUZnsH6CDWU99cYmPdi8GB0Bntt/Ib6QpYeZter6nYKOU/2Hc6Ga6pD5dCTo
DW+kJ008OWzYsROj137Orr9MaSPbvRD7kpCTieADaY9fzUEL2pyQmaY5l0h6uQTN
2sHTE4CIAwL/osKBRkUSZcsEwWMitPxCRiJhIwLn0ae97w3Fd0h9wIag2bzTuf+X
k3CdjhMSSWauhMdlCG9R3kWNfa4ZM5Xn2yVQnCpcR6GfRwwNY7I+EHQVwVi5fl45
QrCDlDyOxJ+FHaedlczrVdCDqAdyieOdsuSlirwbRrYlCClzD+LMAofTRGxvDNvs
lSvl6ove3yhsFGdyNz9C+YDnDyIG9c5QK+Wy0R2LCki9UZ1ynA5WCwuQWw44kTRh
rFeCK3zvQNLcytWIshhK09a3ZeDsMKZnGx+n3lmuA18dOprJ6jg=
=MT/7
-END PGP SIGNATURE-


Re: AW: Basic question about application configuration

2019-10-23 Thread Mathieu Dubois

Hi again,

I noticed that the application also need to access to a directory to 
store the result of some computation usually outside the location of 
tomcat (the results can be rather large). As for the DB this depends on 
each instance of the application. Is there a similar mechanism for such 
a case ?


Thanks in advance,
Mathieu

--
Mathieu Dubois - IR - UMR 8030 équipe LABGeM
CEA - Genoscope. 2 rue Gaston Crémieux. 91057 Evry Cedex France.
Bureau B07
+33 1 60 87 53 35


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



Re: AW: Basic question about application configuration

2019-10-23 Thread Mathieu Dubois

Hi Bernd,

Le 23/10/2019 à 06:55, bernd.sch...@daimler.com a écrit :

Hi Mathieu,


-Ursprüngliche Nachricht-
Von: Mathieu Dubois 
Gesendet: Mittwoch, 23. Oktober 2019 03:00
An: users@tomcat.apache.org

[SNIP]

I have read a bit about Tomcat and if I understand correctly, the
correct way to do is to declare a Resource in the configuration of each
server which represents the DB to use and then adapt the code (in
particular Hibernate configuration) to use this Resource based on it's
name. Then the same WAR file can be deployed on any servers provided
it's configured without maven (i.e. I just have to upload the WAR file
and voilà).

Is that correct ?

Yes, it is a common approach in the Java Application world called jndi.
So your app would also work on a different application server like Wildfly or 
Liberty.

But the way you define it in your application server differs,
So see here for comparison:
https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html
https://developer.jboss.org/thread/279940


Thank you very much for your insight. It will sure help us to 
restructure the project.


Namaste,
Mathieu

--
Mathieu Dubois - IR - UMR 8030 équipe LABGeM
CEA - Genoscope. 2 rue Gaston Crémieux. 91057 Evry Cedex France.
Bureau B07
+33 1 60 87 53 35


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