commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Thorburn <nzi...@gmail.com>
Subject [CONFIGURATION] Configuration Interpolates when Web Application is run directly under Glassfish, but not when debugging under Eclipse
Date Wed, 02 Sep 2009 05:13:41 GMT
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.

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.

Thanks,

- Andrew Thorburn

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message