Tuesday, July 28, 2015

How to use Filter Mediator in WSO2 ESB

Filter mediator is basically used to match or filter the message for a given xpath.

If user gives only the xpath then it will return true or false but if user gives regular expression then the string returned from evaluating the XPath will be matched against the regular expression.


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

This is same as Java coding like "if else" condition. If string in filter is matched then execute “then” block otherwise execute “else” block (if else block is also written) .


<filter xpath="get-property('Language')='WSO2'">
                  <endpoint key="GetWSO2DetailsService_EPR"/>
                  <endpoint key="GetJAVADetailsService_EPR"/>

In above example we are checking the value of ‘Language’, if the value of ‘Language’ is WSO2 then it will call a GetWSO2DetailsService service in send mediator otherwise it will call a GetJAVADetailsService service.

Here “get-property” is a property mediator which holds a particular value same as in Java a variable holds a value.