处理apache骆驼消费者的错误

时间:2015-07-02 13:26:01

标签: java apache-camel

如果用户凭据发生更改,我想停止路由,为此我想处理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");
    }
}

在控制台中我得到了这个例外,但是没有处理。

错误在哪里?

解决方案:

将param添加到端点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);

Apache camel documentation

1 个答案:

答案 0 :(得分:2)

它像鸡蛋和鸡蛋的情况。当您有一条有效的路由消息时,Camel错误处理程序会做出反应,然后在路由过程中会发生一些错误。

但是由于邮件消费者无法登录,因此没有有效的消息要路由。

但您可以启用一个选项来使用Camels错误处理程序来桥接使用者。您可以在此处找到更多详细信息: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及其引用的链接