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.

Syntax:

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

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) .

Example:

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


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.

1 comment:

  1. how can i change my theme or dark mode in wso2 integration studio

    ReplyDelete