我定义了一个包含几个表达式的外部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>
有什么方法可以计算表达式列表吗?
如有任何帮助,我们将不胜感激。
您可以使用java组件并访问eventContext.getMuleContext().getExpressionLanguage().evaluate
方法来评估表达式。
HTH,Marcos
嗨,你想做的事情是做不到的,至少现在不行。
当将值发送到MEL时,就像尝试将其作为文字进行计算一样。所以真的不是真的只是字面意思:
[flowVars.price=="1000"]
您可以得到#[flowVars['price'].equals(payload)],其中payload是列表的值。请注意,在比较字符串时,我使用了equals。
如果你提供更多的上下文,我们可以更好地了解如何实现你想要的