2015-02-09 53 views
1

我定義了一個外部xml,其中包含幾個表達式。騾動態條件

<mule xmlns="http://www.mulesoft.org/schema/mule/core" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:spring-security="http://www.mulesoft.org/schema/mule/spring-security" 
     xmlns:beans="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xsi:schemaLocation=" 
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd 
      http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <beans:bean id="conditions" class="java.util.ArrayList" name="conditions"> 
     <beans:constructor-arg> 
      <beans:list> 
       <beans:value>#[flowVars.price == '1000']</beans:value> 
       <beans:value>...</beans:value> 
      </beans:list> 
     </beans:constructor-arg> 
    </beans:bean> 

</mule> 

在主要流程中,我想評估這些experssions,但結果總是如此。這是我迄今爲止所做的。

<spring:beans> 
    <spring:import resource="classpath:my-conf-dir/expressions.xml"/> 
</spring:beans> 

<flow name="mainFlow" doc:name="mainFlow"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/> 
    <expression-filter expression="#[payload != '/favicon.ico']" doc:name="Expression"/> 

    <set-variable variableName="price" value="1001" doc:name="Set Price" /> 

    <foreach collection="#[app.registry.get('conditions')]" doc:name="For Each"> 
     <logger message="Condition: #[payload]" level="INFO" doc:name="Logger"/> 

     <choice> 
      <when expression="#[payload]"> 
       <logger message="OK" level="INFO" doc:name="Logger"/> 
      </when> 
      <otherwise> 
       <logger message="KO" level="INFO" doc:name="Logger"/> 
      </otherwise> 
     </choice> 
    </foreach> 
</flow> 

有什麼方法可以評估表達式列表嗎?

任何幫助,將不勝感激。

回答

0

可能是什麼,你可以評估使用Java組件和訪問eventContext.getMuleContext().getExpressionLanguage().evaluate方法表達一個更好的主意。

HTH,Marcos

+0

它的工作原理,雖然我不得不修改表達 – Daniel 2015-02-12 14:02:04

+0

太棒了!是的,某些表達式快捷鍵無法使用此方法。 – MarcosNC 2015-02-12 14:48:27

0

您好你正在嘗試做無法做到的,至少不會在目前的方式。

當你發送一個值,MEL像你想這樣做評估它作爲文字。 所以,真正的是不是真正的只是文字:

[flowVars.price == '1000']

你可以做的就是#[flowVars [ '價格']等於(有效載荷) ]有效載荷是列表的值。 請注意,在比較字符串時我使用了equals。

可能是,如果你提供一些更多的情況下,我們可以得到關於如何實現你想要