Simple language expressions and predicates combine plain text strings, variables, and property placeholders in a straight forward manner. The most basic expression will contain a single variable. More complex expressions will use variables to fill in portions of text strings.
Simple language expressions can also use OGNL notation as discussed in OGNL expressions.
Expressions using the Simple language are typically a combination of variables and text strings that are used to create messages.
Table 10, “Simple language variable” shows all of the variables supported by the simple language.
Table 10. Simple language variable
Variable | Type | Description |
---|---|---|
exchangeId | String | The exchange's ID value. |
id | String | The In message ID value. |
body
| Object |
The In message body. Supports OGNL expressions. |
in.body | Object | The In message body. Supports OGNL expressions. |
out.body
| Object |
The Out message body. |
bodyAs( | Type | The In message body, converted to the specified type. All
types, Type , must be specified using their
fully-qualified Java name, except for the types: byte[] ,
String , Integer , and Long . The converted
body can be null. |
mandatoryBodyAs( | Type | The In message body, converted to the specified type. All
types, Type , must be specified using their
fully-qualified Java name, except for the types: byte[] ,
String , Integer , and Long . The converted
body is expected to be non-null. |
header.
HeaderName | Object |
The In message's |
headers.
HeaderName | Object | The In message's HeaderName
header. |
in.header.
HeaderName | Object | The In message's HeaderName
header. Supports OGNL expressions. |
in.headers.
HeaderName | Object | The In message's HeaderName
header. Supports OGNL expressions. |
out.header.
HeaderName
| Object |
The Out message's |
out.headers.
HeaderName | Object | The Out message's HeaderName
header. |
headerAs( | Type | The Key header, converted to the specified type. All
types, Type , must be specified using their
fully-qualified Java name, except for the types: byte[] ,
String , Integer , and Long . The converted
value can be null. |
property.
PropertyName
| Object |
The |
sys. SysPropertyName | String | The SysPropertyName Java system property. |
sysenv. SysEnvVar | String | The SysEnvVar system environment variable. |
exception | String | Either the exception object from Exchange.getException() or, if
this value is null, the caught exception from the
Exchange.EXCEPTION_CAUGHT property; otherwise null.
Supports OGNL expressions. |
exception.message | String | The exception message on the exchange or null , if no exception is
set. |
date: command : pattern | String | A date formatted using a java.text.SimpleDateFormat pattern. The following commands are supported:
now , for the current date and time;
header. HeaderName , or
in.header. HeaderName to use a java.util.Data object in the HeaderName header
from the In message;
out.header. HeaderName to use a java.util.Data object in the HeaderName header
from the Out message; |
bean: beanRef | Object | Invokes a method on the referenced bean. To specify a method name, you can
either append a dot, . , followed by the method name; or you can use the
?method= methodName syntax. |
properties: | String | The value of the Key property placeholder. |
properties: | String | The value of the Key property placeholder, where the
location of the properties file is given by Location . |
threadName | String | The name of the current thread. |
You can use the simple language to define string expressions, based on the variables
provided. For example, you can use a variable of the form,
in.header.
, to obtain the value of the
HeaderName
HeaderName
header, as follows:
<language language="simple">in.header.foo</language>
You can embed simple variables in a string expression, but in this case you must
enclose the variables in ${ }
(when you reference a variable on its own,
the enclosing braces are optional)—for example:
<language language="simple"> Received a message from ${in.header.user} on $(date:in.header.date:yyyyMMdd}. </language>
Sometimes—for example, if you have enabled Spring property placeholders or OSGi
blueprint property placeholders—you might find that the
${
syntax clashes with another property
placeholder syntax. In this case, you can disambiguate the placeholder using the
alternative syntax, Expression
}$simple{
, for the
simple expression. For example:Expression
}
<simple>Hello $simple{in.header.name}, how are you?</simple>
As well as providing variables that access all of the different parts of an exchange, the simple language also provides special variables for formatting dates:
date:command
:
pattern
For example, you can use the date variables as follows:
<language language="simple">Todays date is ${date:now:yyyyMMdd}</language>