Versions Compared

Key

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

...

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

...

Table of Contents
maxLevel3
minLevel3
styleborder:1
locationtop
typeflat
separatorpipe

...

Syntax

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

...

One could also use this Mediator to handle the failure case as well, in this case the configuration would be as follows:

Code Block

<filter (source="xpath" regex="string") | xpath="xpath">
   <then [sequence="string"]>
     mediator+
   </then>
   <else [sequence="string"]>
     mediator+
   </else>
 </filter>

...

  • 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.

    Info
    titleTip

    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. See Common Screens and Dialog Boxes.

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

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

...

Example

Code Block

<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.

Excerpt
hiddentrue

Description of the Filter Mediator in WSO2 ESB.