Apache Camel :捕获身份验证失败错误

ruoxqz4g  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(126)

我有一个由Apache Camel监视电子邮件的路由。如果用户名或密码被更改。我想在监视系统中显示一条消息给用户关于此更改-如身份验证失败...
目前我还不能捕捉到路由中的错误。我不知道我做错了什么。使用下面的代码,我从来没有进入doCatch块。
如何在doCatch块中捕获身份验证失败的错误?

错误:

在控制台中引发以下错误

> 2022-04-18 11:01:01 [Camel (camel-1) thread #6 - imaps://imap.web.de]
> WARN  o.a.c.component.mail.MailConsumer - Consumer
> Consumer[imaps://imap.web.de?closeFolder=false&disconnect=false&password=xxxxxx&subject=FK100+-+daily&unseen=true&username=XXXXX]
> failed polling endpoint:
> imaps://imap.web.de?closeFolder=false&disconnect=false&password=xxxxxx&subject=FK100+-+daily&unseen=true&username=XXXXX.
> Will try again at next poll. Caused by:
> [javax.mail.AuthenticationFailedException - authentication failed]
> javax.mail.AuthenticationFailedException: authentication failed   at
> com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:708)   at
> javax.mail.Service.connect(Service.java:364)  at
> org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:603)
>   at
> org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:128)
>   at
> org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:202)
>   at
> org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollConsumer.java:116)
>   at
> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
>   at
> java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
>   at
> java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
>   at
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
>   at
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
>   at java.base/java.lang.Thread.run(Thread.java:833)

代码:

@Component
public class EmailPollingRoute extends RouteBuilder {

    static final Logger LOGGER = LoggerFactory.getLogger(EmailPollingRoute.class);

    @Override
    public void configure() throws Exception {

        //@formatter:off
        from("direct:processPollingEmail")
        .routeId("routeId_EmailPollingRoute") 
        .doTry()
          .log("doTry")
          .pollEnrich("imaps://imap.web.de"
                + "?username=XXXXX&"
                + "password=XXXXX&"
                + "unseen=true&"
                + "closeFolder=false&"
                + "disconnect=false&"
                + "subject=FK100 - daily")

        .doCatch(Exception.class)
            .process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    LOGGER.info("EmailPollingRoute - doCatch - authentication failed");
                    //final Throwable ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
                    //exchange.getIn().setBody(ex.getMessage());
                }
            })

        .doFinally()
             .log("doFinally")
        .endDoTry();
    }
}
cyvaqqii

cyvaqqii1#

因此,我可以在将以下属性添加到url bridgeErrorHandler=true后捕获错误

.pollEnrich("imaps://imap.web.de"
                + "?username=XXXXX&"
                + "password=XXXXX&"
                + "unseen=true&"
                + "closeFolder=false&"
                + "disconnect=false&"
                +"bridgeErrorHandler=true&"
                + "subject=FK100 - daily")

相关问题