How to use a property variable inside a mule MEL expression?

TERACytE picture TERACytE · Jun 17, 2013 · Viewed 9.7k times · Source

I'm loading in various values via a property file using context:property-placeholder. I can use the properties for Spring injection and logging without error, but i'm receiving an exception when I try to evaluate them within a MEL expression:

<spring:beans>
    <spring:bean id="someId" class="com.myClass">
        <!-- This works just fine -->
        <spring:constructor-arg index="0" value="${myVariable}" />
    </spring:bean>
</spring:beans>

<flow name="myFlow">
    <!-- exception here -->
    <choice>
        <when expression="#[${myVariable} == 'setting1']">
            <logger message="setting1 selected" level="WARN"/>
        </when>
        <otherwise>
            <logger message="setting1 NOT selected" level="WARN"/>
        </otherwise>
    </choice>
</flow>

The error is:

org.mule.exception.DefaultMessagingExceptionStrategy: Caught exception in Exception Strategy: null
java.lang.NullPointerException
at org.mule.routing.filters.ExpressionFilter.getFullExpression(ExpressionFilter.java:140)

Any ideas on how I can check the value of an imported property within a MEL expression?

Here is the full stack:

ERROR 2013-06-17 12:36:52,114 [defaultHttpConnector.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: Caught exception in Exception Strategy: null
java.lang.NullPointerException
    at org.mule.routing.filters.ExpressionFilter.getFullExpression(ExpressionFilter.java:140)
    at org.mule.routing.filters.ExpressionFilter.accept(ExpressionFilter.java:104)
    at org.mule.routing.ChoiceRouter.selectProcessors(ChoiceRouter.java:35)
    at org.mule.routing.AbstractSelectiveRouter.process(AbstractSelectiveRouter.java:194)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:90)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:138)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:195)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:163)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:150)
    at org.mule.transport.vm.VMMessageReceiver.onCall(VMMessageReceiver.java:103)
    at org.mule.transport.vm.VMMessageDispatcher$1.doInTransaction(VMMessageDispatcher.java:90)
    at org.mule.transport.vm.VMMessageDispatcher$1.doInTransaction(VMMessageDispatcher.java:87)
    at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    at org.mule.transport.vm.VMMessageDispatcher.doSend(VMMessageDispatcher.java:93)
    at org.mule.transport.AbstractMessageDispatcher.process(AbstractMessageDispatcher.java:81)
    at org.mule.transport.AbstractConnector$DispatcherMessageProcessor.process(AbstractConnector.java:2553)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.endpoint.outbound.OutboundResponsePropertiesMessageProcessor.process(OutboundResponsePropertiesMessageProcessor.java:39)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.TransactionalInterceptingMessageProcessor$1.doInTransaction(TransactionalInterceptingMessageProcessor.java:49)
    at org.mule.processor.TransactionalInterceptingMessageProcessor$1.doInTransaction(TransactionalInterceptingMessageProcessor.java:46)
    at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    at org.mule.processor.TransactionalInterceptingMessageProcessor.process(TransactionalInterceptingMessageProcessor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:105)
    at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:44)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:99)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:56)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:66)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:87)
    at org.mule.endpoint.DefaultOutboundEndpoint.process(DefaultOutboundEndpoint.java:95)
    at org.mule.routing.outbound.AbstractOutboundRouter.sendRequestEvent(AbstractOutboundRouter.java:461)
    at org.mule.routing.outbound.AbstractOutboundRouter.sendRequest(AbstractOutboundRouter.java:167)
    at org.mule.routing.outbound.FilteringOutboundRouter.route(FilteringOutboundRouter.java:80)
    at org.mule.routing.outbound.OutboundPassThroughRouter.route(OutboundPassThroughRouter.java:71)
    at org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:102)
    at org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:99)
    at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:45)
    at org.mule.routing.outbound.AbstractOutboundRouter.process(AbstractOutboundRouter.java:107)
    at org.mule.component.DefaultInterfaceBinding.process(DefaultInterfaceBinding.java:45)
    at org.mule.component.BindingInvocationHandler.invoke(BindingInvocationHandler.java:95)

Answer

David Dossot picture David Dossot · Jun 17, 2013

You need to surround it with quotes, as it's a string:

<when expression="#['${myVariable}' == 'setting1']">

In pre-Mule 3.3.0, you should be able to use Groovy:

<when evaluator="groovy" expression="'${myVariable}' == 'setting1'">