3

I'm developing an application with mule studio, I need to use the "Choice" component, but I'd like to evaluate not a message property contained in the payload, but a variable contained in a property file, like that:

<choice doc:name="Choice">
                <when expression="${CONTROL_VARIABLE}.equals(&quot;S&quot;)">
                    <set-variable variableName="URL_ADDRESS" value="${URL_PREPATH_VALUE}/[#payload.URL]" doc:name="Variable"/>
                </when>
                <otherwise>
                    <set-variable variableName="URL_ADDRESS" value="[#payload.URL]" doc:name="Variable"/>
                </otherwise>
            </choice>

Of course it doesn't work, because if I understand properly, only message payload can be evaluated.

How can I accomplish the task in the best way? Have I to add all the property file variables in the payload in some way?

Thank you!

user1820620
  • 672
  • 2
  • 13
  • 27

3 Answers3

2

The conditional expression in the CHOICE is going to work absolutely fine with data loaded from properties files.

try the following piece and it should work.

<when expression="'${CONTROL_VARIABLE}' == 'S'">

Hope this helps.

user1760178
  • 6,277
  • 5
  • 27
  • 57
1

you can also define choice expression condition referring to properties files as below.

<when expression="#['${test}' =='1']">

Mohan
  • 520
  • 4
  • 16
-2

You were just missing to enclose you property reference with single quote.You can also use equals method instead of using == operator. You just need to enclose your property reference with single quote before the comparison.

<*when expression="'${CONTROL_VARIABLE}'.equals('S')"*>

Explanation: When you enclose the property reference with single quote like '${CONTROL_VARIABLE}' it gets converted into string object after this you can apply any method/operator which supports String type.

Hope this helps.

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
  • 1
    This answer is c=very similar to the accepted answer. When answering an old question with an accepted answer please add something new and useful. – AdrianHHH Nov 11 '15 at 15:33