【发布时间】:2015-07-02 13:26:00
【问题描述】:
如果用户凭据发生更改,我想停止路由,为此我想处理 javax.mail.AuthenticationFailedException.class 但这不起作用:
from(_getImapSentURL(emailConfiguration)).routeId(routeIdSent)
.onException(javax.mail.AuthenticationFailedException.class)
.process(new EmailErrorHandler()).end()
.process(new EmailContentSentProcessor(user, filterSent));
和错误处理器
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");
}
}
在控制台中我得到了这个异常,但它没有被处理。
错在哪里?
解决办法:
将参数添加到端点 URL consumer.bridgeErrorHandler=true
在路由构建器中添加异常处理程序
onException(Exception.class)
.log("Exception occurred due: ${exception.message}")
.bean(new EmailConsumerExceptionHandler(), "handleException").handled(true)
.end();
实现ExceptionHandler
此外,如果您将 handle(..) 设置为 true,您只能通过这种方式访问异常
Exception cause = originalExchange.getProperty(
Exchange.EXCEPTION_CAUGHT, Exception.class);
【问题讨论】:
标签: java apache-camel