Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleUsing and,or operators

In Camel 2.4 and older the and or or can only be used once in a simple language expression.

From Camel 2.5: you can use these operators multiple times.

...

Notice we use .. in the range without spaces. It is based on the same syntax as Groovy.

From Camel 2.9 onwards : the range value must be in single quotes:

...

Code Block
java
java
from("direct:order")
  .transform().simple("OrderId: ${bean:orderIdGenerator}")
  .to("mock:reply");

Where orderIdGenerator is the id of the bean registered in the Registry. If using Spring then it is the Spring bean id.

If we want to declare which method to invoke on the order id generator bean we must prepend .method name such as below where we invoke the generateId method.

Code Block
java
java
from("direct:order")
  .transform().simple("OrderId: ${bean:orderIdGenerator.generateId}")
  .to("mock:reply");

...

Code Block
java
java
from("direct:order")
  .transform().simple("OrderId: ${bean:orderIdGenerator?method=generateId}")
  .to("mock:reply");

And from From Camel 2.3: you can also convert the body to a given type, for example to ensure that it is a String you can do:

...

In the code above we lookup the header with name type and regard it as a java.util.Map and we then lookup with the key gold and return the value. If the header is not convertible to Map an exception is thrown. If the header with name type does not exist null is returned.

From Camel 2.9: you can nest functions, such as shown below:

...

Referring to Constants or Enums

Available as of Available from Camel 2.11

Suppose you have an enum for customers:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/Customer.java}
And in a Content Based Router we can use the Simple language to refer to this enum, to check the message which enum it matches.
Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/CBRSimpleTypeTest.java}

Using New Lines or Tabs in XML DSLs

Available as of Available from Camel 2.9.3

From Camel 2.9.3, : it is easier to specify new lines or tabs in XML DSLs as you can escape the value now

...

Leading and Trailing Whitespace Handling

Available as of Available from Camel 2.10.0

From Camel 2.10.0, : the trim attribute of the expression can be used to control whether the leading and trailing whitespace characters are removed or preserved. The default of trim=true removes all whitespace characters.

...

Setting the Result Type

Available as of from Camel 2.8

You can now provide a result type to the Simple expression, which means the result of the evaluation will be converted to the desired type. This is most usable to define types such as boolean's, integer's, etc.

...

Changing Function Start and End Tokens

Available as of Available from Camel 2.9.1

You can configure the function start and end tokens - ${} using the setters changeFunctionStartToken and changeFunctionEndToken on SimpleLanguage, using Java code. From Spring XML you can define a <bean> tag with the new changed tokens in the properties as shown below:

...

Loading Script from External Resource

Available as of Available from Camel 2.11

You can externalize the script and have Camel load it from a resource such as: classpath:, file:, or http:. This is done using the following syntax: resource:scheme:location, e.g., to refer to a file on the classpath you can do:

...

Setting Spring beans to Exchange properties

Available as of Available from Camel 2.6

You can set a spring bean into an exchange property as shown below:

...