The simple language provides various elementary expressions that return different
parts of a message exchange. For example, the expression,
simple("header.timeOfDay"), would return the contents of a
header called timeOfDay from the incoming message.
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:
simple("in.header.foo")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:
simple("Received a message from ${in.header.user} on $(date:in.header.date:yyyyMMdd}.")As well as providing variables that access all of the different parts of an
exchange (see Table 17.1), the simple language also
provides special variables for formatting dates,
date:command:pattern,
and for calling bean methods, bean:beanRef.
For example, you can use the date and the bean variables as follows:
simple("Todays date is ${date:now:yyyyMMdd}")
simple("The order type is ${bean:orderService?method=getOrderType}")The Object Graph Navigation
Language (OGNL) is a notation for invoking bean methods in a chain-like
fashion. If a message body contains a Java bean, you can easily access its bean
properties using OGNL notation. For example, if the message body is a Java object
with a getAddress() accessor, you can access the Address
object and the Address object's properties as follows:
simple("${body.address}")
simple("${body.address.street}")
simple("${body.address.zip}")
simple("${body.address.city}")Where the notation, ${body.address.street}, is shorthand for
${body.getAddress.getStreet}.
You can use the null-safe operator, ?., to avoid encountering
null-pointer exceptions, in case the body does not have an
address. For example:
simple("${body?.address?.street}")If the body is a java.util.Map type, you can look up a value in the
map with the key, foo, using the following notation:
simple("${body[foo]?.name}")You can also use square brackets notation, [k], to access the
elements of a list. For example:
simple("${body.address.lines[0]}")
simple("${body.address.lines[1]}")
simple("${body.address.lines[2]}")The last keyword returns the index of the last element of a list. For
example, you can access the second last element of a list, as
follows:
simple("${body.address.lines[last-1]}")







