Enterprise Integration Zone is brought to you in partnership with:

Madhuka is Software Engineer and currently works on the Jaggery, UES, WSO2 Gadget Server team. He holds a B.Sc (Hons) degree in Information Technology from the Faculty of Information Madhuka is a DZone MVB and is not an employee of DZone and has posted 53 posts at DZone. You can read more from them at their website. View Full User Profile

WSO2 ESB Filter Mediator Tutorial

  • submit to reddit

This post will be for WSO2 ESB Filter Mediator and it will be cover simple usecase with basic Filter Mediator functions. It can be used for XPath filtering of messages.

There are two modes of operation

  • Specifies the XPath (boolean expression), return true or false
  • XPath will be matched against the regular expression return true or false


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


I have services call 'BusService' where I can give rootId (road name) and get list bus number that going on that root. In the same services it have some train deatils also.

When client call busService it must give busService and also If client ask for train details rather bus system must give it also.

Here is busServices calls

  <p:getBusNo xmlns:p="http://transport.org">
  <xs:rootId xmlns:xs="http://transport.org">root1</xs:rootId>

<ns:getBusNoResponse xmlns:ns="http://transport.org">


  <p:getTrainNo xmlns:p="http://transport.org">
  <xs:rootId xmlns:xs="http://transport.org">root1</xs:rootId>

<ns:getTrainNoResponse xmlns:ns="http://transport.org">

Now I have write simple WSO2 ESB proxy with filter mediator.

1. Download wso2 esb 4.6.0 

2. Start wso2 esb <WSO2ESB_HOME>/bin/wso2server.bat (offset 1) Other services expose in wso2 AS in offset 0

3. Go to https://localhost:9444/carbon/

4. Then Create "Pass Through Proxy"


5. Here I am adding WSO2 Filter Mediator


  • Specify As: XPath or a Regular expression.
  • XPath: XPath expression if you selected the "Specify As" option to "XPath".
  • Source: which is going match with the reguilar expression
  • Regex: Regular expression to match with the source value.

6. In Here I am filtering for the action  of the WS request and it log the client request

is it bus or train request?


Here is proxy Source View

<proxy xmlns="http://ws.apache.org/ns/synapse" name="transportProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
         <filter source="get-property('Action')" regex=".*getBusNo">
               <log level="custom">
                  <property name="service" value="Bus Services is called"/>
               <log level="custom">
                  <property name="service" value="Train Service is called"/>
         <address uri="http://localhost:9763/services/BusServices"/>
   <publishWSDL uri="http://localhost:9763/services/BusServices?wsdl"/>


6. Go to https://localhost:9444/services/transportProxy?tryit#

Make bus request and train request and see console log



You can improve this usecase with some WSO2 ESB mediator if you wish!!

Published at DZone with permission of Madhuka Udantha, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)