From f53942ef4c0a5ef922ca54c7da620cb60b750a09 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 7 Aug 2013 12:37:20 -0400 Subject: [PATCH] INT-3106 Fix Bogus Warning Logs INT-3007 introduced a warning log when advising a non-message handler class. However, the log was also emitted when other methods on a real MessageHandler were invoked. Suppress the message in these cases and improve the log by including the concrete class for the method rather than the interface on which the method is declared. --- .../handler/advice/AbstractRequestHandlerAdvice.java | 10 +++++++--- .../handler/advice/AdvisedMessageHandlerTests.java | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java index 8d8ae705b7..b36f4a8c2e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/AbstractRequestHandlerAdvice.java @@ -50,11 +50,15 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp boolean isMessageMethod = (method.getName().equals("handleRequestMessage") || method.getName().equals("handleMessage")) && (arguments.length == 1 && arguments[0] instanceof Message); + Object invocationThis = invocation.getThis(); if (!isMessageMethod) { - if (logger.isWarnEnabled()) { + boolean isMessageHandler = invocationThis != null + && MessageHandler.class.isAssignableFrom(invocationThis.getClass()); + if (!isMessageHandler && logger.isWarnEnabled()) { + String clazzName = invocationThis == null ? method.getDeclaringClass().getName() : invocationThis.getClass().getName(); logger.warn("This advice " + this.getClass().getName() + " can only be used for MessageHandlers; an attempt to advise method '" + method.getName() + - "' in '" + method.getDeclaringClass().getName() + "' is ignored"); + "' in '" + clazzName + "' is ignored"); } return invocation.proceed(); } @@ -91,7 +95,7 @@ public abstract class AbstractRequestHandlerAdvice extends IntegrationObjectSupp throw new ThrowableHolderException(e); } } - }, invocation.getThis(), message); + }, invocationThis, message); } catch (Exception e) { if (e instanceof ThrowableHolderException) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java index 086db65776..3a5abba80b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/AdvisedMessageHandlerTests.java @@ -851,7 +851,8 @@ public class AdvisedMessageHandlerTests { assertFalse(called.get()); assertNotNull(logMessage.get()); assertTrue(logMessage.get().endsWith("can only be used for MessageHandlers; " + - "an attempt to advise method 'call' in 'java.util.concurrent.Callable' is ignored")); + "an attempt to advise method 'call' in " + + "'org.springframework.integration.endpoint.AbstractPollingEndpoint$1' is ignored")); } public void filterDiscardNoAdvice() {