Introduction

Overview

To provide greater flexibility when parsing and processing messages, Apache Camel supports language plug-ins for various scripting languages. For example, if an incoming message is formatted as XML, it is relatively easy to extract the contents of particular XML elements or attributes from the message using a language such as XPath. The Apache Camel implements script builder classes, which encapsulate the imported languages. Each language is accessed through a static method that takes a script expression as its argument, processes the current message using that script, and then returns an expression or a predicate.

Declaring the language in use

Red Hat Fuse IDE's Property Editor uses a drop-down list to specify the language used in an expression. The combination of the Expression field and the associated Language field is translated into a language element in the generated XML. The language element has a language attribute that specifies the language used to interpret the expression. The content of the element must be a script written in the relevant language. At runtime, the return value of the script is read by the parent element.

Available languages

Table 1, “Available languages” lists the values for the Language attribute.

Table 1. Available languages

LanguageAttribute ValueDescription
ConstantconstantAllows the use of constants as an expression.
ELelThe Unified Expression Language (EL), originally developed as part of the JSP standard (see http://juel.sourceforge.net/).
GroovygroovyThe Groovy scripting language (see http://groovy.codehaus.org/).
HeaderheaderExtracts the value of a named header.
JavaScriptjavaScriptThe JavaScript scripting language (see http://developer.mozilla.org/en/docs/JavaScript), also known as ECMAScript (see http://www.ecmascript.org/).
MVELmvelThe MVEL expression language (see http://mvel.codehaus.org/).
OGNLognlThe OGNL (Object Graph Navigation Language) language (see http://www.ognl.org/).
PHPphpThe PHP scripting language (see http://www.php.net/).
PropertypropertyExtracts the value of a named property.
PythonpythonThe Python scripting language (see http://www.python.org/).
RubyrubyThe Ruby scripting language (see http://www.ruby-lang.org/).
SimplesimpleA simple expression language, native to Apache Camel.
SQLsqlThe JoSQL language, which is a language for extracting and manipulating data from collections of Java objects, using a SQL-like syntax (see http://josql.sourceforge.net/).
XPathxpathThe XPath language, which is used to select element, attribute, and text nodes from XML documents (see http://www.w3schools.com/xpath/default.asp). The XPath expression is applied to the current message.
XQueryxqueryThe XQuery language, which is an extension of XPath (see http://www.w3schools.com/xquery/default.asp). The XQuery expression is applied to the current message.