Versions Compared

Key

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

...

Tip
titleConfiguring result type

From Camel 2.8 onwards you can configure the result type of the Simple expression. For example to set the type as a java.lang.Boolean or a java.lang.Integer etc.

Info
titleFile language is now merged with Simple language

From Camel 2.2 onwards, the File Language is now merged with Simple language which means you can use all the file syntax directly within the simple language.

Info
titleSimple Language Changes in Camel 2.9 onwards

The Simple language have been improved from Camel 2.9 onwards to use a better syntax parser, which can do index precise error messages, so you know exactly what is wrong and where the problem is. For example if you have made a typo in one of the operators, then previously the parser would not be able to detect this, and cause the evaluation to be true. There is a few changes in the syntax which are no longer backwards compatible. When using Simple language as a Predicate then the literal text must be enclosed in either single or double quotes. For example: "${body} == 'Camel'". Notice how we have single quotes around the literal. Well frankly the syntax is now more close to Java language, so its not hard to understand. The old style of using "body" and "header.foo" to refer to the message body and header is @deprecated, and its encouraged to always use ${ } tokens for the built-in functions.

To get the body of the in message: "body", or "in.body" or "${body}".

...

You can have multiple tokens in the same expression: "Hello ${in.header.name} this is ${in.header.me} speaking".
However you can not nest tokens (i.e. having another ${ } placeholder in an existing, is not allowed).

...

titleFile language is now merged with Simple language

...

, is not allowed).

Variables

Variable

Type

Description

exchangeId

String

Camel 2.3: the exchange id

id

String

the input message id

body

Object

the input body

in.body

Object

the input body

body.OGNL

Object

Camel 2.3: the input body invoked using a Camel OGNL expression.

in.body.OGNL

Object

Camel 2.3: the input body invoked using a Camel OGNL expression.

bodyAs(type)

Type

Camel 2.3: Converts the body to the given type determined by its classname. The converted body can be null.

mandatoryBodyAs(type)

Type

Camel 2.5: Converts the body to the given type determined by its classname, and expects the body to be not null.

out.body

Object

the output body

header.foo

Object

refer to the input foo header

headers.foo

Object

refer to the input foo header

in.header.foo

Object

refer to the input foo header

in.headers.foo

Object

refer to the input foo header

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4a94a33f0d11a1e0-8523279b-45eb4707-8b239a99-5a17824e315f9ae30d05c91e"><ac:plain-text-body><![CDATA[

header.foo[bar]

Object

Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="21697a1cc4c6e202-3d45d8ab-436b4da3-b7e39178-61078d7ea81c6bdc9cf8c7b1"><ac:plain-text-body><![CDATA[

in.header.foo[bar]

Object

Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="98d1bb9f94557d73-ecc67a95-4d45446e-bb729fc0-a51de261cfc370e830971403"><ac:plain-text-body><![CDATA[

in.headers.foo[bar]

Object

Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key

]]></ac:plain-text-body></ac:structured-macro>

header.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

in.header.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

in.headers.foo.OGNL

Object

Camel 2.3: refer to the input foo header and invoke its value using a Camel OGNL expression.

out.header.foo

Object

refer to the out header foo

out.headers.foo

Object

refer to the out header foo

headerAs(key,type)

Type

Camel 2.5: Converts the header to the given type determined by its classname

headers

Map

Camel 2.9: refer to the input headers

in.headers

Map

Camel 2.9: refer to the input headers

property.foo

Object

refer to the foo property on the exchange

property.foo.OGNL

Object

Camel 2.8: refer to the foo property on the exchange and invoke its value using a Camel OGNL expression.

sys.foo

String

refer to the system property

sysenv.foo

String

Camel 2.3: refer to the system environment

exception

Object

Camel 2.4: Refer to the exception object on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

exception.OGNL

Object

Camel 2.4: Refer to the exchange exception invoked using a Camel OGNL expression object

exception.message

String

Camel 2.0. Refer to the exception.message on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

exception.stacktrace

String

Camel 2.6. Refer to the exception.stracktrace on the exchange, is null if no exception set on exchange. Will fallback and grab caught exceptions (Exchange.EXCEPTION_CAUGHT) if the Exchange has any.

date:command:pattern

String

Camel 1.5. Date formatting using the java.text.SimpleDataFormat patterns. Supported commands are: now for current timestamp, in.header.xxx or header.xxx to use the Date object in the IN header with the key xxx. out.header.xxx to use the Date object in the OUT header with the key xxx.

bean:bean expression

Object

Camel 1.5. Invoking a bean expression using the Bean language. Specifying a method name you must use dot as separator. In Camel 2.0 we also support the ?method=methodname syntax that is used by the Bean component.

properties:locations:key

String

Camel 2.3: Lookup a property with the given key. The locations option is optional. See more at Using PropertyPlaceholder.

threadName

String

Camel 2.3: Returns the name of the current thread. Can be used for logging purpose.

ref:xxx

Object

Camel 2.6: To lookup a bean from the Registry with the given id.

...

Operator

Description

==

equals

>

greater than

>=

greater than or equals

<

less than

<=

less than or equals

!=

not equals

contains

For testing if contains in a string based value

not contains

For testing if not contains in a string based value

regex

For matching against a given regular expression pattern defined as a String value

not regex

For not matching against a given regular expression pattern defined as a String value

in

For matching if in a set of values, each element must be separated by comma.

not in

For matching if not in a set of values, each element must be separated by comma.

is

For matching if the left hand side type is an instanceof the value.

not is not is

For matching if the left hand side type is not an instanceof the value.

range

For matching if the left hand side type is not an instanceof the value. is within a range of values defined as numbers: from..to

not range

For matching if the left hand side is not within a range of values defined as numbers: from..to

not range

For matching if the left hand side is not within a range of values defined as numbers: from..to

And the following operators can be used to group expressions:

defined as numbers: from..to

And the following unary operators can be used:

Operator

Description

++

Camel 2.9: To increment a number by one.

--

Camel 2.9: To decrement a number by one.

And the following logical operators can be used to group expressions:

Operator

Description

and

deprecated use && instead. The logical and operator is used to group two expressions.

or

deprecated use || instead. The logical or operator is used to group two expressions.

&&

Camel 2.9: The logical and operator

Operator

Description

and

and is used to group two expressions.

or

||

Camel 2.9: The logical or operator or is used to group two expressions.

Info
titleUsing and,or operators

In Camel 2.4 or older the and or or can only be used once in a simple language expression. From Camel 2.5 onwards you can use these operators multiple times.

...

Code Block
${leftValue} OP rightValue or ${leftValue} OP rightValue 

Some examples:

Code Block

simple("${in.header.foo} == 'foo'")

// ' ' can be omitted
simple("${in.header.foo} == 'foo'")

// here Camel will type convert '100' into the type of in.header.bar and if its an Integer '100' will also be converter to an Integer
simple("${in.header.bar} == '100'")

simple("${in.header.bar} == 100")

// 100 will be converter to the type of in.header.bar so we can do > comparison
simple("${in.header.bar} > 100")

...

Code Block
simple("${in.header.type} is 'String'")

Ranges are also supported. The range interval requires numbers and both from and end are inclusive. For instance to test whether a value is between 100 and 199:

...

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

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

Code Block

simple("${in.header.number} range '100..199'")
Tip
titleCan be used in Spring XML

As the Spring XML does not have all the power as the Java DSL with all its various builder methods, you have to resort to use some other languages
for testing with simple operators. Now you can do this with the simple language. In the sample below we want to test if the header is a widget order:

Code Block
xml
xml
    <from uri="seda:orders">
       <filter>
           <simple>${in.header.type} == 'widget'</simple>
           <to uri="bean:orderService?method=handleWidget"/>
       </filter>
    </from>

...

If you have two expressions you can combine them with the and or or operator.

Tip
titleCamel 2.9 onwards

Use && or || from Camel 2.9 onwards.

For instance:

Code Block
simple("${in.header.title} contains 'Camel' and ${in.header.type'} == 'gold'")

...

Code Block
java
java
    from("seda:orders")
        .filter().simple("${in.header.foo}").to("seda:fooOrders");

You can also use the simple language for simple text concatenations such as:

...