This documentation is for WSO2 Enterprise Service Bus version 4.8.0 . View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The Filter Mediator can be used for XPath filtering of messages based on an XPath or JSON Path. There are two modes of operation.

  1. If the user only specifies the XPath or JSON Path, it will be evaluated as true or false.
  2. 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.

...

Code Block
XML
XML
<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:

Code Block
XML
XML
<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 json-eval(getQuote.request.symbol).
  • Source- XPath expression Expression to locate the value which that matches the regular expression that you can define below.

    Info
    titleTip

    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.

...