DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Querying Without a Query Language
  • Tableau Dashboard Development Best Practices
  • An Introduction to Bloom Filters
  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases

Trending

  • A System Cannot Protect What It Does Not Understand
  • Multi-Scale Feature Learning in CNN and U-Net Architectures
  • How to Format Articles for DZone
  • The Agentic Agile Office: Streamlining Enterprise Agile With Autonomous AI Agents
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. WSO2 ESB Filter Mediator Tutorial

WSO2 ESB Filter Mediator Tutorial

By 
Madhuka  Udantha user avatar
Madhuka Udantha
·
May. 15, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
13.2K Views

Join the DZone community and get the full member experience.

Join For Free

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


Syntax

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


Usecase

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

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

respond:
<ns:getBusNoResponse xmlns:ns="http://transport.org">
  <ns:return>root1Colombo</ns:return>
  <ns:return>Negombo</ns:return>
  <ns:return>Galle</ns:return>
</ns:getBusNoResponse>

getTraingNo

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

respond:
<ns:getTrainNoResponse xmlns:ns="http://transport.org">
  <ns:return>12-Colombo</ns:return>
  <ns:return>13-Muthu</ns:return>
  <ns:return>01-Bange</ns:return>
</ns:getTrainNoResponse>


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"

image

5. Here I am adding WSO2 Filter Mediator

image

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

image

Here is proxy Source View

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


 

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

Make bus request and train request and see console log

image

image

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

Enterprise service bus Mediator (software) Filter (software)

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

Opinions expressed by DZone contributors are their own.

Related

  • Querying Without a Query Language
  • Tableau Dashboard Development Best Practices
  • An Introduction to Bloom Filters
  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook