You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Joe Luo (JIRA)" <ji...@apache.org> on 2014/05/23 10:50:02 UTC

[jira] [Comment Edited] (CAMEL-7456) Camel PropertiesComponent ignores custom parser in Blueprint

    [ https://issues.apache.org/jira/browse/CAMEL-7456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14006978#comment-14006978 ] 

Joe Luo edited comment on CAMEL-7456 at 5/23/14 8:48 AM:
---------------------------------------------------------

If I have a custom parser, then I'd expect my custom parser to be used first and then blueprint or default parser afterwards. There are a lot cases that people might want to use combination of them. For instance, in this case, I configured "propertyPrefix" property to use property placeholder $\{container.stage} here:
{code}
<property name="propertyPrefix" value="${container.stage}."/>
{code}
My custom parser basically just tries to look up system property for the value of the property placeholder "container.stage" to decide what environment I am in. Say "dev", "prod" or "test". Depends on the value returned by my custom parser, I can either go to blueprint or just default file property to find relevant value. And I still want to use blueprint in this case.

I understand that it was not the intention to support custom parser with blueprint. But I think it is reasonable use case I presented here and more people are going to use blueprint in future so I believe the custom parser with blueprint issue should be addressed in my opinion.


was (Author: joeluo):
If I have a custom parser, then I'd expect my custom parser to be used first and then blueprint or default parser afterwards. There are a lot cases that people might want to use combination of them. For instance, in this case, I configured "propertyPrefix" property to use property placeholder $\{container.stage} here:
<property name="propertyPrefix" value="${container.stage}."/>

My custom parser basically just tries to look up system property for the value of the property placeholder "container.stage" to decide what environment I am in. Say "dev", "prod" or "test". Depends on the value returned by my custom parser, I can either go to blueprint or just default file property to find relevant value. And I still want to use blueprint in this case.

I understand that it was not the intention to support custom parser with blueprint. But I think it is reasonable use case I presented here and more people are going to use blueprint in future so I believe the custom parser with blueprint issue should be addressed in my opinion.

> Camel PropertiesComponent ignores custom parser in Blueprint
> ------------------------------------------------------------
>
>                 Key: CAMEL-7456
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7456
>             Project: Camel
>          Issue Type: Bug
>          Components: osgi
>    Affects Versions: 2.12.3
>            Reporter: Joe Luo
>
> I have implemented a custom PropertiesParser which allows me to use system property placeholders in propertyPrefix and propertySuffix.
> In my use case the propertyPrefix is defined as "$\{container.stage}.", where container.stage is a jvm option defined at container creation. The value is one of dev, test and prod.
> This works fine in Java DSL world (SCR bundle), but custom parser is ignored in Blueprint. Here is sample of my blueprint xml:
> {code}
>  <cm:property-placeholder id="integration" persistent-id="org.apache.camel.sample.temp" placeholder-prefix="[[" placeholder-suffix="]]">
>     <cm:default-properties>
>         <cm:property name="example" value="this value is the default"/>
>         <cm:property name="dev.example" value="this value is used in development environment"/>
>         <cm:property name="test.example" value="this value is used in test environment"/>
>         <cm:property name="prod.example" value="this value is used in production environment"/>
>     </cm:default-properties>
> </cm:property-placeholder>
> <bean id="parser" class="org.apache.camel.sample.MyCustomPropertiesParser"/>
> <!-- Load properties for current container stage -->
> <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
>     <property name="propertiesParser" ref="parser"/>
>     <property name="propertyPrefix" value="${container.stage}."/>
>     <property name="fallbackToUnaugmentedProperty" value="true"/>
>     <property name="location" value="blueprint:integration,classpath:properties/temp.properties"/></bean>
> <camelContext id="temp" xmlns="http://camel.apache.org/schema/blueprint">
>     <route id="exampleRoute">
>         <from uri="timer:foo?period=5000"/>
>         <transform>
>             <simple>{{example}}</simple>
>         </transform>
>         <to uri="log:something"/>
>     </route>
> </camelContext>
> {code}
> The reason it did not work was because by default, it uses blueprint property resolver (useBlueprintPropertyResolver="true") to bridge PropertiesComponent to blueprint in order to support looking up property placeholders from the Blueprint Property Placeholder Service. Then it always creates a BlueprintPropertiesParser object and set it to PropertiesComponent. 
> The customer Property Parser I created was only set into the BlueprintPropertiesParser object as a delegate Property Parser. Therefore, it was always the method parseUri() from the BlueprintPropertiesParser object got invoked. The same method from your custom parser was ignored. 
> For more detail, please take a look at org.apache.camel.blueprint.CamelContextFactoryBean.initPropertyPlaceholder() function.
> The only workaround is to add the attribute useBlueprintPropertyResolver="false" to <camelContext> element to disable default blueprint property resolver. However, I will have to change PropertiesComponent's "location" property to remove blueprint "blueprint:integration" from the comma separated value list:
> {code}
>  <property name="location" value="classpath:properties/temp.properties"/> 
> {code}
> Because once I set it to false, I will no longer be able to lookup from blueprint property service.



--
This message was sent by Atlassian JIRA
(v6.2#6252)