You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by java kurious <ja...@gmail.com> on 2014/03/04 17:45:10 UTC

Using Camel properties

Hi All,

I am using camel properties component to read properties file:

<bean id="properties"
class="org.apache.camel.component.properties.PropertiesComponent">
        <property name="location"

value="classpath:META-INF/spring/code-to-value.properties"/>
</bean>



Everything works fine, except when I use a key that is not defined in the
properties file.

<camel:setHeader headerName="property-value-asdf">
           <simple>${properties:asdf}</simple>
</camel:setHeader>



In that case I get an error similar to following :

org.apache.camel.RuntimeCamelException:
java.lang.IllegalArgumentException: *Property
with key [asdf] not found in properties from text: {{asdf}}*
    at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1344)
    at
org.apache.camel.builder.ExpressionBuilder$76.evaluate(ExpressionBuilder.java:1733)
    at
org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
    at
org.apache.camel.builder.SimpleBuilder.evaluate(SimpleBuilder.java:83)
    at
org.apache.camel.builder.ProcessorBuilder$4.process(ProcessorBuilder.java:103)
    at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
    at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
    at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)

What would be the right way to check if the key exists before using it ?

Thanks

Re: Using Camel properties

Posted by Claus Ibsen <cl...@gmail.com>.
No I dont think so. You are welcome to check the JIRA

On Mon, Jun 9, 2014 at 7:47 PM, rmprescott <ra...@gmail.com> wrote:
> Was a ticket created?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5752049.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Using Camel properties

Posted by rmprescott <ra...@gmail.com>.
Was a ticket created?




--
View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5752049.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Camel properties

Posted by javakurious <ja...@gmail.com>.
Thanks ! 



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748872.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Camel properties

Posted by Claus Ibsen <cl...@gmail.com>.
Ah though we had implemented that. Kinda recall that being talked
about in the past / JIRA ticket.

Fell free to log a ticket so we can add such an option.

On Sat, Mar 15, 2014 at 11:21 PM, javakurious <ja...@gmail.com> wrote:
> Hi Claus, thanks for the response. Sorry, I didn't see your response, as I am
> not getting email notification for any replies.
>
> Regarding the option to ignore missing property key, only related option I
> see is /ignoreMissingLocation/ . That does not seem to be the same as ignore
> missing property key.
>
> Is that the one that you are talking about ?
>
> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748847.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io

Re: Using Camel properties

Posted by javakurious <ja...@gmail.com>.
Hi Claus, thanks for the response. Sorry, I didn't see your response, as I am
not getting email notification for any replies. 

Regarding the option to ignore missing property key, only related option I
see is /ignoreMissingLocation/ . That does not seem to be the same as ignore
missing property key. 

Is that the one that you are talking about ?

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748847.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Camel properties

Posted by Claus Ibsen <cl...@gmail.com>.
There is an option you can turn on the properties component to tell it
to ignore unknown property keys.


On Wed, Mar 5, 2014 at 8:01 PM, swwyatt <st...@sungard.com> wrote:
> You could subclass
> org.apache.camel.component.properties.DefaultPropertiesParser and set it as
> the propertiesParser in your PropertiesComponent. Your subclass could handle
> the missing property and just return null.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748353.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io

Re: Using Camel properties

Posted by swwyatt <st...@sungard.com>.
You could subclass
org.apache.camel.component.properties.DefaultPropertiesParser and set it as
the propertiesParser in your PropertiesComponent. Your subclass could handle
the missing property and just return null.



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748353.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Camel properties

Posted by javakurious <ja...@gmail.com>.
Thanks for the response. 

The way I am using properties file is I am using an incoming request's
parameter as a key to look up the properties file to find the correct route
to use. But for an invalid request parameter, I want to check for its
existence in the properties file before using it. 

So, it's not a design time check but a runtime check. 

One possible solution I could think of was to create a separate bean using
Java Properties class and use that to check for it. But, it seemed natural
from Camel PropertiesComponent to expect a null or an empty string  if the
key didn't exist. 

I also tried catching the java.lang.IllegalArgumentException in that route,
but that did not seem to work. But I will try that again. 

Thanks. 



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Camel-properties-tp5748299p5748339.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Camel properties

Posted by Willem Jiang <wi...@gmail.com>.
You may need to use some test editor to help you search the key from the resource file.
We don’t have validator tool in camel for design time check.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com(http://willemjiang.blogspot.com/) (English)
http://jnn.iteye.com(http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On March 5, 2014 at 12:45:52 AM, java kurious (javakurious@gmail.com) wrote:
>  
> Hi All,
>  
> I am using camel properties component to read properties file:  
>  
> > class="org.apache.camel.component.properties.PropertiesComponent">  
> >  
> value="classpath:META-INF/spring/code-to-value.properties"/>  
>  
>  
>  
>  
> Everything works fine, except when I use a key that is not defined  
> in the
> properties file.
>  
>  
> ${properties:asdf}
>  
>  
>  
>  
> In that case I get an error similar to following :
>  
> org.apache.camel.RuntimeCamelException:
> java.lang.IllegalArgumentException: *Property
> with key [asdf] not found in properties from text: {{asdf}}*  
> at
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1344)  
> at
> org.apache.camel.builder.ExpressionBuilder$76.evaluate(ExpressionBuilder.java:1733)  
> at
> org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)  
> at
> org.apache.camel.builder.SimpleBuilder.evaluate(SimpleBuilder.java:83)  
> at
> org.apache.camel.builder.ProcessorBuilder$4.process(ProcessorBuilder.java:103)  
> at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)  
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)  
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)  
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)  
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)  
>  
> What would be the right way to check if the key exists before using  
> it ?
>  
> Thanks
>