Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Try/Catch-like onException with Blueprint DSL

$
0
0
Hello,

I am analyzing the Exception handling capabilities of Apache Camel and might
have run into an inconsistency between the Java DSL and Blueprint, when
using onException on a route-processor level.

Due to several reasons, I do not want to use the doTry/doCatch handling, but
the onException constructs. For instance, to handle any exception from
"processor1" in the following route in Java DSL an onException statement is
used that handles (handled==true) the exception.

from("direct:in")
.onException(IOException.class)
.handled(true)
.process(excProcessor)
.end()
.process(processor1)

However, if there is a subsequent processor, e.g., "processor2", in the
route, which might throw IOExceptions, but shall not be handled using
"excProcessor", the following addition helps to "unregister" the handler for
subsequent processors:

from("direct:in")
.onException(IOException.class)
.handled(true)
.process(excProcessor)
.end()
.process(processor1)
*.onException(Exception.class)
.handled(false)
.end()
.process(processor2)*

Maybe that behavior is not intended (?), but if "processor2" throws an
IOException, the first onException clause with the "excProcessor" does not
get invoked.

How can the same behavior be ensured when using the Blueprint DSL? Directly
translated, the code from above would like the following in Blueprint.
However, now, the IOException is caught by the defined handler. The
"de-registration" does not happen.

<camelContext>
<route>
<from uri="direct:in"/>
<onException>
<exception>IOException</exception>
<handled>
<constant>true</constant>

...
</handled>
</onException>

...
*<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>false</constant>
</handled>
</onException>*

...
<to uri="direct:out"/>
</route>
</camelContext>

Do you know a way how to ensure the same behavior? Thank you in advance.

Best regards,
Daniel Ritter

Viewing all articles
Browse latest Browse all 5648

Trending Articles