I'm trying to retrieve the stacktrace from the onException handler in Apache Camel:
<onException> <exception>java.lang.Exception</exception> <handled> <constant>true</constant> </handled> <setHeader headerName="exception"> <simple>${exception}</simple> </setHeader> </onException>
However, the above only shows the exception rather than the entire stacktrace.
I understand that Camel stores the caught exception as a property on the Exchange with the key: Exchange.EXCEPTION_CAUGHT, but how can this be retrieved from the camel context routes file ?
Using onException to handle known exceptions is a very powerful feature in Camel. You can mark the exception as being handled with the handle DSL, so the caller will not receive the caused exception as a response.
An Exchange is the message container holding the information during the entire routing of a Message received by a Consumer . During processing down the Processor chain, the Exchange provides access to the current (not the original) request and response Message messages.
Apache Camel ™ is a versatile open-source integration framework based on known Enterprise Integration Patterns. Camel empowers you to define routing and mediation rules in a variety of domain-specific languages (DSL, such as Java, XML, Groovy, Kotlin, and YAML).
Use exception.stacktrace to get the stacktrace. See the variables listed in the table at this page: http://camel.apache.org/simple
<simple>${exception.stacktrace}</simple>
There is also a ${exception.message} to refer to the exception message itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With