Question:
I am developing a sample route- FROM: SOURCE ENDPOINT URI
- TO: TRANS ENDPOINT URI // Error or Exception occurred at this TRANS endpoint
- TO: TARGET ENDPOINT URI
Now I want to catch the Error Occured endpoint and pass it to my processor.
Could anyone please help me with this?
Answer:
You can use exchange properties:- CamelFailureEndpoint
- example xml-dsl:
<exchangeProperty>CamelFailureEndpoint</exchangeProperty>
- example java:
exchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class);
- example xml-dsl:
- CamelToEndpoint
- example xml-dsl:
<exchangeProperty>CamelToEndpoint</exchangeProperty>
- example java:
exchange.getProperty(Exchange.TO_ENDPOINT, String.class)
- example xml-dsl:
The first one should print uri for the consumer endpoint (from) that failed and the second one should show the previously called producer (to) endpoint.
One handy way to debug contexts of an failed exchange is to use:
<to uri="log:loggerName?showAll=true" />
This will log all exchange properties, headers, body and exception which can help to understand what information is available within exchange. Be careful where you use it as it might also log secrets and passwords if they’re within the exchange so better use it only locally during development.
For more information you’d probably need to access CamelMessageHistory exchange property through processor, bean or something.
If you have better answer, please add a comment about this, thank you!