Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 23. The Object-Graph Navigation Language(OGNL)


OGNL is an expression language for getting and setting properties of Java objects. You use the same expression for both getting and setting the value of a property. The OGNL support is in the camel-ognl module.

Adding the OGNL module

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

Example 23.1. Adding the camel-ognl dependency

<!-- Maven POM File -->

Static import

To use the ognl() static method in your application code, include the following import statement in your Java source files:
import static org.apache.camel.language.ognl.OgnlExpression.ognl;

Built-in variables

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

Table 23.1. OGNL 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 23.2, “Route using OGNL” shows a route that uses OGNL.

Example 23.2. Route using OGNL

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