Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

Chapter 23. MVEL


Overview

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.

Syntax

You use the MVEL dot syntax to invoke Java methods, for example:

getRequest().getBody().getFamilyName()

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:

request.body.familyName

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

Example 23.1. Adding the camel-mvel dependency

<!-- Maven POM File -->
<properties>
  <camel-version>2.23.2.fuse-7_13_0-00013-redhat-00001</camel-version>
  ...
</properties>

<dependencies>
  ...
  <dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-mvel</artifactId>
    <version>${camel-version}</version>
  </dependency>
  ...
</dependencies>

Built-in variables

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

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

Example 23.2. Route using MVEL

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

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

© 2024 Red Hat, Inc.