2010-02-08

Property placeholder galore in Apache Camel 2.3

We are close to two year anniversary of SPR-4466 with no sign of willingness from Springsource to open up Spring Framework allowing 3rd party frameworks, such as Apache Camel, to leverage their property placeholder feature to the fullest.

The RFE was filled 2 years ago by James Strachan, who is well known in the OS community, but still Spring has just kept postponing the ticket. At first it was scheduled for Spring 3.0, then in december 2009 it was moved to Spring 3.1. I bet its just a sign that the RFE did not fill out a gap that the other spring products needed.

Well we can't wait for Spring forever so this last weekend the Camel team developed a new property placeholder feature which will be part of Camel 2.3. Looking back we should have done that for the Camel 2.0 release but we was waiting for it to provided in Spring 3.0.

Well its not bad either because the property placeholders provided with Camel is implemented in camel-core which means you can use it without using Spring at all :) Its also build in the Camel simple language and the endpoints is resolved at runtime which means you can also use it for ProducerTemplate etc. Basically they work everywhere where you can enter a endpoint URI. So we got them all over, its mayhem, its galore :).

I have already written documented at the Apache site how to use it so I will just be lazy on this blog and refer to its documentation.

Okay if you use Spring XML we have created a nice XML tag for it as shown below:

  <propertyPlaceholder id="properties"

        location="com/mycompany/myprop.properties"/>
And the below is part from a little route in Java DSL using placeholders. Notice the #{ } syntax. Yes it works from Spring XML as well.
// properties

cool.showid=true
cool.result=result
cool.start=direct:start

// route
from("#{cool.start}")
    .to("log:#{cool.start}?showBodyType=false&showExchangeId=#{cool.showid}")
    .to("mock:#{cool.result}");


3 comments:

Christian Schneider said...

Hi Claus,

that sounds great. At last we can specify the directories for our file endpoints directly. Great feature.

Greetings

Christian

Vikas said...

Hi,

I am a new bie in Camel town.
I trying to use Camel's new Property Placeholder feature.

But, when i added camel-core2.3.0.jar in my class path since then i am getting following error:
Error executing script RunApp: (class: org/apache/camel/model/ProcessorType, method: loop signature: ()Lorg/apache/camel/builder/ExpressionClause;) Incompatible argument to function
java.lang.VerifyError: (class: org/apache/camel/model/ProcessorType, method: loop signature: ()Lorg/apache/camel/builder/ExpressionClause;) Incompatible argument to function
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredFields(Class.java:1743)

Error executing script RunApp: (class: org/apache/camel/model/ProcessorType, method: loop signature: ()Lorg/apache/camel/builder/ExpressionClause;) Incompatible argument to function


If i remove camel-core.jar then everything runs smooth as it was earlier.

My lib directory contains following jars:
activemq-all-5.3.1
activemq-pool-5.3.1
activemq-ra-3.2
mysql-connector-java-5.0.7-bin
spring-jms-2.5.6

Please guide me.


Regards,

-Vikas Gupta

Claus Ibsen said...

Hi Vikas

Please use the Camel user forum for support and help with Camel
http://camel.apache.org/support.html

Looking at the stacktrace it looks like you got mixed versions of Camel in there. Make sure all Camel jars is the same version.

ProcessorType is actually from Camel 1.x so you may have an old Camel version in the mix also.