how to compare integer properties in filter mediation in wso2 esb?

折月煮酒 提交于 2019-12-05 16:24:28

I tried your scenario and got the same output as yours. Then looked deep into it as this was a basic functionality and as I thought I've done something similar before.

The issue here is in the type of the property. For some strange reason INTEGER does not work here. You need to have DOUBLE or STRING. Even if you have string, it will correctly cast it when you do a comparison as in here. The following worked for me.

<inSequence>
     <log level="full"/>
     <property xmlns:m0="http://tempuri.org/"
               name="CParam"
               expression="//m0:SumSerViseResponse/m0:SumSerViseResult"
               scope="default"
               type="DOUBLE"/>
     <log level="custom">
        <property name="CParam" expression="$ctx:CParam"/>
     </log>
     <property name="propertyA" value="4.0" scope="default" type="DOUBLE"/>
     <log level="custom">
        <property xmlns:ns="http://org.apache.synapse/xsd"
                  name="propertyA"
                  expression="get-property('propertyA')"/>
     </log>
     <property name="propertyCompare"
               expression="$ctx:CParam > get-property('propertyA')"
               scope="default"
               type="BOOLEAN"/>
     <log level="custom">
        <property name="propertyCompare" expression="get-property('propertyCompare')"/>
     </log>
     <filter xpath="$ctx:CParam > get-property('propertyA')">
        <then>
           <send>
              <endpoint>
                 <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
              </endpoint>
           </send>
        </then>
        <else>
           <drop/>
        </else>
     </filter>
  </inSequence>

following is an example done with switch mediator,

<switch source="get-property('propertyCompare')">
        <case regex="1">
           <log>
              <property name="one" value="__________ONE__________"/>
           </log>
        </case>
        <case regex="2">
           <log>
              <property name="two" value="__________TWO__________"/>
           </log>
        </case>
     </switch>

replace the log mediators with send mediator according to your needs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!