2

I have the following mule expression in a choice component:

 <choice doc:name="Choice">
        <when expression="'localhost' == ${environment}">
           ... Do something
        </when>

The environment property is loaded via a property file, and appears to resolve correctly. However, I get the following error:

[Error: unresolvable property or identifier: localhost]
[Near : {... 'localhost' == localhost ....}]

I've also tried wrapping the expression in #[], and reversing the order of the variables in the comparison <when expression="${environment} == 'localhost'">, but I get the same error.

Gary Sharpe
  • 2,369
  • 8
  • 30
  • 51

3 Answers3

4

The spring property is interpolated before the XML is parsed, leading to the following XML configuration when the environment property is equal to "localhost":

<choice doc:name="Choice">
    <when expression="'localhost' == localhost">
       ... Do something
    </when>

Mule will look for a flow variable or session variable named "localhost", which is probably not what you want.

Try this:

<choice doc:name="Choice">
    <when expression="'localhost' == '${environment}'">
       ... Do something
    </when>
Ryan Hoegg
  • 2,415
  • 2
  • 14
  • 15
0

You should use equals:

<when expression="#['localhost'.equals(${environment})]">

Zulu
  • 8,765
  • 9
  • 49
  • 56
Dds
  • 712
  • 5
  • 7
  • Unfortunately, when I try this I get the following error: Root Exception stack trace: [Error: unresolvable property or identifier: localhost] [Near : {... 'localhost'.equals(localhost) ....}] – Gary Sharpe Apr 09 '15 at 00:07
  • Surrounding ${environment} with single quotes solved the problem. – Gary Sharpe Apr 09 '15 at 00:09
  • Yeah my bad, as explained by Ryan the place holder just replace the value which in turn, when interpreted by mel, as it has no '' it will asume you are referring to a variable name. Happy you got it working ;) – Dds Apr 09 '15 at 13:05
0

making
expression ="'localhost' == '${environment}'" will solves the problem. in the expresssion right side needs to be another string to compare but in your code it will be converted as "'localhost' == localhost as it unable to resolve the localhost i.e right side of assignment operator it throws error