Search code examples
muleesb

Choice flow control component fails in Mule ESB


i have a choice flow control component that uses an expression as follows:

 <choice>
   <when expression="${LoggingFlag} == YES">SOME CODE</when>
   <otherwise>SOME OTHER CODE</otherwise>                                                                                                           
 </choice>

Here LoggingFlag used is a key-value pair defined in the app.properties file.

LoggingFlag=NO

when i run the code i see the following error:

Execution of the expression "NO == YES" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Exception stack is:
1. [Error: unresolvable property or identifier: NO]
[Near : {... NO == YES ....}]

Can someone tell me what is the reason behind this issue?


Solution

  • This error occurs due to Mule not being able to resolve the type of value, set to LoggingFlag while comparing it in choice. For this you need to explicitly change the type to string, so that Mule can compare the two easily. For that you need to use:

    <choice> <when expression="'${LoggingFlag}' == 'YES'">SOME CODE</when> <otherwise>SOME OTHER CODE</otherwise> </choice>