On Tue, Apr 29, 2025 at 1:07 PM Christopher Schultz <
ch...@christopherschultz.net> wrote:

> > ABT,
> >
> > On 4/29/25 11:25 AM, A Name wrote:
> > > On Tue, Apr 29, 2025 at 10:54 AM Christopher Schultz <
> > > ch...@christopherschultz.net> wrote:
> > >>> Are you able to view the sources of the application? Are you (or your
> > >>> team) knowledgeable enough about the code to make such changes?
> IMHO, I
> > >>> would take the time to make these changes because it will simplify
> your
> > >>> application (Tomcat would now be responsible for building and
> managing
> > >>> the data source) and also allow you to configure your application in
> a
> > >>> more flexible way -- essentially it makes it possible to achieve your
> > >>> goal of decoupling the configuration from the application bundle
> itself.
> > >>
> > > I have a team of developers - but, at this moment, the customer does
> not
> > > want a path that includes code changes.  We may change in the future,
> but I
> > > was investigating a no-code change option.
> > >
> > >
> > >>>> In the new world, I'd need 2 sets of those parameters (basically
> with the
> > >>>> same names for the app to find them).  one pointing to
> dbserver-site1 and
> > >>>> one pointing to dbserver-site2.
> >>>>
> > >>>> Basically I'm looking for ideas that would not involve App code
> changes if
> > >>>> possible.  I can change the XML configs in the conf directory
> without
> > >>>> issue... but for program reasons, at this time, the app code (or the
> > >>>> META-INF/xml files) are not supposed to be touched on considering
> this
> > >>>> adventure.
> > >>>
> > >>> An app code change would be best, but you can also use some well-work
> > >>> hacks to get around that.
> > >>
> > >> We can keep that in mind for the future - but due to other priorities
> from
> > > the customer, code changes for this are not on the table.
> > >
> > >
> > >>> I think your host/site context.xml file ideas are interesting.
> Would I be
> > >>> able to take the context info that I put here out of web.xml and put
> it in
> > >>> the conf/Catalina/localhost/site1app.xml and put another copy in
> > >>> conf/Catalina/localhost/site2app.xml with the different
> > >>> url/username/password?
> > >>>
> > >>> That would be an ideal and simple answer.
> > >>>
> > >>> I can think of two other ways to do this. The first way requires no
> code
> > >>> changes and should continue to work. It essentially uses the same
> > >>> servlet context parameters you are already using, but re-locates
> them to
> > >>> context.xml -- which I didn't actually know you could do until I just
> > >>> re-re-re-re-read the documentation.
> > >>>
> > >>>
> > >>
> https://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_Parameters
> > >> <
> https://tomcat.apache.org/tomcat-9.0-doc/config/context.html#Context_Parameters
> >
> > >>>
> > >>> You can remove these from WEB-INF/web.xml:
> > >>> <context-param>
> > >>>   <param-name>foo</param-name>
> > >>>     <param-value>bar</param-value>
> > >>> </context-param>
> > >>>
> > >>>
> > >>> And put them into META-INF/context.xml under <Context> (which is the
> > >>> document-element for that file) :
> > >>>
> > >>>     <Parameter name="foo" value="bar" override="true|false"/>
> > >>>
> > >>> If you move those definitions and they work, then you can take the
> next
> > >>> step and move the application's META-INF/context.xml file out of the
> > >>> application and into Tomcat's conf/[engine]/[host]/[appname].xml
> > >>>
> > >>> If that works, then enjoy your day. :)
> > >>
> > > I might put them straight in the appname.xml in my sandbox - changing
> > > META-INF/context.xml changes what deploys with the app and that's
> still in
> > > the "not right now" currently.
> >
> > Tomcat does not read both META-INF/context.xml and also
> > conf/[engine]/[host]/[appname].xml and merge them together: the latter
> > takes precedence. So you'll have to merge them yourself. Just copy the
> > existing META-INF/context.xml file -> conf/[engine]/[host]/[appname].xml
> > and modify from there.
> >
> > -chris
>

Thanks Chris & Mark!

I'll take note.  I sandboxed this yesterday afternoon just putting those
database context-params into an appsite1.xml and  appsite2.xml and it
worked.  I'll doublecheck the META-INF\context.xml entries as well to make
sure I didn't lose anything in the test.

Reply via email to