Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 11744 invoked from network); 3 Sep 2009 03:03:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Sep 2009 03:03:26 -0000 Received: (qmail 42826 invoked by uid 500); 3 Sep 2009 03:03:25 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 42648 invoked by uid 500); 3 Sep 2009 03:03:24 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 42638 invoked by uid 99); 3 Sep 2009 03:03:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 03:03:24 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of nzipsi@gmail.com designates 74.125.92.148 as permitted sender) Received: from [74.125.92.148] (HELO qw-out-1920.google.com) (74.125.92.148) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Sep 2009 03:03:14 +0000 Received: by qw-out-1920.google.com with SMTP id 14so462550qwa.60 for ; Wed, 02 Sep 2009 20:02:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=EeF7WNzCCyoXB2P1c1cvd/Knd7Z6dLby9bQUiBb/x6s=; b=TwhaOSWUwnO3xPtocpB4TmWcKtQKsi2J+47EEAzcBnIMtoNcUp1fO4dbgHN+3EjF+J ybZXBe0WKv7Tuq1SKkElNYN7ydwIiGntb8k0DKY7bUX454vYOh6f0dybKzqHCHewJQQx bojAWSU7Zd3rkkauAxvPDM9L4ScDaB2I2OnIQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=KLM2YBHNpvr1WlSAxLsjsrCde0IWwG83jvehctcDrkYEJJ8jYVHSKFZ/EIDbedmuO9 Qwm7PmcjrJxMXqKnkuSWfHtIZNNVtp3FxD8U7/oXUJWEYce/kd0oPp7xeOzF7jylTmyl fiRKMs+hH75PXsQ98EwmTEXECw7ExR+En3Tuw= MIME-Version: 1.0 Received: by 10.229.119.131 with SMTP id z3mr2649226qcq.37.1251946970820; Wed, 02 Sep 2009 20:02:50 -0700 (PDT) In-Reply-To: References: <4A9EA5D8.5020104@oliver-heger.de> Date: Thu, 3 Sep 2009 15:02:50 +1200 Message-ID: Subject: Re: [CONFIGURATION] Configuration Interpolates when Web Application is run directly under Glassfish, but not when debugging under Eclipse From: Andrew Thorburn To: Commons Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Yeah, you know what? I was wrong. I had just loaded up a second copy of my application into Glassfish without realising it. Go me? - Andrew On Thu, Sep 3, 2009 at 1:18 PM, Andrew Thorburn wrote: > Thanks Oliver. > > I have no idea why, but it's suddenly started working. I messed about > with a few things, including dumping the combined configuration (but > nothing was interpolated), and removing breakpoints which I had set on > several different copies of my Configurator class. > > Absolutely bizarre. All I can do now is hope that it doesn't recur... > > Thanks, > > - Andrew Thorburn > > On Thu, Sep 3, 2009 at 5:05 AM, Oliver > Heger wrote: >> Hi Andrew, >> >> what you describe seems really complicated. I am not sure whether I full= y >> understand the problem, but I hope at least to give you some hints. Comm= ents >> inline... >> >> Andrew Thorburn schrieb: >>> >>> This is something that doesn't make an awful lot of sense to me: >>> >>> I've got a web application that uses CommonsConfiguration to configure >>> the logging (first it loads a configuration file as =C2=A0base, then lo= ads >>> a new configuration from the database), and for some reason it will >>> not interpolate the various parameters when I try and debug it under >>> Eclipse (using the Glassfish WTP plugin). It just doesn't happen. >>> >>> I'm using Java 1.5, Commons Configuration 1.6, Commons Lang 2.2, >>> Eclipse 3.5 and Glassfish 2.1. >>> >>> I know that it works when I run it under Glassfish directly as I can >>> see the log file being created in the right directory and such, and I >>> can also see it printing out the parameters with everything >>> successfully interpolated and expanded. >>> >>> I'm not sure exactly why it's not doing anything, but there we go. >>> >>> It doesn't even interpolate System parameters, including ones that >>> I've set my self. >>> >>> I can't provide the code which is actually causing the problem, and >>> I'm not entirely sure how to replicate it. The best I can do is show >>> code which behaves in a similar fashion: >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0/** >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 * @param args >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 */ >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0public static void main(String[] args) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0{ >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.setProper= ty("ProcessID", "pid"); >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.print= ln("java.io.tmpdir [" + >>> System.getProperty("java.io.tmpdir") + "]"); >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Configuration c = =3D new BaseConfiguration(); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("p= rocess.default.logfile_directory", >>> "${java.io.tmpdir}"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.default.filename_prefix", "PREFIX"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.default.filename_suffix", "log"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.default.filename", >>> >>> "${logger.default.filename_prefix}${ProcessID}.${logger.default.filenam= e_suffix}"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.log4j.rootLogger", "ERROR, APP_ROD, >>> APP_EMAIL"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.log4j.appender.APP_ROD", >>> "org.apache.log4j.DailyRollingFileAppender"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.log4j.appender.APP_ROD.File", >>> >>> "${process.default.logfile_directory}/${ProcessID}/${logger.default.fil= ename}"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c.setProperty("l= ogger.log4j.appender.APP_ROD.DatePattern", >>> "'.'yyyyMMdd"); >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CompositeConfigu= ration cc =3D new CompositeConfiguration(); >>> >>> >>> =C2=A0cc.addConfiguration((AbstractConfiguration)c.subset("logger")); >>> >>> >>> =C2=A0System.out.println(cc.getString("log4j.appender.APP_ROD.File")); >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printProperties(= ConfigurationConverter.getProperties(cc)); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printProperties(= ConfigurationConverter.getProperties(c)); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>> >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0private static void printProperties(Properti= es props) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0{ >>> >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for(Entry ent : props.entrySet()) >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0System.out.println("[" + ent.getKey() + "] [" + >>> ent.getValue() + "]"); >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >>> >>> And the output from the above: >>> >>> java.io.tmpdir [/tmp] >>> >>> ${process.default.logfile_directory}/${ProcessID}/${logger.default.file= name} >>> >>> [log4j.rootLogger] [ERROR,APP_ROD,APP_EMAIL] >>> [log4j.appender.APP_ROD.DatePattern] ['.'yyyyMMdd] >>> [log4j.appender.APP_ROD] [org.apache.log4j.DailyRollingFileAppender] >>> [log4j.appender.APP_ROD.File] >>> >>> [${process.default.logfile_directory}/${ProcessID}/${logger.default.fil= ename}] >>> [default.filename_prefix] [PREFIX] >>> [default.filename_suffix] [log] >>> [default.filename] >>> >>> [${logger.default.filename_prefix}${ProcessID}.${logger.default.filenam= e_suffix}] >>> >>> [process.default.logfile_directory] [${java.io.tmpdir}] >>> [logger.default.filename_prefix] [PREFIX] >>> [logger.default.filename_suffix] [log] >>> [logger.log4j.appender.APP_ROD.File] >>> [${java.io.tmpdir}/${ProcessID}/PREFIX${ProcessID}.log] >>> [logger.default.filename] [PREFIX${ProcessID}.log] >>> [logger.log4j.appender.APP_ROD.DatePattern] ['.'yyyyMMdd] >>> [logger.log4j.appender.APP_ROD] >>> [org.apache.log4j.DailyRollingFileAppender] >>> [logger.log4j.rootLogger] [ERROR,APP_ROD,APP_EMAIL] >>> >>> Which seems a little... odd... since it left >>> process.default.logfile_directory as ${java.io.tmpdir} despite the >>> property definitely being set. >> >> If you work with a plain configuration like BaseConfiguration, system >> properties are not interpolated out of the box. You need to prefix the >> variable with the "sys:" prefix. There is an example in the user guide: >> http://commons.apache.org/configuration/userguide/howto_basicfeatures.ht= ml#Variable_Interpolation >> >> However, when using a CombinedConfiguration that includes a >> SystemConfiguration the situation is different as the SystemConfiguratio= n >> should make all its properties available. >> >>> >>> This differs from my actual problem in that *no* interpolation is >>> performed when converting to a Properties Object. None at all. Also, >>> the properties are loaded from an XML file, and then from a >>> CombinedConfiguration constructed from the XMLFile, System Properties >>> and a Database Table. >>> >>> I *know* that it works normally, as a temporary log winds up /tmp. >>> >>> Having said the above, if I stop Glassfish in Eclipse and then start >>> it from the command line, I get the same issue (of no interpolation). >>> >>> There's a variety of issues that could be the problem here. It could >>> be something funny about the Glassfish plugin. It could be something >>> to do with how I've got the web project set up - prior to this, it was >>> built via Ant and deployed directly. It could be something to do with >>> Eclipse's compiler/classpath/whatever settings. >>> >>> However, I really don't have a clue where to begin here - has anyone >>> seen this sort of problem before and been able to find a solution? Any >>> hints would be most welcome, as I'm not even certain that this is >>> actually a commons-configuration problem. It's just that >>> commons-configuration is the visible symptom. >>> >>> Apologies if the above seems disjointed or unclear. >> >> I think we can assume that the interpolation features of Commons >> Configuration work as expected - otherwise we would see lots of bug repo= rts. >> So if interpolation does not work in your case, the combined configurati= on >> probably does not contain the properties you expect. >> >> To debug the problem you can dump the complete content of the >> CombinedConfiguration. An easy way to achieve this is to create an >> XMLConfiguration from the CombinedConfiguration and store it somewhere, = e.g. >> if cc is the CombinedConfiguration: >> >> XMLConfiguration xmlConf =3D new XMLConfiguration(cc); >> xmlConf.save(new File("dump.xml")); >> >> Maybe, depending on the environment you start the application system >> properties are not propagated as expected? >> >> HTH >> Oliver >> >>> >>> Thanks, >>> >>> - Andrew Thorburn >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> For additional commands, e-mail: user-help@commons.apache.org >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org