Contact Us 1-800-596-4880

Using Non-MEL Expressions

This page refers to pre-Mule 3.3 expressions. This type of expression is still supported, but is not recommended.

Instead, please refer to Mule Expression Language MEL for a complete user guide and reference.

Expressions allow you to extract information from the current message or determine how to handle the message. Expressions are very useful with routers and filters for defining routing logic and for filtering out unwanted messages.

Mule provides several default expression evaluators, allowing you to embed expression logic in a variety of expression languages, or you can create your own evaluators to support additional languages.

This page describes how to use expressions. For more details on how to configure expressions, see Non-MEL Expressions Configuration Reference.

Message Property Scopes

Starting with Mule 3 expressions operating on message properties also support an optional scope qualifier syntax. For more information about message scopes, see Mule Concepts.

Using Expressions with Transformers

This section describes the transformers that support expressions. For more information on transformers, see Using Transformers.

Expression Transformer

The expression transformer executes one or more expressions on the current message where the result of the expression(s) will become the payload of the current message.

For example, imagine you have a flow component with a message signature that accepts three arguments:

public class ShippingService
    public ShippingConfirmation makeShippingRequest(Customer customer, Item[] items, DataHandler supportingDocumentation)
        //do stuff

And the message being passed to you component looks like this:

public interface ShippingRequestMessage
    public Customer getCustomer();
    public Item[] getShippingItems();

The <expression-transformer> can be used to extract the fields from the ShippingRequestMessage to invoke the ShippingService. Note that we can only get two of the arguments from the ShippingRequestMessage: Customer and Item[]. The supporting documentation, which could be something like a Microsoft Word or Excel document, is an attachment to the ShippingRequestMessage. Attachments can be associated with any message within Mule.

    <return-argument evaluator="bean" expression="customer"/>
    <return-argument evaluator="bean" expression="shippingItems"/>
    <return-argument evaluator="attachment" expression="supportingDocs" required="false"/>

Here we execute three separate expressions to obtain the three arguments required to invoke the ShippingService.makeShippingRequest() method. The first two expressions use the bean evaluator to extract objects from the message. The last argument uses the attachment evaluator to obtain a single attachment. Note that supportDocuments can be null, so we set required="false" on the return argument.

Message Properties Transformer

The <message-properties-transformer> allows you to add, remove, or rename properties dynamically or statically on the current message. For example:

    <add-message-property key="GUID" value="#[string:#[xpath:/msg/header/ID]-#[xpath:/msg/body/@ref]]"/>

The above expressions extract the <ID> element value and the ref attribute on the <body> element, setting the result as a message property named GUID.

XSLT Transformer

The XSLT transformer processes the XML payload of the message through XSLT. Using expressions, you can inject information about the current message into the XSLT as a parameter. For example:

<mulexml:xslt-transformer name="xslt" xslFile="./conf/xsl/cd-listing.xsl">
    <mulexml:context-property key="title" value="#[header:ListTitle]"/>
    <mulexml:context-property key="rating" value="#[header:ListRating]"/>

When executed, the headers ListTitle and ListRating from the current message are added to the XSLT context as parameters called title and rating, respectively. You can reference these parameters inside the XSLT using the <xsl:param> element:

Using Expression Filters

Expression filters can be used in content-based routing to assert statements on the current message and route the message accordingly. Expression filters work in the same way as other types of Mule filters and have the same expression attributes as listed above. The expression on the filter must evaluate to true or false. For example:

<expression-filter evaluator="header" expression="my-header!=null"/>

As usual, you can use AND, OR, and NOT filters to combine expressions.

    <expression-filter evaluator="header" expression="origin-country=USA"/>
    <expression-filter evaluator="groovy" expression="payload.purchase.amount > 10000"/>

Note that expression filters support a sub-set of all expression evaluators, because filters should only evaluate against the current message. For example, there is no point in using a function expression on a filter. The supported expression evaluators are: bean, custom, exception-type, groovy, header, jxpath, ognl, payload-type, regex, wildcard, and xpath. For more information on expression evaluators, see Non-MEL Expressions Configuration Reference.

For more information on filters, see Using Filters.

To read more about configuring expressions, see Non-MEL Expressions Configuration Reference.