godeatgod
godeatgod

Reputation: 97

How to specify a relative file location in Tomcat application's context.xml file and specifically in a resource element?

I have the following resource definition (datasource) in my Tomcat 10 web application's context.xml file:

<Resource name="jdbc/postgresql" auth="Container" type="javax.sql.DataSource" username="dba" password="secret" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://address:port/
?sslmode=verify-full&amp;sslrootcert=/usr/local/tomcat/webapps/myApp/META-INF/root.crt" maxTotal="100" maxIdle="30" maxWaitMillis="10000"/>

The sslrootcert parameter in the jdbc url identifies the location of the root certificate file (which I placed in the META-INF directory).

The above context.xml and resource definition work perfectly in my development environment that I control; however, I will be moving the app to a hosted production server where I do not know the directory that tomcat is installed in. So I need a way to dynamically or relatively identify the location of the root.crt file relative to my WAR file.

The following do NOT work, but I'm providing here in case it provides clarity on what I'm trying to achieve:

The documentation says the path must start with a "/" so I don't know if the environment variable is even reading, and catalina.home variable is not a preferred solution as it limits me to this type of web app server.

In short, I'm looking for what gets filled in the blank below to allow me to reference the root.crt file in a relative way to my WAR file:
sslrootcert=_________________/root.crt

Upvotes: 0

Views: 210

Answers (1)

Ironluca
Ironluca

Reputation: 3762

In Postgres Documentation The below is mentioned

The location of the client certificate, the PKCS-8 client key and root certificate can be overridden with the sslcert , sslkey , and sslrootcert settings respectively. These default to /defaultdir/postgresql.crt, /defaultdir/postgresql.pk8, and /defaultdir/root.crt respectively where defaultdir is ${user.home}/.postgresql/ in *nix systems and %appdata%/postgresql/ on windows.

You could try keeping the SSL root certificate in the default path and exclude the 'sslrootcert' parameter from the JDBC URL and check

Upvotes: 1

Related Questions