Search code examples
mulemule-elmule-component

Integer Comparision in mule choice component


I have a very simple flow where im trying to do comparision of inbound property and payload which are integers inside a choice component, inspite of the values being the same the choice component routes its to the default section.

I would like to get some help to make this work

Thank you in advance

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <flow name="flow_testFlow1" doc:name="flow_testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <set-payload value="#[12]" doc:name="Set Payload"/>
        <set-property propertyName="trial" value="#[12]" doc:name="Property"/>
        <choice doc:name="Choice">
            <when expression="#[payload == message.inboundProperties['trial']]">
                <logger level="INFO" doc:name="Logger" message="Success"/>
            </when>
            <otherwise>
                <logger level="INFO" doc:name="Logger" message="error"/>
            </otherwise>
        </choice>
    </flow>
</mule>

Solution

  • set-property sets properties in the outbound scope, the inbound scope is read-only (created by the inbound endpoint).

    So you need to fix your choice route expression like this:

    <when expression="#[payload == message.outboundProperties['trial']]">
    

    And then it works.