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



Basic question about application configuration

2019-10-22 Thread Mathieu Dubois

Dear Tomcat users,

I am not familiar with Tomcat or the Java world in general so I have a 
rather simple question.


Part of my job is to maintain and evolve a Java web application based on 
JBPM which as such use a (MySQL) DB. This application is independently 
deployed on a handful Tomcat servers (each instance uses a different 
DB). We use a very old version of Tomcat (5.5.17) but I don't think that 
this is related to my question.


We use maven to create the WAR file. Right now we have to create one WAR 
file per server based on different maven profiles (i.e. running `mvn 
-Pserver1 ...' then `mvn -Pserver2 ...', etc.). Those profiles contains 
the MySQL DB to use (and other configuration) which is used to configure 
Hibernate (and other libraries) at compile time for this server.


As you can imagine, there are several problems with this approach: it is 
impossible to deploy without the source code and maven, the 
configuration of each deployment has to be in the code, etc.


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 ?

Thanks in advance,
Mathieu Dubois

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