Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Fix duplicate error logging #465

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.handler.invocation.InvocableHandlerMethod;
import org.springframework.util.ClassUtils;
import org.springframework.util.comparator.ComparableComparator;
import org.springframework.validation.Errors;
Expand Down Expand Up @@ -233,7 +234,11 @@ protected void handleNoMatch(Set<MappingInformation> ts, String lookupDestinatio
@Override
protected void processHandlerMethodException(HandlerMethod handlerMethod,
Exception ex, Message<?> message) {
super.processHandlerMethodException(handlerMethod, ex, message);
InvocableHandlerMethod exceptionHandlerMethod = getExceptionHandlerMethod(
handlerMethod, ex);
if (exceptionHandlerMethod != null) {
super.processHandlerMethodException(handlerMethod, ex, message);
}
throw new MessagingException(
"An exception occurred while invoking the handler method", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,39 @@ public void getMappingForMethod_methodWithExpressionProducingMultipleQueueNames_
.containsAll(Arrays.asList("queueOne", "queueTwo"))).isTrue();
}

@Test
public void processHandlerMethodException_invocableHandlerMethodNotAvailable_errorMustNotBeLogged() {
// Arrange
StaticApplicationContext applicationContext = new StaticApplicationContext();
applicationContext.registerSingleton("sqsListenerWithoutMessageExceptionHandler",
SqsListenerWithoutMessageExceptionHandler.class);
applicationContext.registerBeanDefinition("queueMessageHandler",
getQueueMessageHandlerBeanDefinition());
applicationContext.refresh();
MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class);

LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
Logger log = logContext.getLogger(QueueMessageHandler.class);
log.setLevel(Level.ERROR);
log.addAppender(appender);
appender.setContext(log.getLoggerContext());

// Act
try {
messageHandler.handleMessage(MessageBuilder.withPayload("testContent")
.setHeader(QueueMessageHandler.LOGICAL_RESOURCE_ID, "receive")
.build());
}
catch (MessagingException e) {
// ignore
}

// Assert
assertThat(appender.list).isEmpty();
}

@SuppressWarnings("UnusedDeclaration")
private static class IncomingMessageHandler {

Expand Down Expand Up @@ -604,6 +637,14 @@ private String getLastReceivedMessage() {

}

private static class SqsListenerWithoutMessageExceptionHandler {

@SqsListener("receive")
public String receive(String value) {
return value.toUpperCase();
}
}

private static class IncomingMessageHandlerWithMultipleQueueNames {

private String lastReceivedMessage;
Expand Down