Jon,
On 12/6/23 11:34, Mcalexander, Jon J. wrote:
I was hoping to find some use cases with examples.
I recently set up a local environment using the
ServiceBindingPropertySource. The idea is that there are only a few
options for configuring Tomcat-provided database connections for an
application:
1. Hard-code the connection string, credentials, etc. into your
application's META-INF/context.xml file
2. Use replaceable parameters in your META-INF/context.xml for such
things, and use your build-process to merge them (this is what we
currently do at $work)
3. Configure the connection in conf/server.xml and use <ResourceLink> in
META-INF/context.xml (or with <resource-link> in WEB-INF/web.xml?)
4. Something else
I'm interested in how to deploy copies of an application on-the-fly and
since k8s does that kind of thing and, well, the
ServiceBindingPropertySource was built for this kind of thing, I decided
that #4 above could be "use ServiceBindingPropertySource".
export
CATALINA_BASE=-Dorg.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.ServiceBindingPropertySource
(among other things, of course)
export SERVICE_BINDING_ROOT=/path/to/your/stuff
find /path/to/your/stuff
/myapp
/myapp/jdbc-url
/myapp/jdbc-username
/myapp/jdbc-password
cat /path/to/your/stuff/myapp/*
jdbc:yadda...
scott
tiger
(note that these files actually have no trailing \n characters. I added
them for readability in this post)
In META-INF/context.xml, I have this:
<Resource name="jdbc/diagnosis"
...
url="${chomp:myapp.jdbc-chadis-url}"
username="${chomp:myapp.jdbc-username:-jon}"
password="${chomp:myapp.jdbc-password:-mcalexander}"
driverClassName="${chomp:myapp.jdbc-driver-class-name:-com.mysql.jdbc.Driver}"
...
A couple of things, here:
1. I used "chomp:" which allows me to have files which have trailing
newlines which will be removed by the ServiceBindingPropertySource
because figuring out how to get vi to stop adding a trailing \n to a
text file is a pain in the neck. Forget the fact that my files don't
actually have those trailing \ns in them. I did it "just in case".
2. I have supplied "default values". If the file specified in the
${filename} doesn't exist, you get the default. For example, I have no
file named myapp/jdbc-driver, and so the default MySQL driver class name
specified in the configuration will be used.
I had a few issues getting started. First, the documentation is sorely
inadequate. I had to read code and finagle a few things to get it to
work in the first place. I also added the "chomp:" thing to the
ServiceBindingPropertySource because the trailing newline thing annoyed
me so much. Second... *environment variable*? /Seriously?/ Well, that's
how servicebinding.io defines things. I think it would make sense to use
a system property possibly as an alternative.
Works as it says on the tin, once you get it going.
I mentioned that we use our build-process to, well, build our
configuration files. That's been great, but it means we need or
tool-chain installed in production and we can't just e.g. drop a WAR
someplace and have it deploy. We use that process for building the
Tomcat installation as well, including conf/server.xml.
We use replaceable parameters for all of the following in server.xml:
- Shutdown port
- Connector port
- Non-TLS connector port
- JVM-route
We could set these things as system properties during JVM launch and
leave the parameterized stuff in the file we actually deploy. One fewer
step in the deployment process. But we've had this system in place for
so long, there's no particular reason to switch from build-replacement
to deploy-replacement, so we haven't done it.
Moving to something like k8s means we can't really stick with what we've
got. Plus, k8s can act as a configuration-deployment system and it can
do that by .... writing directories full of configuration files like the
one used by (wait for it) ServiceBindingPropertySource.
So that's the what and why with my example(s).
Hope that helps,
-chris
-----Original Message-----
From: Christopher Schultz <ch...@christopherschultz.net>
Sent: Wednesday, December 6, 2023 9:20 AM
To: users@tomcat.apache.org
Subject: Re: Looking for examples...
Jon,
On 12/5/23 19:02, Mcalexander, Jon J. wrote:
I am trying to find decent examples for Property Replacements in
Catalina.properties. I have an instance that is giving me the
following Warning and it bugs me:
Dec 05, 2023 5:48:51 PM org.apache.tomcat.util.digester.Digester
replaceSystemProperties
WARNING: System property [common.loader] failed to update and
remains
["${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}
/lib","${catalina.home}/lib/*.jar"]
Is anything specifically not working, or are you just trying to get this warning
to go away?
I've looked at the docs, and all I'm really finding is the following:
So... which property source are you actually using? Or are you using the
default?
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org