Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 处理apachecamel使用者错误_Java_Apache Camel - Fatal编程技术网

Java 处理apachecamel使用者错误

Java 处理apachecamel使用者错误,java,apache-camel,Java,Apache Camel,如果用户凭据发生更改,我想停止路由,为此我想处理javax.mail.AuthenticationFailedException.class,但这不起作用: from(_getImapSentURL(emailConfiguration)).routeId(routeIdSent) .onException(javax.mail.AuthenticationFailedException.class) .process(new EmailError

如果用户凭据发生更改,我想停止路由,为此我想处理
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
另外,如果将
句柄(…)
设置为true,则只能通过这种方式访问异常

Exception cause = originalExchange.getProperty(
            Exchange.EXCEPTION_CAUGHT, Exception.class);

参考

这就像鸡和蛋一样。驼峰错误处理程序会在您有有效消息要路由时做出反应,然后在路由过程中发生一些错误

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

但是您可以打开一个选项,用Camels错误处理程序连接消费者。你可以从这里找到更多的细节:以及它所指的链接