-----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:
>> 
>> <?xml version="1.0"?> <web-app
>> 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"> <context-param> <description> You can
>> put whatever you want in here. It's just documentation for human
>> readers. </description> 
>> <param-name>my-configuration-property-name</param-name> 
>> <param-value>my value</param-value> </context-param> ... 
>> </web-app>
>> 
>> If you want to put, for example, a directory path in here for
>> storing temporary files, you could do it like this:
>> 
>> <web-app> <context-param> <description>Path to the temporary file
>> directory where we write filed.</description> 
>> <param-name>fr.cns.genoscope.appname.tmpfiledir</param-name> 
>> <param-value>/tmp/app/temp-files</param-value> </context-param> 
>> ... </web-app>
>> 
>> 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:
>> 
>> <?xml version="1.0"?> <Context> <Parameter
>> name="fr.cns.genoscope.appname.tmpfiledir" 
>> value="/usr/local/other/location/for/client/X" override="true"/> 
>> ... </Context>
>> 
>> 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 <Engine> 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 <Host> 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 that.

If you define your data source(s) in conf/[engine]/[host]/[app].xml
then you don't even need to "map" them into your application because
they should already be mapped.

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

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl2yIrAACgkQHPApP6U8
pFjQcg//d+cw86NIByikbnYsCccD7e5Ca4NjBkf9IoDLbqHaxIKZf6Ci3dHhWApB
JcgzWBlL/+c51rz5xwCyz9qUxfOwPrQbxdhjrgkW5huGESAINl8tg01P5mlXtPs1
NsiecH/whevzUZhUiKEXq5bJBffoBQYsUMdgaRN3yATF8aXyyKjmfJT1kZ6aZhHA
uUTPrK7lftpufddGjkTWFGbHAVcaY5728cp+BIAc1eZ51TZrfi3WxtHWRZvn8OoK
a2B81Y7he+QN+OG25w3E5JwX8XWEVNWH10iPqSmvO+h5efZlBol46AtP9saJ0lno
BCqjIoc4uMBgFXPkKJJluvgWRQdthHK03iKK/cAVYxrBeOSqnIliRfl1iJUmj+jZ
gDzY9mNgp1Y/ICe+PGHy5zIguHGyaCTWDHn1qar6EaU7Zi67qiSORKCRFBeSTWFy
gZH0uqWo4X/Neq4z96E+iuDVhPJlM+WRYl/uH4BfkubK/DmMXIZ1LcCX7frnDXoA
Q8hDzrAKcQV3txe5JgsoCe7QrKaQsPM784lFAQta2joZ3RIwG0O0T7t6UXINgTKP
kNJ1V0dnMa+li5w3c+g7cQNDHH33aJ5I0RcwBaP1gT9qpszuJ5znaHoOKs10U25V
K73FfcDngC/Z9eh0O0P7ug/g0McJZZL2BM9DRPTJKajPT8Bk0GA=
=DeCG
-----END PGP SIGNATURE-----

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

Reply via email to