Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5AA96200C25 for ; Fri, 24 Feb 2017 23:13:22 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 59359160B69; Fri, 24 Feb 2017 22:13:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A3C8E160B62 for ; Fri, 24 Feb 2017 23:13:21 +0100 (CET) Received: (qmail 39574 invoked by uid 500); 24 Feb 2017 22:13:20 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 39563 invoked by uid 99); 24 Feb 2017 22:13:20 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2017 22:13:20 +0000 Received: from Christophers-MacBook-Pro.local (pool-173-66-116-184.washdc.fios.verizon.net [173.66.116.184]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id D82BB1A00A2 for ; Fri, 24 Feb 2017 22:13:19 +0000 (UTC) Subject: Re: Getting application root path before servlet is initialized? To: Tomcat Users List References: From: Christopher Schultz Message-ID: Date: Fri, 24 Feb 2017 17:13:19 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit archived-at: Fri, 24 Feb 2017 22:13:22 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Martin, On 2/24/17 12:37 PM, Martin Knoblauch wrote: > On Fri, Feb 24, 2017 at 6:00 PM, Christopher Schultz < > chris@christopherschultz.net> wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 >> >> Martin, >> >> On 2/21/17 8:31 AM, Martin Knoblauch wrote: >>> Hi, >>> >>> is there a way to find the absolute path of the application >>> root before the servlet is initialized? >>> >>> Alternatively: is there a way to defer the initialization of a >>> datasource until the servlet is initialized? >>> >>> Background: I have extended >>> "org.apache.tomcat.jdbc.pool.DataSourceFactory" to >>> automatically set credentials so that they are not stored in >>> the "Catalina/localhost/XXX.xml" file. Instead they are taken >>> from encrypted values in a file below the application root. >>> Works fine if I know that path at "createDataSource" time. >> >> Where are you configuring your ? In conf/server.xml or >> in your application's META-INF/context.xml file? >> > > conf/Catalina/localhost/XXX.xml Good. If your custom DataSource can accept custom properties, then you can add one with a dynamic path, like this: In your code, you read that path and use it. >>> In order to avoid hard coding that path, I need a programmatic >>> to find that value. Unfortunately the datasource is initialized >>> before the servlet, so "getRealPath()" is not working yet. >> >> getRealPath is a bad idea. Also, your DataSources will be >> fully-configured before any servlets are initialized, so it's too >> late. > > Correct :-( That is the problem I need(ed) to solve. Given enough > assumptions about the deployment rules for this app, I was able to > find a reliable way to deduce the AppRoot. But the fact that the DS > is initialized before the/any servlet is still ugly. You can use system property replacement in your Tomcat deployment descriptor (META-INF/context.xml, or in your case conf/Catalina/localhost/XXX.xml) to locate the file relative to CATALINA_BASE like this: - -chris -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJYsK//AAoJEBzwKT+lPKRYU0QP/30vNxE+FBStms0J8TA0aC6w ZPyA53htgBnMFbKEPt6zmSx3pYtdRE866I3IXiq7c8j9Fcy3c6img9ohVW9cwx+q Id8Gc1MqHNk1dMxSUpQN+YBVTg+N6hEQshocxcIAKJ7vzind1dUdJgnGLowZBb2G OCLbr8BqdhBz97Cw+B2tv+P310ez0RS1ZInbi0cTr7RHkFsUYPFL8Z86668ZYJGA HO5cOEv1+a2W6kIiVEcyDzAo65y6dlp8/Nn/7J00mufT241F/haON7KHWyGXSYKU C19zYFWjhbZWENrTO2gOSPumib12RgUs45mVbOzYKnMDAZxzMQETgtX31hJE9Pxt J++OLvF+OwdFwveBNNNpJOpAcmzmX40RSKp+wez+nLftvI6aKXTXKer8zIiYur9Y nu4cyj4Hjb1tFOFsl2+2jdhFjHb3dFJ/76qylMNgfpsjw1VYHiUlU6QM6G7I2xZd AROO6Nk4uPElPzl4u83pJ0knD7CKIV8oTE7H5/7pXgFU1SmUq+S/QLhN9Nvq2XKi Sykr/lxJWkDIpT1w3mRUhcnREODt4Uzp/0dpuD1i+oSrz8hIcAvZMqgAh8F1nSOQ d8N0TnrJ2w0j63R0mDfoNiRg+2Olxwy0J+xQgNimSC8rOPahu8msatUkXg/JtFDX z4DR8aawD45uJ+tO18Tr =bMSR -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org