Re: [configuration] JXPathException when setting the default expression engine

2014-09-12 Thread Oliver Heger

Hi Nick,

you are right, this is indeed a problem in 1.10. 
DefaultConfigurationBuilder extends XMLConfiguration; therefore, setting 
the default expression engine affects the way keys are resolved.


The preferred way to set the expression engine for the combined 
configuration produced by the builder is to declare the desired engine 
in the definition file that is loaded. There is an example in the user's 
guide [1] in the sub section The header section


In the upcoming version 2.0, this problem should no longer exist. Here 
different mechanisms are used for setting a default expression engine 
and for constructing a combined configuration. I hope that a first alpha 
release of Commons Configuration 2.0 will be available soon.


So, as the problem will be solved in the next version, it probably does 
not make sense to open a Jira ticket.


Oliver

[1] 
http://commons.apache.org/proper/commons-configuration/userguide/howto_configurationbuilder.html#Configuration_definition_file_reference


On 11.09.2014 21:37, Nick Watts wrote:

Hello, I've run into a problem that looks to me like a bug. I thought I'd
get some input on it first though.

Here are two JUnit test cases that both pass with Commons Config 1.10:

import static org.junit.Assert.*;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationBuilder;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.DefaultExpressionEngine;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.jxpath.JXPathException;
import org.junit.Before;

public class Test {

 @Before
 public void before() {
 HierarchicalConfiguration.setDefaultExpressionEngine(new
DefaultExpressionEngine());
 }

 @org.junit.Test
 public void testSetExpressionEngineAfterLoad() throws
ConfigurationException {
 ConfigurationBuilder builder = new
DefaultConfigurationBuilder(configuration_builder.xml);
 ((XMLConfiguration)builder).setBasePath(src/test/resources/);
 Configuration config = builder.getConfiguration();
 HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine());
 assertEquals(mail.test.org, config.getString(mail/host));
 assertEquals(r...@test.org, config.getString(mail/from));
 assertEquals(otheru...@test.org, config.getString(mail/to));
 assertEquals(that...@test.org, config.getString(mail/cc));
 assertEquals(, config.getString(mail/bcc));
 }

 @org.junit.Test(expected=JXPathException.class)
 public void testSetExpressionEngineBeforeLoad() {
 try {
 HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine());
 ConfigurationBuilder builder = new
DefaultConfigurationBuilder(configuration_builder.xml);
 ((XMLConfiguration)builder).setBasePath(src/test/resources/);
 builder.getConfiguration();
 } catch (ConfigurationException e) {
 e.printStackTrace();
 }
 }
}


The configuration_builder.xml file:

?xml version=1.0 encoding=ISO-8859-1?
configuration
 override
 xml fileName=dev.config.xml config-name=env-config /
 xml fileName=config.xml config-name=default-config /
 /override
/configuration


the config.xml file:

?xml version=1.0 encoding=UTF-8?
config
 mail
 hostmail.test.org/host
 fromr...@test.org/from
 tonwa...@test.org/to
 cc/
 bcc/
 /mail
/config

the dev.config.xml file:

?xml version=1.0 encoding=UTF-8?
config
 mail
 tootheru...@test.org/to
 ccthat...@test.org/cc
 /mail
  /config



The possible bug is that the call to
HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine()) must come after the call to
builder.getConfiguration(). If it precedes builder.getConfiguration() then
you get this stack trace:

org.apache.commons.jxpath.JXPathException: Invalid XPath:
'[@systemProperties]'. Syntax error at the beginning of the expression
 at org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
 at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpression(JXPathContextReferenceImpl.java:218)
 at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iteratePointers(JXPathContextReferenceImpl.java:529)
 at
org.apache.commons.jxpath.JXPathContext.selectNodes(JXPathContext.java:654)
 at
org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.query(XPathExpressionEngine.java:183)
 at
org.apache.commons.configuration.HierarchicalConfiguration.fetchNodeList(HierarchicalConfiguration.java:958)
 at

Re: [configuration] JXPathException when setting the default expression engine

2014-09-12 Thread Nick Watts
Thanks for the pointer to the documentation. I missed that section somehow.
Also, I appreciate the explanation of how this problem is being resolved in
the 2.0 release. I configured the XPathExpressionEngine in the config
definition file and that solved my problem.

On Fri, Sep 12, 2014 at 9:46 AM, Oliver Heger oliver.he...@oliver-heger.de
wrote:

 Hi Nick,

 you are right, this is indeed a problem in 1.10.
 DefaultConfigurationBuilder extends XMLConfiguration; therefore, setting
 the default expression engine affects the way keys are resolved.

 The preferred way to set the expression engine for the combined
 configuration produced by the builder is to declare the desired engine in
 the definition file that is loaded. There is an example in the user's guide
 [1] in the sub section The header section

 In the upcoming version 2.0, this problem should no longer exist. Here
 different mechanisms are used for setting a default expression engine and
 for constructing a combined configuration. I hope that a first alpha
 release of Commons Configuration 2.0 will be available soon.

 So, as the problem will be solved in the next version, it probably does
 not make sense to open a Jira ticket.

 Oliver

 [1] http://commons.apache.org/proper/commons-configuration/
 userguide/howto_configurationbuilder.html#Configuration_definition_file_
 reference


 On 11.09.2014 21:37, Nick Watts wrote:

 Hello, I've run into a problem that looks to me like a bug. I thought I'd
 get some input on it first though.

 Here are two JUnit test cases that both pass with Commons Config 1.10:

 import static org.junit.Assert.*;

 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationBuilder;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.XMLConfiguration;
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
 import org.apache.commons.jxpath.JXPathException;
 import org.junit.Before;

 public class Test {

  @Before
  public void before() {
  HierarchicalConfiguration.setDefaultExpressionEngine(new
 DefaultExpressionEngine());
  }

  @org.junit.Test
  public void testSetExpressionEngineAfterLoad() throws
 ConfigurationException {
  ConfigurationBuilder builder = new
 DefaultConfigurationBuilder(configuration_builder.xml);
  ((XMLConfiguration)builder).setBasePath(src/test/resources/);
  Configuration config = builder.getConfiguration();
  HierarchicalConfiguration.setDefaultExpressionEngine(new
 XPathExpressionEngine());
  assertEquals(mail.test.org, config.getString(mail/host));
  assertEquals(r...@test.org, config.getString(mail/from));
  assertEquals(otheru...@test.org, config.getString(mail/to));
  assertEquals(that...@test.org, config.getString(mail/cc));
  assertEquals(, config.getString(mail/bcc));
  }

  @org.junit.Test(expected=JXPathException.class)
  public void testSetExpressionEngineBeforeLoad() {
  try {
  HierarchicalConfiguration.setDefaultExpressionEngine(new
 XPathExpressionEngine());
  ConfigurationBuilder builder = new
 DefaultConfigurationBuilder(configuration_builder.xml);
  ((XMLConfiguration)builder).setBasePath(src/test/
 resources/);
  builder.getConfiguration();
  } catch (ConfigurationException e) {
  e.printStackTrace();
  }
  }
 }


 The configuration_builder.xml file:

 ?xml version=1.0 encoding=ISO-8859-1?
 configuration
  override
  xml fileName=dev.config.xml config-name=env-config /
  xml fileName=config.xml config-name=default-config /
  /override
 /configuration


 the config.xml file:

 ?xml version=1.0 encoding=UTF-8?
 config
  mail
  hostmail.test.org/host
  fromr...@test.org/from
  tonwa...@test.org/to
  cc/
  bcc/
  /mail
 /config

 the dev.config.xml file:

 ?xml version=1.0 encoding=UTF-8?
 config
  mail
  tootheru...@test.org/to
  ccthat...@test.org/cc
  /mail
   /config



 The possible bug is that the call to
 HierarchicalConfiguration.setDefaultExpressionEngine(new
 XPathExpressionEngine()) must come after the call to
 builder.getConfiguration(). If it precedes builder.getConfiguration() then
 you get this stack trace:

 org.apache.commons.jxpath.JXPathException: Invalid XPath:
 '[@systemProperties]'. Syntax error at the beginning of the expression
  at org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.
 java:60)
  at
 org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.
 compileExpression(JXPathContextReferenceImpl.java:218)
  at
 

[configuration] JXPathException when setting the default expression engine

2014-09-11 Thread Nick Watts
Hello, I've run into a problem that looks to me like a bug. I thought I'd
get some input on it first though.

Here are two JUnit test cases that both pass with Commons Config 1.10:

import static org.junit.Assert.*;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationBuilder;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.DefaultExpressionEngine;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.jxpath.JXPathException;
import org.junit.Before;

public class Test {

@Before
public void before() {
HierarchicalConfiguration.setDefaultExpressionEngine(new
DefaultExpressionEngine());
}

@org.junit.Test
public void testSetExpressionEngineAfterLoad() throws
ConfigurationException {
ConfigurationBuilder builder = new
DefaultConfigurationBuilder(configuration_builder.xml);
((XMLConfiguration)builder).setBasePath(src/test/resources/);
Configuration config = builder.getConfiguration();
HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine());
assertEquals(mail.test.org, config.getString(mail/host));
assertEquals(r...@test.org, config.getString(mail/from));
assertEquals(otheru...@test.org, config.getString(mail/to));
assertEquals(that...@test.org, config.getString(mail/cc));
assertEquals(, config.getString(mail/bcc));
}

@org.junit.Test(expected=JXPathException.class)
public void testSetExpressionEngineBeforeLoad() {
try {
HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine());
ConfigurationBuilder builder = new
DefaultConfigurationBuilder(configuration_builder.xml);
((XMLConfiguration)builder).setBasePath(src/test/resources/);
builder.getConfiguration();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
}


The configuration_builder.xml file:

?xml version=1.0 encoding=ISO-8859-1?
configuration
override
xml fileName=dev.config.xml config-name=env-config /
xml fileName=config.xml config-name=default-config /
/override
/configuration


the config.xml file:

?xml version=1.0 encoding=UTF-8?
config
mail
hostmail.test.org/host
fromr...@test.org/from
tonwa...@test.org/to
cc/
bcc/
/mail
/config

the dev.config.xml file:

?xml version=1.0 encoding=UTF-8?
config
mail
tootheru...@test.org/to
ccthat...@test.org/cc
/mail
 /config



The possible bug is that the call to
HierarchicalConfiguration.setDefaultExpressionEngine(new
XPathExpressionEngine()) must come after the call to
builder.getConfiguration(). If it precedes builder.getConfiguration() then
you get this stack trace:

org.apache.commons.jxpath.JXPathException: Invalid XPath:
'[@systemProperties]'. Syntax error at the beginning of the expression
at org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpression(JXPathContextReferenceImpl.java:218)
at
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iteratePointers(JXPathContextReferenceImpl.java:529)
at
org.apache.commons.jxpath.JXPathContext.selectNodes(JXPathContext.java:654)
at
org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.query(XPathExpressionEngine.java:183)
at
org.apache.commons.configuration.HierarchicalConfiguration.fetchNodeList(HierarchicalConfiguration.java:958)
at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.fetchNodeList(AbstractHierarchicalFileConfiguration.java:439)
at
org.apache.commons.configuration.HierarchicalConfiguration.getProperty(HierarchicalConfiguration.java:344)
at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.getProperty(AbstractHierarchicalFileConfiguration.java:392)
at
org.apache.commons.configuration.AbstractConfiguration.resolveContainerStore(AbstractConfiguration.java:1171)
at
org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1038)
at
org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1021)
at
org.apache.commons.configuration.DefaultConfigurationBuilder.initSystemProperties(DefaultConfigurationBuilder.java:793)
at
org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:612)
at
org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:587)
at