The Filter Mediator can be used for XPath filtering of messages based on an XPath or JSON Path. There are two modes of operation.
- If the user only specifies the XPath or JSON Path, it will be evaluated as true or false.
- If the user specifies a regular expression as well, the string returned from evaluating the XPath or JSON Path will be matched against the regular expression.
<filter (source="xpath[XPath|json-eval(JSON Path)]" regex="string") | xpath="xpath[XPath|json-eval(JSON Path)]"> mediator+ </filter>
The Filter Mediator either tests the given XPath/JSON Path expression as a boolean Boolean expression, or matches the evaluation result of a source XPath/JSON Path expression as a string against the given regular expression. If the test succeeds, the Filter Mediator will execute the enclosed mediators in sequence.
One could also use this Mediator mediator to handle a failure scenario as well. In this case, the configuration will be as follows:
<filter (source="xpath[XPath|json-eval(JSON Path)]" regex="string") | xpath="xpath[XPath|json-eval(JSON Path)]"> <then [sequence="string"]> mediator+ </then> <else [sequence="string"]> mediator+ </else> </filter>
In this case, the Filter condition remains the same and the succeeded messages will be mediated using the the set of mediators enclosed in the "then" element in sequence, while failed messages will be mediated using the set of Mediators mediators enclosed in the "else" element in sequence.
- Specify As - Specifies whether you give the condition as an XPath or a Regular expression.
- XPath - XPath or JSON Path expression if you selected the "XPath" for "Specify As" option to "XPath". When specifying a JSON Path, use the format
json-eval(<JSON_PATH>), such as
Source- XPath expression Expression to locate the value which that matches the regular expression that you can define below.
Info title Tip
Click the "Namespaces" link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have used in the XPath or JSON Path expression.
- Regex - Regular expression to match the source value.