0

我正在尝试#[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)替换我的组件,它就可以正常工作。

任何帮助将不胜感激!

4

1 回答 1

0

当您说这是一个初始化问题时,您是对的:出于任何原因,子流中的组件的初始化方式与它们在流中的初始化方式不同,即。这有效:

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

我相信这是一个错误,因此我报告了它。请为这个问题点赞。

要使用异步事件进行此操作,例如 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>
于 2012-07-12T16:48:49.880 回答