WSO2 ESB Content Aware Routing 1

Posted: October 12, 2013 in linux, ubuntu
Tags: , ,
  • ESB filter mediater

The Filter Mediator can be used for XPath filtering of messages. There are two modes of operation.

We can use the filter mediater when we want to do filtering messages based on XPath. It can be used in two ways

  1. Specify a XPath – The XPath will be evaluated to either True or False
  2. Expression and a regular expression –  Here the expression is matched with the given regular expression. Return true if it matches, false if doesn’t match.

In both cases, if returns true “then” part will be executed, if returns false “else” part will be executed.

In the fallowing example we use the filter in the 2nd way. We try to filter the message based on the action of the message. If the action of the message contains “getQuote”, we log “GetQuote service is called”. Else we log “Another service is called”.


<filter source="get-property('Action')" regex=".*getQuote">
<then>
<log level="custom">
<property name="output" value="GetQuote service is called"/>
</log>
</then>
<else>
<log level="custom">
<property name="output" value="Another service is called"/>
</log>
</else>
</filter>

Example ESB proxy with above filter mediator is below.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="filter_mediater" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<filter source="get-property('Action')" regex=".*getQuote">
<then>
<log level="custom">
<property name="output" value="GetQuote service is called"/>
</log>
</then>
<else>
<log level="custom">
<property name="output" value="Another service is called"/>
</log>
</else>
</filter>
</inSequence>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</target>
<description></description>
</proxy>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s