From 40ba72b84a7eb5dbd30f400b64f968cfb237e3d9 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 18 Oct 2018 17:39:52 -0400 Subject: [PATCH] INT-4545: Fix RPMHWrapper registration for ``@SA` JIRA: https://jira.spring.io/browse/INT-4545 Improve the logic in the `AbstractMethodAnnotationPostProcessor` to check for existing `MessageHandler` and be sure that we need to register a `ReplyProducingMessageHandlerWrapper` bean **Cherry-pick to 5.0.x** --- ...AbstractMethodAnnotationPostProcessor.java | 8 ++-- .../ReplyProducingMessageHandlerWrapper.java | 6 ++- .../configuration/EnableIntegrationTests.java | 40 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java index 3a20244c37..0dcfdacd3b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java @@ -135,9 +135,11 @@ public abstract class AbstractMethodAnnotationPostProcessor - * This class is used internally by Framework in cased when request-reply is important + * This class is used internally by Framework in cases when request-reply is important * and there is no other way to apply advice chain. *

* The lifecycle control is delegated to the {@code target} {@link MessageHandler}. @@ -39,6 +40,7 @@ public class ReplyProducingMessageHandlerWrapper extends AbstractReplyProducingM private final MessageHandler target; public ReplyProducingMessageHandlerWrapper(MessageHandler target) { + Assert.notNull(target, "'target' must not be null"); this.target = target; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java index df6f963dd7..3b620af2bf 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java @@ -40,6 +40,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -47,6 +48,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.apache.commons.logging.Log; import org.hamcrest.BaseMatcher; @@ -109,6 +111,7 @@ import org.springframework.integration.endpoint.MethodInvokingMessageSource; import org.springframework.integration.endpoint.PollingConsumer; import org.springframework.integration.expression.SpelPropertyAccessorRegistrar; import org.springframework.integration.gateway.GatewayProxyFactoryBean; +import org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.history.MessageHistoryConfigurer; import org.springframework.integration.json.JsonPropertyAccessor; @@ -718,6 +721,24 @@ public class EnableIntegrationTests { assertEquals(ClassUtils.getStaticMethod(TestSpelFunction.class, "bar", Object.class), testSpelFunction); } + @Autowired + private MessageChannel myHandlerChannel; + + @Autowired + private PollableChannel myHandlerSuccessChannel; + + @Test + public void testAdvicedServiceActivator() { + Date testDate = new Date(); + + this.myHandlerChannel.send(new GenericMessage<>(testDate)); + + Message receive = this.myHandlerSuccessChannel.receive(10_000); + + assertNotNull(receive); + assertEquals(testDate, receive.getPayload()); + } + @Configuration @ComponentScan @IntegrationComponentScan @@ -1124,6 +1145,25 @@ public class EnableIntegrationTests { return new SpelPropertyAccessorRegistrar(new JsonPropertyAccessor(), new EnvironmentAccessor()); } + @Bean + @ServiceActivator(inputChannel = "myHandlerChannel", adviceChain = "myHandlerAdvice") + public MessageHandler myHandler() { + return message -> { }; + } + + @Bean + public Advice myHandlerAdvice() { + ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice(); + advice.setOnSuccessExpressionString("payload"); + advice.setSuccessChannel(myHandlerSuccessChannel()); + return advice; + } + + @Bean + public QueueChannel myHandlerSuccessChannel() { + return new QueueChannel(); + } + } @Configuration