Basic syntax

Overview

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.

Variables

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

VariableTypeDescription
exchangeIdStringThe exchange's ID value.
idStringThe In message ID value.
body Object

The In message body. Supports OGNL expressions.

in.bodyObjectThe In message body. Supports OGNL expressions.
out.body Object

The Out message body.

bodyAs(Type)TypeThe 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)TypeThe 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. HeaderNameObject

The In message's HeaderName header. Supports OGNL expressions.

headers. HeaderNameObjectThe In message's HeaderName header.
in.header. HeaderNameObjectThe In message's HeaderName header. Supports OGNL expressions.
in.headers. HeaderNameObjectThe In message's HeaderName header. Supports OGNL expressions.
out.header. HeaderName Object

The Out message's HeaderName header.

out.headers. HeaderNameObjectThe Out message's HeaderName header.
headerAs(Key,Type)TypeThe 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 PropertyName property on the exchange.

sys.SysPropertyNameStringThe SysPropertyName Java system property.
sysenv.SysEnvVarStringThe SysEnvVar system environment variable.
exceptionStringEither 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.messageStringThe exception message on the exchange or null, if no exception is set.
date:command:patternStringA 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:beanRefObjectInvokes 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:KeyStringThe value of the Key property placeholder.
properties:Location:KeyStringThe value of the Key property placeholder, where the location of the properties file is given by Location.
threadNameStringThe name of the current thread.

Basic expression

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.HeaderName, to obtain the value of the HeaderName header, as follows:

<language language="simple">in.header.foo</language>

Variables embedded in a string

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 ${Expression} syntax clashes with another property placeholder syntax. In this case, you can disambiguate the placeholder using the alternative syntax, $simple{Expression}, for the simple expression. For example:

<simple>Hello $simple{in.header.name}, how are you?</simple>

Date variables

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>

Bean variables

The simple language also provides special variables for calling bean methods:

bean:beanRef

For example, you can use the bean variables as follows:

<language language="simple">
  The order type is ${bean:orderService?method=getOrderType}
</language>