The Spring Expression Language (SpEL) is an object graph navigation language provided with Spring 3, which can be used to construct predicates and expressions in a route. A notable feature of SpEL is the ease with which you can access beans from the registry.
The SpEL expressions must use the placeholder syntax,
#{
, so that they can be embedded in
a plain text string (in other words, SpEL has expression templating enabled).SpelExpression
}
SpEL can also look up beans in the registry (typically, the Spring registry), using the
@
syntax. For example, given a bean with the
ID, BeanID
headerUtils
, and the method, count()
(which counts the number of
headers on the current message), you could use the headerUtils
bean in an SpEL
predicate, as follows:
#{@headerUtils.count > 4}
To use SpEL in your routes you need to add a dependency on camel-spring
to your project as shown in Example 18.1.
Example 18.1. Adding the camel-spring dependency
<!-- Maven POM File --> <properties> <camel-version>2.8.0-fuse-00-08</camel-version> ... </properties> <dependencies> ... <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>${camel-version}</version> </dependency> ... </dependencies>
Table 18.1 lists the variables that are accessible when using SpEL.
Table 18.1. SpEL variables
Variable | Type | Description |
---|---|---|
this | Exchange | The current exchange is the root object. |
exchange | Exchange | The current exchange. |
exchangeId | String | The current exchange's ID. |
exception | Throwable | The exchange exception (if any). |
fault | Message | The fault message (if any). |
request | Message | The exchange's In message. |
response | Message | The exchange's Out message (if any). |
properties | Map | The exchange properties. |
property( | Object | The exchange property keyed by Name . |
property( | Type | The exchange property keyed by Name , converted to the
type, Type . |