...
The simple language uses ${body
} placeholders for complex expressions where the expression contains constant literals.
Deprecated: The ${}
placeholders can be omitted if the expression starts with the token, or if the token is only itself.
...
Div |
---|
class | confluenceTableSmall |
---|
|
Variable | Type | Description |
---|
camelId
| String
| Camel 2.10: the CamelContext name. | camelContext.OGNL
| Object
| Camel 2.11: the CamelContext invoked using a Camel OGNL expression. | collate(group)
| List
| Camel 2.17: The collate function iterates the message body and groups the data into sub lists of specified size. This can be used with the Splitter EIP to split a message body and group/batch the split sub messages into a group of N sub lists. This method works similar to the collate method in Groovy. | exchange
| Exchange
| Camel 2.16: the Exchange. | exchange.OGNL
| Object
| Camel 2.16: the Exchange invoked using a Camel OGNL expression. | 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 . | bodyAs(type).OGNL
| Object
| Camel 2.18: Converts the body to the given type determined by its classname and then invoke methods using a Camel OGNL expression. 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 . | mandatoryBodyAs(type).OGNL
| Object
| Camel 2.18: Converts the body to the given type determined by its classname and then invoke methods using a Camel OGNL expression. | out.body
| Object
| The output body. | header.foo
| Object
| Refer to the input foo header. | header[foo]
| Object
| Camel 2.9.2: refer to the input foo header. | headers.foo
| Object
| Refer to the input foo header. | headers[foo]
| Object
| Camel 2.9.2: refer to the input foo header. | in.header.foo
| Object
| Refer to the input foo header. | in.header[foo ]
| Object
| Camel 2.9.2: refer to the input foo header. | in.headers.foo
| Object
| Refer to the input foo header. | in.headers[foo ]
| Object
| Camel 2.9.2: refer to the input foo header. | header.foo[bar]
| Object
| Camel 2.3: regard input foo header as a map and perform lookup on the map with bar as key. | 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. | 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. | 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.header[foo ]
| Object
| Camel 2.9.2: refer to the out header foo . | out.headers.foo
| Object
| Refer to the out header foo . | out.headers[foo ]
| Object
| Camel 2.9.2: 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
| Deprecated: refer to the foo property on the exchange. | exchangeProperty.foo
| Object
| Camel 2.15: refer to the foo property on the exchange. | property[foo ]
| Object
| Deprecated: refer to the foo property on the exchange. | exchangeProperty[foo ]
| Object
| Camel 2.15: refer to the foo property on the exchange. | property.foo .OGNL
| Object
| Deprecated: refer to the foo property on the exchange and invoke its value using a Camel OGNL expression. | exchangeProperty.foo .OGNL
| Object
| Camel 2.15: 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 foo . | sysenv.foo
| String
| Camel 2.3: refer to the system environment property foo . | 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
| 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. Result 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
| Date formatting using the java.text.SimpleDateFormat 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
| Invoking a bean expression using the Bean language. Specifying a method name you must use dot as separator. We also support the ?method=methodname syntax that is used by the Bean component. | properties:locations:key
| String
| Deprecated: (use properties-location instead) Camel 2.3: Lookup a property with the given key. The locations option is optional. See more at Using PropertyPlaceholder. | properties-location:locations:key
| String
| Camel 2.14.1: Lookup a property with the given key. The locations option is optional. See more at Using PropertyPlaceholder. | properties:key:default
| String
| Camel 2.14.1: Lookup a property with the given key. If the key does not exists or has no value, then an optional default value can be specified. | routeId
| String
| Camel 2.11: Returns the Id of the current route the Exchange is being routed. | 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. | type:name.field
| Object
| Camel 2.11: To refer to a type or field by its FQN name. To refer to a field you can append .FIELD_NAME . For example you can refer to the constant field from Exchange as: org.apache.camel.Exchange.FILE_NAME | . | null
| null
| Camel 2.12.3: represents a null . | random(value)
| Integer
| Camel 2.16.0: returns a random Integer between 0 (included) and value (excluded) | random(min,max)
| Integer
| Camel 2.16.0: returns a random Integer between min (included) and max (excluded) | collate(group)
| List
| Camel 2.17: The collate function iterates the message body and groups the data into sub lists of specified size. This can be used with the Splitter EIP to split a message body and group/batch the split sub messages into a group of N sub lists. This method works similar to the collate method in Groovy. | Integer
| Camel 2.16.0: returns a random Integer between min (included) and max (excluded) | skip(number)
| Iterator
| Camel 2.19: The skip function iterates the message body and skips the first number of items. This can be used with the Splitter EIP to split a message body and skip the first N number of items. | messageHistory
| String
| Camel 2.17: The message history of the current exchange how it has been routed. This is similar to the route stack-trace message history the error handler logs in case of an un-handled unhandled exception. | messageHistory(false)
| String
| Camel 2.17: As messageHistory but without the exchange details (only includes the route strack-trace). This can be used if you do not want to log sensitive data from the message itself. |
|
...
Info |
---|
Camel's OGNL support is for invoking methods only. You cannot access fields. From Camel 2.11.1 onwards : we added special support for accessing the length field of Java arrays. |
...
You can also use the null safe operator (?.
) to avoid a NPE if for example the body does not have an address
...
Suppose there was no value with the key foo
then you can use the null safe operator to avoid the a NPE as shown:
Code Block |
---|
|
simple("${body[foo]?.name}")
|
You can also access List
types, for example to get lines from the address you can do:
...
Code Block |
---|
|
simple("${body.address.lines[last]}")
|
And to get the 2nd last you can subtract a number, so we can penultimate line use subtraction. In this case use last-1
to indicate for this:
Code Block |
---|
|
simple("${body.address.lines[last-1]}")
|
And the 3rd third last is of course:
Code Block |
---|
|
simple("${body.address.lines[last-2]}")
|
And you can call the the size
method on the list with
Code Block |
---|
|
simple("${body.address.lines.size}")
|
From Camel 2.11.1 we added support for the length field for Java arrays as well, eg. Example:
Code Block |
---|
|
String[] lines = new String[]{"foo", "bar", "cat"};
exchange.getIn().setBody(lines);
simple("There are ${body.length} lines")
|
...
Operator | Description |
---|
==
| Equals. |
=~
| Camel 2.16: equals ignore case (will ignore case when comparing String values). |
>
| 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. If you want to include an empty value, then it must be defined using double comma, eg ',,bronze,silver,gold', which is a set of four values with an empty value and then the three medals. |
not in
| For matching if not in a set of values, each element must be separated by comma. If you want to include an empty value, then it must be defined using double comma, eg . Example: ',,bronze,silver,gold' , which is a set of four values with an empty value and then the three medals. |
is
| For matching if the left hand side type is an instanceof the value. |
not is
| For matching if the left hand side type is not an instanceof the value. |
range
| For matching if the left hand side is within a range of values defined as numbers: from..to . From Camel 2.9: the range values must be enclosed in single quotes. |
not range
| For matching if the left hand side is not within a range of values defined as numbers: from..to . From Camel 2.9: the range values must be enclosed in single quotes. |
starts with
| Camel 2.17.1, 2.18: For testing if the left hand side string starts with the right hand string. |
ends with
| Camel 2.17.1, 2.18: For testing if the left hand side string ends with the right hand string. |
...
Operator | Description |
---|
++
| Camel 2.9: To increment a number by one. The left hand side must be a function, otherwise parsed as literal. |
--
| Camel 2.9: To decrement a number by one. The left hand side must be a function, otherwise parsed as literal. |
\
| Camel 2.9.3 to 2.10.x To escape a value, e.g., \$ , to indicate a $ sign. Special: Use \n for new line, \t for tab, and \r for carriage return. Note: Escaping is not supported using the File Language. Note: from Camel 2.11, the escape character is no longer supported. It has been replaced with the following three escape sequences. |
\n
| Camel 2.11: To use newline character. |
\t
| Camel 2.11: To use tab character. |
\r
| Camel 2.11: To use carriage return character. |
\ }
| Camel 2.18: To use the } character as text. |
...
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 is used to group two expressions. |
||
| Camel 2.9: The logical or operator is used to group two expressions. |
...
And an example with contains, testing if the title contains the word Camel:
Code Block |
---|
|
simple("${in.header.title} contains 'Camel'")
|
...
The Simple language can be used for the predicate test above in the Message Filter pattern, where we test if the in message has a foo
header (a header with the key foo
exists). If the expression evaluates to to true
then the message is routed to the mock:fooOrders
endpoint, otherwise it is lost in the deep blue sea .
...
Code Block |
---|
|
from("direct:hello")
.transform().simple("Hello ${in.header.user} how are you?")
.to("mock:reply");
|
Notice that we must use use ${}
placeholders in the expression now to allow Camel to parse it correctly.
...
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.
...