How to compare integer properties using a filter in wso2 esb?

I am new to wso2 esb and define 3 services that return an integer value and use a filter broker to route from one to another, but it doesn’t work correctly, and in filter mode, my source always returns false:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="SeqOne"> <log level="full"/> <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:m0="http://tempuri.org/" name="CParam" expression="//m0:SumSerViseResponse/m0:SumSerViseResult" scope="default" type="INTEGER"/> <log level="custom"> <property xmlns:ns="http://org.apache.synapse/xsd" name="CParam" expression="$ctx:CParam"/> </log> <property name="propertyA" value="4" scope="default" type="INTEGER"/> <log level="custom"> <property xmlns:ns="http://org.apache.synapse/xsd" name="propertyA" expression="get-property('propertyA')"/> </log> <property xmlns:ns="http://org.apache.synapse/xsd" name="propertyCompare" expression="$ctx:CParam > get-property('propertyA')" type="STRING"/> <log level="custom"> <property xmlns:ns="http://org.apache.synapse/xsd" name="propertyCompare" expression="get-property('propertyCompare')"/> </log> <filter xmlns:ns="http://org.apache.synapse/xsd" source="get-property('propertyCompare')" regex="true"> <then> 
+4
source share
2 answers

I tried your script and got the same result as yours. Then he looked deep into it, as that was the main functionality, and as I thought, I had already done something similar before.

The problem here is the property type. For some strange reason, INTEGER doesn't work here. You must have DOUBLE or STRING . Even if you have a line, it will display it correctly when you perform a comparison, as 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> 
+5
source

The following is an example with a switch broker,

 <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 journal brokers with the dispatch broker according to your needs.

+1
source

Source: https://habr.com/ru/post/1502743/


All Articles