Why does Mule flow default-exception-strategy have no effect?
Asked Answered
B

4

6

I'm using Mule standalone 3.1.0 and I have a flow with a default exception strategy. My fooImpl class throws an exception on purpose and its stacktrace gets vomited onto the mule stdout - ExceptionTransformer is not triggered and I get no email. If I remove the default-exception-strategy completely nothing at all changes.

I want it to send an email and print the exception with ExceptionTransformer. What am I doing wrong?

<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>

Further on, I tried to use <custom-exception-strategy class="com.arcusys.nkeservice.mule.dynasty.ExceptionTest"> instead of default-exception-strategy. Then ExceptionTest gets instantiated during service startup, but @override handleException never gets called.

My forced exception I get to stdout is like this:

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
Bogoch answered 20/2, 2015 at 11:49 Comment(6)
Just a thought, what happens if you move the <smtp:outbound-endpoint... into the <default-exception-strategy> rather than having it in a different flow?Kostival
Can you include the logs you're getting when this happens? This would help us review better what your issue is.Glendoraglendower
@AndersR.Bystrup Makes no difference sadly.Bogoch
@Glendoraglendower I added the stack trace that get print to stdout when my forced exception is thrown. Nothing else happens.Bogoch
For what it's worth, I tried running your example on Mule 3.5.1 (only one I had readily available), and that works just as you expect...Kostival
@Nenotlep Mule 3.1.0 is a little more than 4 years old: it's time to upgrade (at least to 3.1.3, see Ryan's answer below).Pirn
M
0

You have to use inside your flow to catch the exception and perform the notification.

<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>

Hope this helps.

Mensa answered 20/2, 2015 at 14:26 Comment(5)
Hey, thanks for the answer. I did not -1 you, but I did try this; I could not deploy my app with that set, I got: 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.Bogoch
@DownVoter. Care to comment.Mensa
because catch-exception-strategy was not available in v3.1.x. catch-exception-strategy is relatively new and default-exception-strategy is correct prior to v3.3.xZinck
catch-exception-strategy is only available from Mule 3.3 IIRC (perhaps that caused the downvote).Kostival
Thanks for the clarification. I didn't check the Mule verison in the question.Mensa
T
0

As mentioned, you need to use a catch exception strategy, the default one will just log the exception. Also, instead of using a VM outbound endpoint to reach the error handler in an other flow, you could define the catch exception strategy as a global exception strategy. You can find more information on all that here.

Tundra answered 20/2, 2015 at 21:7 Comment(6)
I tried that, but catch-exception-strategy does not seem to be supported, I get ab exception saying Invalid content was found starting with element 'catch-exception-strategy'. Please note that I'm on Mule 3.1.0.Bogoch
I didn't -1 you though.Bogoch
Have you tried using just a simple logging component before the vm outbound endpoint and after the vm inbound endpoint to see whether the exception strategy is actually executing the inner message processors or not?Tundra
I tried adding a logger statement after inbound-endpoint, cxf:jaxws-service and component. I can see the first two but never the 3rd! Also added loggers to a bunch of other places, but they never fire either.Bogoch
And a logger before the vm:outbound-endpoint does not show? What about after the vm:inbound-endpoint? I'm not very familiar with mule 3.1.0 but looking at mule-hello-example I'd try configuring the vm:inbound-endpoint's exchange pattern as request-response: <vm:inbound-endpoint path="generalErrorHandler" exchange-pattern="request-response"/>Tundra
Yeah, I tried a logger in both those places and they didn't show. I also tried request-response but alas, nothing happened :cBogoch
P
-2

use below as part of choice based exception strategy for your flow
<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>

Parisian answered 21/2, 2015 at 17:9 Comment(1)
Hi! Thanks, but I tried that, but I got Invalid content was found starting with element 'choice-exception-strategy'. I didn't -1 you though.Bogoch

© 2022 - 2024 — McMap. All rights reserved.