commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Thorburn <nzi...@gmail.com>
Subject Re: [CONFIGURATION] Configuration Interpolates when Web Application is run directly under Glassfish, but not when debugging under Eclipse
Date Thu, 03 Sep 2009 01:18:50 GMT
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<oliver.heger@oliver-heger.de> wrote:
> Hi Andrew,
>
> what you describe seems really complicated. I am not sure whether I fully
> understand the problem, but I hope at least to give you some hints. Comments
> 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  base, then loads
>> 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:
>>
>>        /**
>>         * @param args
>>         */
>>        public static void main(String[] args)
>>        {
>>                System.setProperty("ProcessID", "pid");
>>
>>                System.out.println("java.io.tmpdir [" +
>> System.getProperty("java.io.tmpdir") + "]");
>>
>>                Configuration c = new BaseConfiguration();
>>                c.setProperty("process.default.logfile_directory",
>> "${java.io.tmpdir}");
>>                c.setProperty("logger.default.filename_prefix", "PREFIX");
>>                c.setProperty("logger.default.filename_suffix", "log");
>>                c.setProperty("logger.default.filename",
>>
>> "${logger.default.filename_prefix}${ProcessID}.${logger.default.filename_suffix}");
>>                c.setProperty("logger.log4j.rootLogger", "ERROR, APP_ROD,
>> APP_EMAIL");
>>                c.setProperty("logger.log4j.appender.APP_ROD",
>> "org.apache.log4j.DailyRollingFileAppender");
>>                c.setProperty("logger.log4j.appender.APP_ROD.File",
>>
>> "${process.default.logfile_directory}/${ProcessID}/${logger.default.filename}");
>>                c.setProperty("logger.log4j.appender.APP_ROD.DatePattern",
>> "'.'yyyyMMdd");
>>
>>                CompositeConfiguration cc = new CompositeConfiguration();
>>
>>
>>  cc.addConfiguration((AbstractConfiguration)c.subset("logger"));
>>
>>
>>  System.out.println(cc.getString("log4j.appender.APP_ROD.File"));
>>
>>                printProperties(ConfigurationConverter.getProperties(cc));
>>                printProperties(ConfigurationConverter.getProperties(c));
>>        }
>>
>>
>>        private static void printProperties(Properties props)
>>        {
>>
>>                for(Entry<Object, Object> ent : props.entrySet())
>>                {
>>                        System.out.println("[" + ent.getKey() + "] ["
+
>> ent.getValue() + "]");
>>                }
>>        }
>>
>> And the output from the above:
>>
>> java.io.tmpdir [/tmp]
>>
>> ${process.default.logfile_directory}/${ProcessID}/${logger.default.filename}
>>
>> [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.filename}]
>> [default.filename_prefix] [PREFIX]
>> [default.filename_suffix] [log]
>> [default.filename]
>>
>> [${logger.default.filename_prefix}${ProcessID}.${logger.default.filename_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.html#Variable_Interpolation
>
> However, when using a CombinedConfiguration that includes a
> SystemConfiguration the situation is different as the SystemConfiguration
> 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 reports.
> So if interpolation does not work in your case, the combined configuration
> 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 = 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


Mime
View raw message