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

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • An Introduction to Bloom Filters
  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases
  • Filtering Java Collections via Annotation-Driven Introspection
  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)

Trending

  • Kubeflow: Driving Scalable and Intelligent Machine Learning Systems
  • Contextual AI Integration for Agile Product Teams
  • Optimizing Integration Workflows With Spark Structured Streaming and Cloud Services
  • Power BI Embedded Analytics — Part 2: Power BI Embedded Overview
  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
12.9K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • An Introduction to Bloom Filters
  • Motivations for Creating Filter and Merge Plugins for Apache JMeter With Use Cases
  • Filtering Java Collections via Annotation-Driven Introspection
  • Rethinking Enterprise Integration: The Understated Role of Enterprise Service Bus (ESB)

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: