Search code examples
syntaxexpressionevalesbmule

Mule Choice Expression - Routing based off Outbound property


I have a property I am extracting from the Message's Payload and setting into an Outbound property (to make it easier to access). I want to simply check the size of this property, but all my best guesses are giving me exceptions.

I've tried using the #[header:OUTBOUND:count] syntax, adding an evaluator="header" attribute to the <when> tag, nothing seems to be working. I've tried other evaluators as well, but I cannot find any Mule documentation with examples of syntax, so I'm just guessing how the expressions should be formed.

<choice doc:name="Choice">
        <when expression="message.outboundProperties['count']==0">
            <processor-chain>
                ... something here ...
            </processor-chain>
        </when>
        <otherwise>
            <processor-chain>
                ... alternate option ...
            </processor-chain>
        </otherwise>
    </choice>

Solution

  • Assuming you're running Mule 3.3.0 and that count is numeric, your syntax is correct and should work as is.

    To make it canonical, add #[] around the expression:

    <when expression="#[message.outboundProperties['count'] == 0]">
    

    Because its name is compatible with MVEL attribute naming, you could even access the count entry directly:

    <when expression="#[message.outboundProperties.count == 0]">