Chapter 22. MVEL


MVEL is a Java-based dynamic language that is similar to OGNL, but is reported to be much faster. The MVEL support is in the camel-mvel module.


You use the MVEL dot syntax to invoke Java methods, for example:
Because MVEL is dynamically typed, it is unnecessary to cast the message body instance (of Object type) before invoking the getFamilyName() method. You can also use an abbreviated syntax for invoking bean attributes, for example:

Adding the MVEL module

To use MVEL in your routes you need to add a dependency on camel-mvel to your project as shown in Example 22.1, “Adding the camel-mvel dependency”.

Example 22.1. Adding the camel-mvel dependency

<!-- Maven POM File -->


Built-in variables

Table 22.1, “MVEL variables” lists the built-in variables that are accessible when using MVEL.

Table 22.1. MVEL variables

thisorg.apache.camel.ExchangeThe current Exchange
exchangeorg.apache.camel.ExchangeThe current Exchange
exceptionThrowablethe Exchange exception (if any)
exchangeIDStringthe Exchange ID
faultorg.apache.camel.MessageThe Fault message(if any)
requestorg.apache.camel.MessageThe IN message
responseorg.apache.camel.MessageThe OUT message
propertiesMapThe Exchange properties
property(name)ObjectThe value of the named Exchange property
property(name, type)TypeThe typed value of the named Exchange property


Example 22.2, “Route using MVEL” shows a route that uses MVEL.

Example 22.2. Route using MVEL

    <from uri="seda:foo"/>
      <language langauge="mvel"> == 'bar'</language>
      <to uri="seda:bar"/>