【问题标题】:Why does Mule flow default-exception-strategy have no effect?为什么 Mule flow default-exception-strategy 没有效果?
【发布时间】:2015-02-20 11:49:23
【问题描述】:

我正在使用 Mule 独立版 3.1.0,并且我有一个带有默认异常策略的流程。我的 fooImpl 类故意抛出异常,它的堆栈跟踪被吐到 mule 标准输出上 - ExceptionTransformer 没有被触发,我也没有收到任何电子邮件。如果我删除 default-exception-strategy 完全没有任何变化。

我希望它发送一封电子邮件并使用ExceptionTransformer 打印异常。我做错了什么?

<flow name="fooService">
    <inbound-endpoint address="http://localhost:63082/foo" exchange-pattern="request-response" />
    <cxf:jaxws-service serviceClass="com.example.mule.foo.fooImpl" />
    <component class="com.example.mule.foo.fooImpl" />
    <all>
        <file:outbound-endpoint path="/home/hodor/mule-standalone-3.1.0/old/" outputPattern="foo_#[function:datestamp].xml" />
        <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" connector-ref="stdioConnector" transformer-refs="objectToInputStream"/>
    </all>
    <default-exception-strategy>
        <vm:outbound-endpoint path="generalErrorHandler" exchange-pattern="one-way" />
    </default-exception-strategy>
</flow>

<flow name="generalErrorHandler">
    <vm:inbound-endpoint path="generalErrorHandler" exchange-pattern="one-way" />
    <custom-transformer class="com.example.mule.foo.ExceptionTransformer" />
    <all>
        <smtp:outbound-endpoint host="${error.smtp.host}" port="${error.smtp.port}" subject="${error.smtp.subject}" to="${error.smtp.to}" cc="${error.smtp.cc}" bcc="${error.smtp.bcc}" from="${error.smtp.sender}" />
    </all>
</flow>

此外,我尝试使用&lt;custom-exception-strategy class="com.arcusys.nkeservice.mule.dynasty.ExceptionTest"&gt; 而不是default-exception-strategy。然后ExceptionTest 在服务启动期间被实例化,但@override handleException 永远不会被调用。

我进入标准输出的强制异常是这样的:

WARN  2015-02-23 10:59:17,159 [[foo].connector.http.0.receiver.2] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://foo.com/}FooImplService#{http://foo.com/}getCase has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Component that caused exception is: org.mule.component.DefaultJavaComponent component for: SimpleFlowConstruct{fooService}. Message payload is of type: Object[]
    at org.mule.module.cxf.MuleInvoker.invoke(MuleInvoker.java:85)
    at org.mule.module.cxf.MuleJAXWSInvoker.invoke(MuleJAXWSInvoker.java:47)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:247)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113)
    at org.mule.module.cxf.CxfInboundMessageProcessor.sendToDestination(CxfInboundMessageProcessor.java:292)
    at org.mule.module.cxf.CxfInboundMessageProcessor.process(CxfInboundMessageProcessor.java:131)
    at org.mule.module.cxf.config.FlowConfiguringMessageProcessor.process(FlowConfiguringMessageProcessor.java:50)
    at org.mule.processor.AbstractInterceptingMessageProcessor.processNext(AbstractInterceptingMessageProcessor.java:75)
    at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:103)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.AbstractInterceptingMessageProcessor.processNext(AbstractInterceptingMessageProcessor.java:75)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessor.processNext(AbstractInterceptingMessageProcessor.java:75)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
    at org.mule.processor.AbstractInterceptingMessageProcessor.processNext(AbstractInterceptingMessageProcessor.java:75)
    at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:41)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:60)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.construct.AbstractFlowConstruct$1$1.process(AbstractFlowConstruct.java:107)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.AbstractInterceptingMessageProcessor.processNext(AbstractInterceptingMessageProcessor.java:75)
    at org.mule.processor.ExceptionHandlingMessageProcessor.process(ExceptionHandlingMessageProcessor.java:25)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:60)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:60)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:188)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:161)
    at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:148)
    at org.mule.transport.http.HttpMessageReceiver$HttpWorker.doRequest(HttpMessageReceiver.java:247)
    at org.mule.transport.http.HttpMessageReceiver$HttpWorker.processRequest(HttpMessageReceiver.java:206)
    at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:164)
    at org.mule.work.WorkerContext.run(WorkerContext.java:309)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.mule.component.ComponentException: Component that caused exception is: org.mule.component.DefaultJavaComponent component for: SimpleFlowConstruct{fooService}. Message payload is of type: Object[]
    at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:359)
    at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:89)
    at org.mule.component.AbstractJavaComponent.doInvoke(AbstractJavaComponent.java:80)
    at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:114)
    at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:52)
    at org.mule.component.AbstractComponent$1.process(AbstractComponent.java:236)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:60)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.component.AbstractComponent.process(AbstractComponent.java:147)
    at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:62)
    at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:90)
    at org.mule.module.cxf.CxfInboundMessageProcessor.processNext(CxfInboundMessageProcessor.java:334)
    at org.mule.module.cxf.MuleInvoker.invoke(MuleInvoker.java:80)
    ... 49 more
Caused by: java.io.IOException: Test IOException
    at com.foo.FooImpl.getCase(FooImpl.java:240)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.mule.model.resolvers.AbstractEntryPointResolver.invokeMethod(AbstractEntryPointResolver.java:151)
    at org.mule.model.resolvers.MethodHeaderPropertyEntryPointResolver.invoke(MethodHeaderPropertyEntryPointResolver.java:112)
    at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:39)
    at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:350)
    ... 63 more

【问题讨论】:

  • 想一想,如果您将&lt;smtp:outbound-endpoint... 移动到&lt;default-exception-strategy&gt; 而不是将其置于不同的流程中会发生什么?
  • 您能否包含发生这种情况时获得的日志?这将有助于我们更好地审查您的问题。
  • @AndersR.Bystrup 可悲的是没有区别。
  • 为了它的价值,我尝试在 Mule 3.5.1 上运行您的示例(我只有一个现成可用的),并且正如您所期望的那样工作......
  • @Nenotlep Mule 3.1.0 已经有 4 年多了:是时候升级了(至少升级到 3.1.3,请参阅下面 Ryan 的回答)。

标签: java web-services cxf mule jax-ws


【解决方案1】:
【解决方案2】:

您必须在流程内部使用来捕获异常并执行通知。

<flow name="fooService">
    <inbound-endpoint address="http://localhost:63082/foo" exchange-pattern="request-response" />
    <cxf:jaxws-service serviceClass="com.example.mule.foo.fooImpl" />
    <component class="com.example.mule.foo.fooImpl" />
    <all>
        <file:outbound-endpoint path="/home/hodor/mule-standalone-3.1.0/old/" outputPattern="foo_#[function:datestamp].xml" />
        <stdio:outbound-endpoint system="OUT" exchange-pattern="one-way" connector-ref="stdioConnector" transformer-refs="objectToInputStream"/>
    </all>
    <catch-exception-strategy>
        <vm:outbound-endpoint path="generalErrorHandler" exchange-pattern="one-way" />
    </catch-exception-strategy>
</flow>

希望这会有所帮助。

【讨论】:

  • 您好,谢谢您的回答。我没有 -1 你,但我确实尝试过;我无法使用该集部署我的应用程序,我得到:Eexception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'catch-exception-strategy'. One of '{"http://.../core":abstract-message-processor, "http://.../core":abstract-outbound-endpoint, "http://.../core":response, "http://.../core":abstract-exception-strategy, "http://.../core":threading-profile}' is expected.
  • @DownVoter。欢迎发表评论。
  • 因为 catch-exception-strategy 在 v3.1.x 中不可用。 catch-exception-strategy 相对较新,默认异常策略在 v3.3.x 之前是正确的
  • catch-exception-strategy 仅可从 Mule 3.3 IIRC 获得(可能导致投票失败)。
  • 感谢您的澄清。我没有检查问题中的 Mule 版本。
【解决方案3】:

如前所述,您需要使用捕获异常策略,默认策略只会记录异常。此外,您可以将捕获异常策略定义为全局异常策略,而不是使用 VM 出站端点到达其他流中的错误处理程序。你可以找到更多关于here 的信息。

【讨论】:

  • 我试过了,但似乎不支持 catch-exception-strategy,我得到一个异常说 Invalid content was found starting with element 'catch-exception-strategy'。请注意,我使用的是 Mule 3.1.0。
  • 我没有 -1 你。
  • 您是否尝试过在 vm 出站端点之前和 vm 入站端点之后仅使用一个简单的日志记录组件来查看异常策略是否实际上正在执行内部消息处理器?
  • 我尝试在inbound-endpointcxf:jaxws-servicecomponent 之后添加一个记录器语句。我可以看到前两个,但看不到第三个!还在许多其他地方添加了记录器,但它们也从不开火。
  • vm:outbound-endpoint 之前的记录器不显示?在vm:inbound-endpoint 之后呢?我对 mule 3.1.0 不是很熟悉,但是查看 mule-hello-example 我会尝试将 vm:inbound-endpoint 的交换模式配置为请求-响应:&lt;vm:inbound-endpoint path="generalErrorHandler" exchange-pattern="request-response"/&gt;
【解决方案4】:

使用下面作为您的流程的基于选择的异常策略的一部分
<choice-exception-strategy> <catch-exception-strategy when="#[exception.causedBy(java.lang.Exception)]" doc:name="Catch Exception Strategy"> <vm:outbound-endpoint path="generalErrorHandler" exchange-pattern="one-way" /> </catch-exception-strategy></choice-exception-strategy>

【讨论】:

  • 嗨!谢谢,但我试过了,但我得到了Invalid content was found starting with element 'choice-exception-strategy'. 我没有 -1 你虽然。
猜你喜欢
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-09
  • 1970-01-01
  • 2015-05-31
  • 2021-04-17
相关资源
最近更新 更多