This documentation is for WSO2 ESB version 4.0.2. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The Filter Mediator can be used for XPath filtering of messages. There are two modes of operation.

  1. If user only specifies the XPath, it will be evaluated as true or false.
  2. If user specifies a regular expression as well, the string returned from evaluating the XPath will be matched against the regular expression.

In both modes, if evaluation of expression returns true child mediators will be executed.

The Filter Mediator closely resembles the "If-else" control structure.



Syntax

<filter (source="xpath" regex="string") | xpath="xpath">
   mediator+
</filter>

The Filter Mediator either test the given XPath expression as a boolean expression, or match the evaluation result of a source XPath 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 to handle the failure case as well, in this case the configuration would be as follows:

<filter (source="xpath" regex="string") | xpath="xpath">
   <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 enclosed in the else element in sequence.


UI Configuration

Here are the configuration options related to the Filter Mediator:

  • Specify As -Specifies whether you give the condition as an XPath or a Regular expression.
  • XPath - XPath expression if you selected the "Specify As" option to "XPath".
  • Source - XPath expression to locate the value which is going match with the regular expression that you can define below.

    Tip

    You can 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 expression.

  • Regex - Regular expression to match with the source value.

Note

You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.


Example

<filter source="get-property('To')" regex=".*/StockQuote.*">
      <then>
          <send/>
      </then>
      <else>
          <drop/>
      </else>
</filter>

In this example, 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.

  • No labels