Reputation: 842
I want to stop route in case if user credentials changed, for this I want to handle javax.mail.AuthenticationFailedException.class
but this does not work:
from(_getImapSentURL(emailConfiguration)).routeId(routeIdSent)
.onException(javax.mail.AuthenticationFailedException.class)
.process(new EmailErrorHandler()).end()
.process(new EmailContentSentProcessor(user, filterSent));
and error processor
public class EmailErrorHandler implements Processor {
private static final long serialVersionUID = 1L;
Logger logger = Logger.getLogger(getClass());
@Override
public void process(Exchange exchange) throws Exception {
logger.info("handled");
}
}
In console I'm getting this exception but it's not handled.
Where is the mistake?
Solution:
Add param to endpoint URL consumer.bridgeErrorHandler=true
In route builder add exception handler
onException(Exception.class)
.log("Exception occurred due: ${exception.message}")
.bean(new EmailConsumerExceptionHandler(), "handleException").handled(true)
.end();
Implement ExceptionHandler
Also if you set handle(..)
to true you can access to exception only in this way
Exception cause = originalExchange.getProperty(
Exchange.EXCEPTION_CAUGHT, Exception.class);
in reffer to Apache camel documentation
Upvotes: 3
Views: 2685
Reputation: 55540
Its like a chicken and egg situation. The Camel error handler reacts when you have a valid message to route and then during routing some error happens.
But as the mail consumer cannot login then there is no valid message to route.
But you can turn on an option to bridge the consumer with Camels error handler. You can find more details from here: http://camel.apache.org/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.html and the links it refers to
Upvotes: 3