|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
36 | 36 | import org.springframework.integration.transaction.IntegrationResourceHolder;
|
37 | 37 | import org.springframework.integration.transaction.IntegrationResourceHolderSynchronization;
|
38 | 38 | import org.springframework.integration.transaction.TransactionSynchronizationFactory;
|
| 39 | +import org.springframework.lang.Nullable; |
39 | 40 | import org.springframework.messaging.MessagingException;
|
40 | 41 | import org.springframework.transaction.support.TransactionSynchronization;
|
41 | 42 | import org.springframework.transaction.support.TransactionSynchronizationManager;
|
@@ -200,22 +201,24 @@ private void callIdle() {
|
200 | 201 | }
|
201 | 202 | catch (Exception ex) {
|
202 | 203 | publishException(ex);
|
203 |
| - if (this.shouldReconnectAutomatically |
204 |
| - && ex.getCause() instanceof jakarta.mail.MessagingException messagingException) { |
205 |
| - |
206 |
| - //run again after a delay |
207 |
| - logger.info(messagingException, |
208 |
| - () -> "Failed to execute IDLE task. Will attempt to resubmit in " |
209 |
| - + this.reconnectDelay + " milliseconds."); |
210 |
| - delayNextIdleCall(); |
211 |
| - } |
212 |
| - else { |
213 |
| - logger.warn(ex, |
214 |
| - "Failed to execute IDLE task. " + |
215 |
| - "Won't resubmit since not a 'shouldReconnectAutomatically' " + |
216 |
| - "or not a 'jakarta.mail.MessagingException'"); |
217 |
| - break; |
| 204 | + if (this.shouldReconnectAutomatically) { |
| 205 | + jakarta.mail.MessagingException messagingException = |
| 206 | + getJakartaMailMessagingExceptionFromCause(ex.getCause()); |
| 207 | + |
| 208 | + if (messagingException != null) { |
| 209 | + //run again after a delay |
| 210 | + logger.info(messagingException, |
| 211 | + () -> "Failed to execute IDLE task. Will attempt to resubmit in " |
| 212 | + + this.reconnectDelay + " milliseconds."); |
| 213 | + delayNextIdleCall(); |
| 214 | + continue; |
| 215 | + } |
218 | 216 | }
|
| 217 | + logger.warn(ex, |
| 218 | + "Failed to execute IDLE task. " + |
| 219 | + "Won't resubmit since not a 'shouldReconnectAutomatically' " + |
| 220 | + "or not a 'jakarta.mail.MessagingException'"); |
| 221 | + break; |
219 | 222 | }
|
220 | 223 | }
|
221 | 224 | }
|
@@ -256,6 +259,21 @@ private void delayNextIdleCall() {
|
256 | 259 | }
|
257 | 260 | }
|
258 | 261 |
|
| 262 | + @Nullable |
| 263 | + private static jakarta.mail.MessagingException getJakartaMailMessagingExceptionFromCause(Throwable cause) { |
| 264 | + if (cause == null) { |
| 265 | + return null; |
| 266 | + } |
| 267 | + if (cause instanceof jakarta.mail.MessagingException messagingException) { |
| 268 | + return messagingException; |
| 269 | + } |
| 270 | + Throwable nextCause = cause.getCause(); |
| 271 | + if (cause == nextCause) { |
| 272 | + return null; |
| 273 | + } |
| 274 | + return getJakartaMailMessagingExceptionFromCause(nextCause); |
| 275 | + } |
| 276 | + |
259 | 277 | private class MessageSender implements Consumer<Object> {
|
260 | 278 |
|
261 | 279 | MessageSender() {
|
|
0 commit comments