The Filter Mediator can be used for filtering messages based on an XPath, JSONPath or a regular expression. If the test succeeds, the Filter mediator executes the other mediators enclosed in the sequence.
The Filter Mediator closely resembles the "If-else" control structure.
This mediator could also be used to handle a scenario where two different sequences are applied to messages that meet the filter criteria and messages that do not meet the filter criteria.
In this case, the Filter condition remains the same. The messages that match the filter criteria will be mediated using the set of mediators enclosed in the
then element. The messages that do not match the filter criteria will be mediated using the set of mediators enclosed in the
The parameters available for configuring the Filter mediator are as follows:
This is used to specify whether you want to specify the filter criteria via an XPath expression or a regular expression.
The expression to locate the value that matches the regular expression that you can define in the Regex parameter.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression.
|Regex||The regular expression to match the source value.|
Example 1: Sending only messages matching the filter criteria
In this example, the Filter will get the
To header value and match it against the given regular expression. If this evaluation returns
true, it will send the message. If the evaluation returns
false, it will drop the message.
Example 2: Applying separate sequences
In this example, the Log mediator is used to log information from a service named Bus Services via a property when the request matches the filter criteria. When the request does not match the filter criteria, another log mediator configuration is used log information from a service named Train Service in a similar way.