Over a million developers have joined DZone.

WSO2 ESB Filter Mediator Tutorial

· Integration Zone

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

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

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.


Published at DZone with permission of Madhuka Udantha, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}