4

谁能解释为什么会发生以下行为?为什么在使用逻辑 AND 时操作数的顺序很重要?在 mule-ce 3.3.1 上运行。

输出如下:

true  
true  
false  
true


<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">

    <flow name="testFlow1" doc:name="testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="20005" path="test" doc:name="HTTP"/>

        <message-properties-transformer overwrite="true" scope="session" doc:name="Message Properties">
              <add-message-property key="productNumber" value="1" />
        </message-properties-transformer>

        <logger level="INFO" message="#[(sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2') and  (sessionVars['quantity'] == null)]" doc:name="Logger"/>
        <!-- true -->

        <logger level="INFO" message="#[(sessionVars['quantity'] == null) and (sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2')]" doc:name="Logger"/>
        <!-- true -->

        <message-properties-transformer overwrite="true" scope="session" doc:name="Message Properties">
              <add-message-property key="productNumber" value="3" />
        </message-properties-transformer>

        <logger level="INFO" message="#[(sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2') and  (sessionVars['quantity'] == null)]" doc:name="Logger"/>
        <!-- false -->

        <logger level="INFO" message="#[(sessionVars['quantity'] == null) and (sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2')]" doc:name="Logger"/>
        <!-- true? it should not be true! -->        
    </flow>
</mule>
4

2 回答 2

2

使用& 而不是和。它计算正确的值。更新流程

<logger level="INFO" message="#[(sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2') &amp;&amp;  (sessionVars['quantity'] == null)]" doc:name="Logger"/>
    <!-- false -->


<logger level="INFO" message="#[(sessionVars['quantity'] == null) &amp;&amp; (sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '1')]" doc:name="Logger"/>
于 2014-11-09T06:17:17.117 回答
0

我不知道为什么会发生这种情况,但我在 3.4.0 CE 中也有同样的经历。获得正确结果的一种解决方法似乎是使用“&&”,如

#[(sessionVars['quantity'] == null) && (sessionVars['productNumber'] == '1' || sessionVars['productNumber'] == '2')]

于 2013-10-29T17:45:31.760 回答