This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new e02cb28 CAMEL-16180: camel-mail - Make mail consumer re-connect on next poll if error opening mail folder. This makes the consumer more roboust. e02cb28 is described below commit e02cb28f4b797561ce2b7580206ca26037dd86a7 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Mar 24 19:02:41 2021 +0100 CAMEL-16180: camel-mail - Make mail consumer re-connect on next poll if error opening mail folder. This makes the consumer more roboust. --- .../apache/camel/component/mail/MailConsumer.java | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java index 85b989b..41443b8 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java @@ -144,8 +144,18 @@ public class MailConsumer extends ScheduledBatchPollingConsumer { } // ensure folder is open - if (!folder.isOpen()) { - folder.open(Folder.READ_WRITE); + try { + if (!folder.isOpen()) { + folder.open(Folder.READ_WRITE); + } + } catch (MessagingException e) { + // some kind of connectivity error, so lets re-create connection + String msg = "Error opening mail folder due to " + e.getMessage() + ". Will re-create connection on next poll."; + LOG.warn(msg); + if (LOG.isDebugEnabled()) { + LOG.debug(msg, e); + } + disconnect(); } try { @@ -193,22 +203,26 @@ public class MailConsumer extends ScheduledBatchPollingConsumer { // should we disconnect, the header can override the configuration boolean disconnect = getEndpoint().getConfiguration().isDisconnect(); if (disconnect) { - if (LOG.isDebugEnabled()) { - LOG.debug("Disconnecting from {}", getEndpoint().getConfiguration().getMailStoreLogInformation()); - } - try { - store.close(); - } catch (Exception e) { - LOG.debug("Could not disconnect from {}. This exception is ignored.", - getEndpoint().getConfiguration().getMailStoreLogInformation(), e); - } - store = null; - folder = null; + disconnect(); } return polledMessages; } + private void disconnect() { + if (LOG.isDebugEnabled()) { + LOG.debug("Disconnecting from {}", getEndpoint().getConfiguration().getMailStoreLogInformation()); + } + try { + store.close(); + } catch (Exception e) { + LOG.debug("Could not disconnect from {}. This exception is ignored.", + getEndpoint().getConfiguration().getMailStoreLogInformation(), e); + } + store = null; + folder = null; + } + @Override public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size();