骡子:进程表达式评估器

时间:2012-07-12 14:56:01

标签: mule

我正在尝试在我的流程中使用表达式#[process:processName:valueToProcess]

这是我的流程配置:

<flow name="exampleFlow">
  <quartz:inbound-endpoint jobName="job1" cronExpression="0/5 * * * * ?" connector-ref="quartzConnector">
    <quartz:event-generator-job>
      <quartz:payload>foo</quartz:payload>
    </quartz:event-generator-job>
  </quartz:inbound-endpoint>

  <logger message="#[process:test:#[payload]]" level="INFO"/>
</flow>

<sub-flow name="test" doc:name="test">
  <component class="com.myComp.ComponentTest" doc:name="Java"/>
</sub-flow>

这是我的Java组件:

package com.myComp;

public class ComponentTest
{
  public String test(String s)
  {
    return s + "bar";
  }
}

在评估表达式#[process:test:#[payload]]时出现问题。它抛出了这个例外:

java.lang.NullPointerException
    at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:112)
    at org.mule.component.AbstractComponent.process(AbstractComponent.java:156)
    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.api.processor.MessageProcessors$LifecyleAwareMessageProcessorWrapper.process(MessageProcessors.java:114)
    at org.mule.expression.MessageProcessorExpressionEvaluator.evaluate(MessageProcessorExpressionEvaluator.java:87)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:273)
    at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:209)
    at org.mule.expression.DefaultExpressionManager$1.match(DefaultExpressionManager.java:399)
    at org.mule.util.TemplateParser.parse(TemplateParser.java:156)
    at org.mule.util.TemplateParser.parse(TemplateParser.java:133)
    at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:395)
    at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:379)
    at org.mule.api.processor.LoggerMessageProcessor.log(LoggerMessageProcessor.java:89)
    at org.mule.api.processor.LoggerMessageProcessor.process(LoggerMessageProcessor.java:71)
    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.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:111)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:158)
    at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:43)
    at org.mule.work.WorkerContext.run(WorkerContext.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

任何其他脚本组件都会发生同样的情况。 我猜它与我的组件生命周期有关,但我找不到让它工作的方法。 如果我用任何其他Mule处理器(例如logger,stringAppend)替换我的组件,它可以正常工作。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

当你说这是一个初始化问题时你是对的:由于任何原因,子流中的组件没有像它们在流中那样被初始化,即。这有效:

<flow name="test" doc:name="test">
  <component class="com.myComp.ComponentTest" doc:name="Java"/>
</flow>

我认为这是一个错误I reported it。请提出问题。

为了使用异步事件(如Quartz入站端点生成的事件),您需要将processingStrategy="synchronous"添加到被调用的流中以便同步调用,否则默认情况下它将异步调用(即使process:test:#[payload]期望同步响应)。这是Mule 3中一个众所周知的怪癖。

所以最终解决方案是:

<flow name="test" processingStrategy="synchronous" doc:name="test">
  <component class="com.myComp.ComponentTest" doc:name="Java"/>
</flow>