Nav

Filters

Mule bundles more than a dozen Filters that determine whether a message can proceed through an application flow. The simplest filters implement basic logic operators (such as and, or, and not), but these simple elements can be combined in various ways to specify complex logical conditions.

Custom Filters

In addition to applying standard filters, you can create a custom filter to specify a precise set of conditions a message must satisfy before it can continue through the flow. Note that the reference is to a class implementing the Filter interface.

The Filter Class is required if you build global filter. See Filters Configuration Reference for details on how to work with this class.

Global Filters

You can create a global filter that specifies a set of conditions that the message must meet at points along the flow specified by the Filter Reference building block:

filter-reference-icon

Bundled Filters

The following filters are provided in Anypoint Studio. Drag the Filter Reference building block to the canvas, click the green plus sign to configure the filter, and click a filter type from the Choose Global Type menu. For more information, see Filter Reference.

filter-types

Filters Description

And, Or, Not

These logic filters express simple logic. When required to express complex logic, these three filters can be used in combination with other filters.

Custom

References a user-implemented filter class.

Exception

Filters against an exception of a specified type.

Expression

Filters against a range of expressions.

Idempotent Message

Ensures that a flow receives only unique messages.

Reference: Idempotent Filter

Message

Applies specified criteria to a message to determine whether it should be processed.

Message Property

Applies a regular expression pattern to the message payload to determine whether it should be processed.

Payload

Evaluates the payload type of a message to determine whether it should be processed.

Regex

Applies a regular expression pattern to determine whether it should be processed.

Schema Validation

Uses the JAXP libraries, to validate a message against a schema.

Wildcard

Matches string messages against a wildcard pattern.

Filter Logic

When a message fails to satisfy the conditions specified by a filter, that filter returns a null value, which causes the processing of that particular message to halt. In other words, the message is rejected and undergoes no further processing.

When a message satisfies the conditions specified by a filter, that filter passes the payload of the message to the next building block in the flow, and processing of that particular message continues.

When you place a filter immediately after an HTTP endpoint configured for a request-response pattern, and no response has been configured for the flow, Mule uses as a response the result returned by the final message processor in the flow, which is null.

Configuring Filters

This section covers only those configuration activities common to all filters. For configuration activities that apply only to individual filters, click one of the links in the Reference column of the table Bundled Filters.

As for all Studio building blocks, you configure Filters in two major steps:

  1. Drag the filter from the Palette to the Message Flow canvas, then set its position within the sequence of building blocks that make up the application flow.

  2. Provide values for the required fields on the various tabs in the filter’s Properties Editor.

filter-properties

Filter Example

The following example creates an And filter:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <and-filter name="And" doc:name="And">
        <and-filter/>
    </and-filter>
    <flow name="add_logicFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <filter ref="And" doc:name="Filter Reference"/>
    </flow>
</mule>