Question

I have the following route defined using Spring DSL:

<camelContext id="myapp-camel-ctx" errorHandlerRef="deadLetterErrorHandler"
xmlns="http://camel.apache.org/schema/spring">
    <route id="myapp-camel-route">
        <from uri="timer://runOnce?repeatCount=1&amp;delay=10" />

        <to uri="bean:fizzBean?method=doFizz" />

        <!-- What I call the "Smooks processor" -->
        <to uri="smooks://my-smooks-config.xml" />

        <to uri="bean:buzzBean?method=doBuzz" />
    </route>
</camelContext>

<bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
    <property name="deadLetterUri" value="bean:errorCatcher" />
</bean>

<bean id="errorCatcher" class="com.me.myorg.myapp.ErrorCatcher">
    <property name="foo" value="BAR" />
</bean>

Sometimes, depending on the output (outbound message) of the fizzBean, the Smooks processor throws an exception and hangs the entire application. When it does this, I can see the exception being thrown in the app logs (it's actually a MySQL exception), but not sure how to wrap/catch it and continue processing. I thought that, given the ErrorCatcher setup above, the thrown MySQL exception would be handled and that the route would continue processing. Instead, I never see evidence in my app logs that the ErrorCatcher#handle method gets executed when these Smooks/MySQL exceptions are thrown.

Have I configured anything incorrectly here? Is there anything more I can do (either via the Smooks processor's URI configs or something else) to prevent exceptions being thrown from inside that processor from hanging the entire app? Thanks in advance!

Was it helpful?

Solution

It depends how the Smooks team have implemented their Camel component. The Camel error handler only kicks in, if an exception was thrown, which Camel can catch; or there was an exception explicit set on the Exchange using setException. If Smooks do not do that (maybe they catch the exception, and dont propagate that back to Camel), then Camel cannot detect that exception and react upon it.

If you want to see what goes on at runtime, you can enable the tracer http://camel.apache.org/tracer

Also mind that when you use a bean to handle the exception with the error handler. Then read this FAQ how to get access to the caused exception: http://camel.apache.org/why-is-the-exception-null-when-i-use-onexception.html

OTHER TIPS

your configuration seems to be correct, if you want to see that it works, you can change your handle methods signature as follows

public void handle(Exception exception, Exchange exchange) {
    System.out.println("Got Exception..."+exception.getMessage());
    System.out.println("Exchange is :"+exchange);
    }

now you can see the result on the console...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top