骡子动态条件

时间:2015-02-09 11:06:45

标签: mule esb mule-studio

我定义了一个包含很少表达式的外部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>

在主要流程中我想评估这些表现,但结果总是如此。这是我到目前为止所做的。

<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>

有没有办法评估表达式列表?

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:0)

你好,你要做的事情是不能做到的,至少不是以现在的方式。

当您向MEL发送值时,您尝试将其评估为文字。 所以真实不是真的只是文字:

[flowVars.price ==&#39; 1000&#39;]

你可以做的是#[flowVars [&#39; price&#39;]。equals(payload)]其中payload是列表的值。 请注意我在比较字符串时使用了equals。

如果您提供更多背景信息,我们可以更好地了解如何实现您的目标

答案 1 :(得分:0)

您可以使用java组件评估表达式并访问eventContext.getMuleContext().getExpressionLanguage().evaluate方法。

HTH,马科斯