Skip to content

Commit 5e9ec03

Browse files
andrebraitgaryrussell
authored andcommitted
GH-1156: Fix default error handler in javadoc
Delegate logging to an overridable method Fix typo, update copyright date range Fix while clause indentation and polish javadocs (cause param).
1 parent 7941596 commit 5e9ec03

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -449,7 +449,7 @@ public Object getMessageListener() {
449449

450450
/**
451451
* Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By
452-
* default there will be <b>no</b> ErrorHandler so that error-level logging is the only result.
452+
* default a {@link ConditionalRejectingErrorHandler} with its default list of fatal exceptions will be used.
453453
*
454454
* @param errorHandler The error handler.
455455
*/

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/ConditionalRejectingErrorHandler.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -161,18 +161,12 @@ public static class DefaultExceptionStrategy implements FatalExceptionStrategy {
161161
public boolean isFatal(Throwable t) {
162162
Throwable cause = t.getCause();
163163
while (cause instanceof MessagingException
164-
&& !(cause instanceof
165-
org.springframework.messaging.converter.MessageConversionException)
164+
&& !(cause instanceof org.springframework.messaging.converter.MessageConversionException)
166165
&& !(cause instanceof MethodArgumentResolutionException)) {
167166
cause = cause.getCause();
168167
}
169168
if (t instanceof ListenerExecutionFailedException && isCauseFatal(cause)) {
170-
if (this.logger.isWarnEnabled()) {
171-
this.logger.warn(
172-
"Fatal message conversion error; message rejected; "
173-
+ "it will be dropped or routed to a dead letter exchange, if so configured: "
174-
+ ((ListenerExecutionFailedException) t).getFailedMessage());
175-
}
169+
logFatalException((ListenerExecutionFailedException) t, cause);
176170
return true;
177171
}
178172
return false;
@@ -187,6 +181,22 @@ private boolean isCauseFatal(Throwable cause) {
187181
|| isUserCauseFatal(cause);
188182
}
189183

184+
/**
185+
* Log the fatal ListenerExecutionFailedException at WARN level, excluding stack
186+
* trace. Subclasses can override this behavior.
187+
* @param t the {@link ListenerExecutionFailedException}.
188+
* @param cause the root cause (skipping any general {@link MessagingException}s).
189+
* @since 2.2.4
190+
*/
191+
protected void logFatalException(ListenerExecutionFailedException t, Throwable cause) {
192+
if (this.logger.isWarnEnabled()) {
193+
this.logger.warn(
194+
"Fatal message conversion error; message rejected; "
195+
+ "it will be dropped or routed to a dead letter exchange, if so configured: "
196+
+ t.getFailedMessage());
197+
}
198+
}
199+
190200
/**
191201
* Subclasses can override this to add custom exceptions.
192202
* @param cause the cause

0 commit comments

Comments
 (0)