You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Martin Ritchie <ri...@apache.org> on 2009/09/14 14:30:05 UTC

[CONFIGURATION] Help with optional XML file in override section of configuration builder.

Hi,

I have been reading the Configuration Builder docs
(http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html)
and have been trying to get the configuration below to take my
optional configuration.
However, both the test.config property and the resulting file must
exist even though I have marked the config as optional. Can someone
with more understanding of commons configuartion take a look at the
config below and point out what I've done wrong?

Regards
Martin

<configuration>
   <system/>
   <override>
       <xml fileName="${test.config}" config-optional="true"/>
       <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
       <xml fileName="${TEST_HOME}/etc/config.xml"/>
   </override>
</configuration>

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Martin Ritchie <ri...@apache.org>.
2009/9/16 Oliver Heger <ol...@oliver-heger.de>:
> Ralph Goers schrieb:
>>
>> On Sep 16, 2009, at 4:37 AM, Martin Ritchie wrote:
>>
>>>
>>> Oliver,
>>> Thanks for the pointer to use DefaultConfigurationBuilder.
>>>
>>> Whilst this now does not need to have the test.config property defined
>>> or the file existing it does behave differently to the older
>>> ConfigurationFactory.
>>>
>>> With the configuration as shown in the pastie
>>> (http://pastie.org/617143) the ConfigurationFactory builds a single
>>> configuration tree where later elements are overwritten by newer
>>> values.
>>> So given the configuration values shown here: http://pastie.org/618625
>>> The value of tests.store.class in config.xml (MemoryMessageStore) is
>>> overwritten with (SlowMessageStore) from the test.config. The
>>> additional values in the test.config are also propgated in to the
>>> final configuraiton.
>>>
>>> When I changed to use the DefaultConfigurationBuilder the entire
>>> virtualhosts section was overwritten as a result the other virtualhost
>>> sections in config.xml were lost.
>>>
>>> Is there a way I can get the behaviour as seen with the
>>> ConfigurationFactory but have the file parsing/loading of the
>>> DefaultConfigurationBuilder?
>>>
>> What you are experiencing is probably a result of the NodeCombiner being
>> used. In trunk you will find a "MergeCombiner" that may behave the way you
>> want it to. If you build trunk you should look at the updated documentation
>> as it provides some documentation on how the 3 combiners work and what
>> results they will produce in various situations.
>>
>> Ralph
>>
>
> The problem may also be related to the handling of list nodes. [1] contains
> a discussion about NodeCombiners used when constructing a combined
> configuration (which is done under the hood by DefaultConfigurationBuilder).
> It also mentions possible problems when dealing with list structures.
>
> In the description of the configuration definition file for
> DefaultConfigurationBuilder [2] it is explained how list nodes can be
> specified.
>
> Oliver
>
>
> [1]
> http://commons.apache.org/configuration/userguide/howto_combinedconfiguration.html#Node%20combiners
>
> [2]
> http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html#Enhancements_of_the_configuration_definition_file
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org

Thanks for your suggestions Ralph and Oliver. I'll take a look at what
we are doing.

Cheers

Martin


-- 
Martin Ritchie

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Oliver Heger <ol...@oliver-heger.de>.
Ralph Goers schrieb:
> 
> On Sep 16, 2009, at 4:37 AM, Martin Ritchie wrote:
> 
>>
>> Oliver,
>> Thanks for the pointer to use DefaultConfigurationBuilder.
>>
>> Whilst this now does not need to have the test.config property defined
>> or the file existing it does behave differently to the older
>> ConfigurationFactory.
>>
>> With the configuration as shown in the pastie
>> (http://pastie.org/617143) the ConfigurationFactory builds a single
>> configuration tree where later elements are overwritten by newer
>> values.
>> So given the configuration values shown here: http://pastie.org/618625
>> The value of tests.store.class in config.xml (MemoryMessageStore) is
>> overwritten with (SlowMessageStore) from the test.config. The
>> additional values in the test.config are also propgated in to the
>> final configuraiton.
>>
>> When I changed to use the DefaultConfigurationBuilder the entire
>> virtualhosts section was overwritten as a result the other virtualhost
>> sections in config.xml were lost.
>>
>> Is there a way I can get the behaviour as seen with the
>> ConfigurationFactory but have the file parsing/loading of the
>> DefaultConfigurationBuilder?
>>
> What you are experiencing is probably a result of the NodeCombiner being 
> used. In trunk you will find a "MergeCombiner" that may behave the way 
> you want it to. If you build trunk you should look at the updated 
> documentation as it provides some documentation on how the 3 combiners 
> work and what results they will produce in various situations.
> 
> Ralph
> 

The problem may also be related to the handling of list nodes. [1] 
contains a discussion about NodeCombiners used when constructing a 
combined configuration (which is done under the hood by 
DefaultConfigurationBuilder). It also mentions possible problems when 
dealing with list structures.

In the description of the configuration definition file for 
DefaultConfigurationBuilder [2] it is explained how list nodes can be 
specified.

Oliver


[1] 
http://commons.apache.org/configuration/userguide/howto_combinedconfiguration.html#Node%20combiners

[2] 
http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html#Enhancements_of_the_configuration_definition_file

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Ralph Goers <ra...@dslextreme.com>.
On Sep 16, 2009, at 4:37 AM, Martin Ritchie wrote:

>
> Oliver,
> Thanks for the pointer to use DefaultConfigurationBuilder.
>
> Whilst this now does not need to have the test.config property defined
> or the file existing it does behave differently to the older
> ConfigurationFactory.
>
> With the configuration as shown in the pastie
> (http://pastie.org/617143) the ConfigurationFactory builds a single
> configuration tree where later elements are overwritten by newer
> values.
> So given the configuration values shown here: http://pastie.org/618625
> The value of tests.store.class in config.xml (MemoryMessageStore) is
> overwritten with (SlowMessageStore) from the test.config. The
> additional values in the test.config are also propgated in to the
> final configuraiton.
>
> When I changed to use the DefaultConfigurationBuilder the entire
> virtualhosts section was overwritten as a result the other virtualhost
> sections in config.xml were lost.
>
> Is there a way I can get the behaviour as seen with the
> ConfigurationFactory but have the file parsing/loading of the
> DefaultConfigurationBuilder?
>
What you are experiencing is probably a result of the NodeCombiner  
being used. In trunk you will find a "MergeCombiner" that may behave  
the way you want it to. If you build trunk you should look at the  
updated documentation as it provides some documentation on how the 3  
combiners work and what results they will produce in various situations.

Ralph


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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Martin Ritchie <ri...@apache.org>.
2009/9/15 Oliver Heger <ol...@oliver-heger.de>:
> Martin Ritchie schrieb:
>>
>> 2009/9/14 Oliver Heger <ol...@oliver-heger.de>:
>>>
>>> Martin Ritchie schrieb:
>>>>
>>>> Hi,
>>>>
>>>> I have been reading the Configuration Builder docs
>>>>
>>>>
>>>> (http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html)
>>>> and have been trying to get the configuration below to take my
>>>> optional configuration.
>>>> However, both the test.config property and the resulting file must
>>>> exist even though I have marked the config as optional. Can someone
>>>> with more understanding of commons configuartion take a look at the
>>>> config below and point out what I've done wrong?
>>>>
>>>> Regards
>>>> Martin
>>>>
>>>> <configuration>
>>>>  <system/>
>>>>  <override>
>>>>      <xml fileName="${test.config}" config-optional="true"/>
>>>>      <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
>>>>      <xml fileName="${TEST_HOME}/etc/config.xml"/>
>>>>  </override>
>>>> </configuration>
>>>>
>>> Maybe you can provide a short code fragment demonstrating how you load
>>> this
>>> configuration. What exactly happens, do you get an exception?
>>>
>>> Per default, the configuration builder logs an exception if it cannot
>>> create
>>> a configuration marked as optional. But this should not have any further
>>> consequences.
>>>
>>> Oliver
>>
>> Hi Oliver,
>>
>> I've put the code and errors up here:
>> http://pastie.org/617143
>>
>> Perhaps I'm misunderstanding quite how the Configuration works. I
>> would have expected that an optional value would be skipped if it
>> cannot resolve the variables in the name or the file does not exist.
>>
>> If the default behaviour is to create the optional configuration then
>> I can understand my first exception as I have not defined variable ;
>> test.config. However I can't understand the second exception occurs
>> because the file does not exist and so the default behaviour of
>> creating the file should proceed.
>>
>> Thanks again for your help
>>
>> Martin
>>
>
> Whether the variable for the file name exists or not is not checked, the
> configuration always tries to load the file.
>
> The second exception is probably caused by your usage of
> ConfigurationFactory. Try DefaultConfigurationBuilder instead. Its API is
> very similar to the one of ConfigurationFactory, but it is more powerful and
> thus it is recommended to use this class. IIRC ConfigurationFactory does not
> understand the "config-optional" attribute - it only knows the "optional"
> attribute.
>
> Oliver
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org

Oliver,
Thanks for the pointer to use DefaultConfigurationBuilder.

Whilst this now does not need to have the test.config property defined
or the file existing it does behave differently to the older
ConfigurationFactory.

With the configuration as shown in the pastie
(http://pastie.org/617143) the ConfigurationFactory builds a single
configuration tree where later elements are overwritten by newer
values.
So given the configuration values shown here: http://pastie.org/618625
The value of tests.store.class in config.xml (MemoryMessageStore) is
overwritten with (SlowMessageStore) from the test.config. The
additional values in the test.config are also propgated in to the
final configuraiton.

When I changed to use the DefaultConfigurationBuilder the entire
virtualhosts section was overwritten as a result the other virtualhost
sections in config.xml were lost.

Is there a way I can get the behaviour as seen with the
ConfigurationFactory but have the file parsing/loading of the
DefaultConfigurationBuilder?

Regards

Martion
-- 
Martin Ritchie

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Oliver Heger <ol...@oliver-heger.de>.
Martin Ritchie schrieb:
> 2009/9/14 Oliver Heger <ol...@oliver-heger.de>:
>> Martin Ritchie schrieb:
>>> Hi,
>>>
>>> I have been reading the Configuration Builder docs
>>>
>>> (http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html)
>>> and have been trying to get the configuration below to take my
>>> optional configuration.
>>> However, both the test.config property and the resulting file must
>>> exist even though I have marked the config as optional. Can someone
>>> with more understanding of commons configuartion take a look at the
>>> config below and point out what I've done wrong?
>>>
>>> Regards
>>> Martin
>>>
>>> <configuration>
>>>   <system/>
>>>   <override>
>>>       <xml fileName="${test.config}" config-optional="true"/>
>>>       <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
>>>       <xml fileName="${TEST_HOME}/etc/config.xml"/>
>>>   </override>
>>> </configuration>
>>>
>> Maybe you can provide a short code fragment demonstrating how you load this
>> configuration. What exactly happens, do you get an exception?
>>
>> Per default, the configuration builder logs an exception if it cannot create
>> a configuration marked as optional. But this should not have any further
>> consequences.
>>
>> Oliver
> 
> Hi Oliver,
> 
> I've put the code and errors up here:
> http://pastie.org/617143
> 
> Perhaps I'm misunderstanding quite how the Configuration works. I
> would have expected that an optional value would be skipped if it
> cannot resolve the variables in the name or the file does not exist.
> 
> If the default behaviour is to create the optional configuration then
> I can understand my first exception as I have not defined variable ;
> test.config. However I can't understand the second exception occurs
> because the file does not exist and so the default behaviour of
> creating the file should proceed.
> 
> Thanks again for your help
> 
> Martin
> 

Whether the variable for the file name exists or not is not checked, the 
configuration always tries to load the file.

The second exception is probably caused by your usage of 
ConfigurationFactory. Try DefaultConfigurationBuilder instead. Its API 
is very similar to the one of ConfigurationFactory, but it is more 
powerful and thus it is recommended to use this class. IIRC 
ConfigurationFactory does not understand the "config-optional" attribute 
- it only knows the "optional" attribute.

Oliver

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Martin Ritchie <ri...@apache.org>.
2009/9/14 Oliver Heger <ol...@oliver-heger.de>:
> Martin Ritchie schrieb:
>>
>> Hi,
>>
>> I have been reading the Configuration Builder docs
>>
>> (http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html)
>> and have been trying to get the configuration below to take my
>> optional configuration.
>> However, both the test.config property and the resulting file must
>> exist even though I have marked the config as optional. Can someone
>> with more understanding of commons configuartion take a look at the
>> config below and point out what I've done wrong?
>>
>> Regards
>> Martin
>>
>> <configuration>
>>   <system/>
>>   <override>
>>       <xml fileName="${test.config}" config-optional="true"/>
>>       <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
>>       <xml fileName="${TEST_HOME}/etc/config.xml"/>
>>   </override>
>> </configuration>
>>
>
> Maybe you can provide a short code fragment demonstrating how you load this
> configuration. What exactly happens, do you get an exception?
>
> Per default, the configuration builder logs an exception if it cannot create
> a configuration marked as optional. But this should not have any further
> consequences.
>
> Oliver

Hi Oliver,

I've put the code and errors up here:
http://pastie.org/617143

Perhaps I'm misunderstanding quite how the Configuration works. I
would have expected that an optional value would be skipped if it
cannot resolve the variables in the name or the file does not exist.

If the default behaviour is to create the optional configuration then
I can understand my first exception as I have not defined variable ;
test.config. However I can't understand the second exception occurs
because the file does not exist and so the default behaviour of
creating the file should proceed.

Thanks again for your help

Martin

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



-- 
Martin Ritchie

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


Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder.

Posted by Oliver Heger <ol...@oliver-heger.de>.
Martin Ritchie schrieb:
> Hi,
> 
> I have been reading the Configuration Builder docs
> (http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html)
> and have been trying to get the configuration below to take my
> optional configuration.
> However, both the test.config property and the resulting file must
> exist even though I have marked the config as optional. Can someone
> with more understanding of commons configuartion take a look at the
> config below and point out what I've done wrong?
> 
> Regards
> Martin
> 
> <configuration>
>    <system/>
>    <override>
>        <xml fileName="${test.config}" config-optional="true"/>
>        <xml fileName="${TEST_HOME}/etc/config-systests-settings.xml"/>
>        <xml fileName="${TEST_HOME}/etc/config.xml"/>
>    </override>
> </configuration>
> 

Maybe you can provide a short code fragment demonstrating how you load 
this configuration. What exactly happens, do you get an exception?

Per default, the configuration builder logs an exception if it cannot 
create a configuration marked as optional. But this should not have any 
further consequences.

Oliver

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