Este contenido no está disponible en el idioma seleccionado.

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


Overview

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.

Camel on EAP deployment

This component is supported by the Camel on EAP (Wildfly Camel) framework, which offers a simplified deployment model on the Red Hat JBoss Enterprise Application Platform (JBoss EAP) container.

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 24.1, “Adding the camel-ognl dependency”.

Example 24.1. Adding the camel-ognl dependency

<!-- Maven POM File -->
...
<dependencies>
  ...
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-ognl</artifactId>
    <version>${camel-version}</version>
  </dependency>
  ...
</dependencies>

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 24.1, “OGNL variables” lists the built-in variables that are accessible when using OGNL.

Table 24.1. OGNL variables
NameTypeDescription

this

org.apache.camel.Exchange

The current Exchange

exchange

org.apache.camel.Exchange

The current Exchange

exception

Throwable

the Exchange exception (if any)

exchangeID

String

the Exchange ID

fault

org.apache.camel.Message

The Fault message(if any)

request

org.apache.camel.Message

The IN message

response

org.apache.camel.Message

The OUT message

properties

Map

The Exchange properties

property(name)

Object

The value of the named Exchange property

property(name, type)

Type

The typed value of the named Exchange property

Example

Example 24.2, “Route using OGNL” shows a route that uses OGNL.

Example 24.2. Route using OGNL

<camelContext>
  <route>
    <from uri="seda:foo"/>
    <filter>
      <language langauge="ognl">request.headers.foo == 'bar'</language>
      <to uri="seda:bar"/>
    </filter>
  </route>
</camelContext>
Red Hat logoGithubRedditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

© 2024 Red Hat, Inc.