简体   繁体   中英

Apache camel onException adding error details to the original message

I have added this exception handling to the camel route.

 .onException(BeanCreationException.class, ValidationException.class)
     .handled(true)
     .process(new OnExceptionProcessor())
     .to("errorQueue0").id("errorQueue")
     .end()
public class OnExceptionProcessor implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        exchange.getIn().setHeader("FailedBecause", cause.getMessage());
    }
}

When I read this message back from the error queue, I cannot find this header. any idea on how to add error details along with the original message to the error queue

This could be a context problem because you are in a processor that is called by the error handler .

As an alternative, you could return the String value to set in the header from your processor method . By the way, this also improves the testability of your Processor.

Then you can use this return value to set the header in the error handler route directly.

.setHeader("FailedBecause", method(new OnExceptionProcessor()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM