复合MEL语句有问题

时间:2014-12-31 17:25:40

标签: mule mule-el

我需要从配置文件中读取值,并且我一直遇到嵌入式MEL语句的问题;追逐多个死胡同,我没有想法。我使用会话变量将其简化为一个相当简单的示例。

谢谢你,
- 唐

以下代码失败:
消息:[错误:缺少左侧节点]
[近:{... message.payload.contains(#[sessionVars [' valueToMatch']])....}]

    <set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />        
    <choice doc:name="Choice">
        <when expression="#[message.payload.contains(#[sessionVars['valueToMatch']])]">
            <set-session-variable variableName="success" value="true" />        
        </when>
        <otherwise>
            <set-session-variable variableName="success" value="false" />       
        </otherwise>
    </choice>

以下代码有效:

    <choice doc:name="Choice">
        <when expression="#[message.payload.contains('Now we are engaged in a great civil war')]">
            <set-session-variable variableName="success" value="true" />        
        </when>
        <otherwise>
            <set-session-variable variableName="success" value="false" />       
        </otherwise>
    </choice>

2 个答案:

答案 0 :(得分:1)

我的猜测是问题是你要在表达式中放置一个表达式,试试这个:

"#[message.payload.contains(sessionVars['valueToMatch'])]"

而不是

"#[message.payload.contains(#[sessionVars['valueToMatch']])]"

答案 1 :(得分:1)

试试这个#[message.payload contains valueToMatch] ...它将完美而简单地工作: -

<set-session-variable variableName="valueToMatch" value="Now we are engaged in a great civil war" />        
    <choice doc:name="Choice">
        <when expression="#[message.payload contains valueToMatch]">
            <set-session-variable variableName="success" value="true" />        
        </when>
        <otherwise>
            <set-session-variable variableName="success" value="false" />       
        </otherwise>
    </choice>