如何捕捉出现在ImapMailReceiver中的AuthenticationFailedException。

huangapple go评论102阅读模式
英文:

How to catch AuthenticationFailedException that appeared in ImapMailReceiver

问题

private IntegrationFlowRegistration getIntegrationFlowRegistration(){
    IntegrationFlow flow = IntegrationFlows
                .from(Mail.imapIdleAdapter(createImapMailReceiver(imapUrl))
                        .autoStartup(true)
                )
                .handle(System.out::println)
                .get();
    return this.flowContext.registration(flow).register();
}

我为不同的客户动态创建IntegrationFlowRegistration有时候凭据是不正确的我想捕捉AuthenticationFailedException并将其记录但找不到方法来捕捉它请您能否给我一个提示说明如何实现我已阅读了DSL文档但未找到相应的方法或示例
英文:
private IntegrationFlowRegistration getIntegrationFlowRegistration(){
  IntegrationFlow flow = IntegrationFlows
            .from(Mail.imapIdleAdapter(createImapMailReceiver(imapUrl))
                    .autoStartup(true)
            )
            .handle(System.out::println)
            .get();
    return this.flowContext.registration(flow).register();

}

I create dynamically IntegrationFlowRegistration for different customers and sometimes credentials are incorrect. I would like to catch AuthenticationFailedException and log it but can't find a way to catch it. Could you please give me a hint of how it can't be done? I read DSL documentation but didn't find a way or good example there.

答案1

得分: 1

添加一个ApplicationListener<ImapIdleExceptionEvent> bean,或者一个接收该事件类型的@EventListener方法。

@EventListener
public void imap(ImapIdleExceptionEvent event) {
...
}

https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#imap-idle-and-lost-connections

从3.0版本开始,IMAP空闲适配器在发生异常时会发出应用程序事件(特别是ImapIdleExceptionEvent实例),从而允许应用程序检测并对这些异常采取措施。您可以通过使用<int-event:inbound-channel-adapter>或配置为接收ImapIdleExceptionEvent或其超类之一的任何ApplicationListener来获取这些事件。

英文:

Add an ApplicationListener&lt;ImapIdleExceptionEvent&gt; bean, or an @EventListener method that receives that event type.

@EventListener
public void imap(ImapIdleExceptionEvent event) {
...
}

https://docs.spring.io/spring-integration/docs/current/reference/html/mail.html#imap-idle-and-lost-connections

>Beginning with the 3.0 release, the IMAP idle adapter emits application events (specifically ImapIdleExceptionEvent instances) when exceptions occur. This allows applications to detect and act on those exceptions. You can obtain the events by using an &lt;int-event:inbound-channel-adapter&gt; or any ApplicationListener configured to receive an ImapIdleExceptionEvent or one of its super classes.

huangapple
  • 本文由 发表于 2020年10月26日 22:55:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64539555.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定