Skip to content

Commit 887a089

Browse files
artembilangaryrussell
authored andcommitted
Fix Messaging Annotations for ReplyProdMHWrapper
To ensure advice-chain applicability the provided plain `MessageHandler` is wrapped into a `ReplyProducingMessageHandlerWrapper` with its particular `.wrapper` bean name. When we build a graph for integration components, we use a `componentName` from the `IntegrationObjectSupport` to represent a node for endpoint in the graph. In most cases the component name is an endpoint id around a `MessageHandler` * Populate the missed component name in a `ReplyProducingMessageHandlerWrapper` in the `AbstractMethodAnnotationPostProcessor` so nodes in the graph has a proper name for their endpoint in the application context
1 parent cf7f2df commit 887a089

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.springframework.integration.channel.DirectChannel;
5555
import org.springframework.integration.channel.MessagePublishingErrorHandler;
5656
import org.springframework.integration.config.IntegrationConfigUtils;
57+
import org.springframework.integration.context.IntegrationObjectSupport;
5758
import org.springframework.integration.context.Orderable;
5859
import org.springframework.integration.endpoint.AbstractEndpoint;
5960
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
@@ -164,6 +165,11 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
164165
&& StringUtils.hasText(MessagingAnnotationUtils.endpointIdValue(method))) {
165166
handlerBeanName = handlerBeanName + ".wrapper";
166167
}
168+
if (handler instanceof IntegrationObjectSupport) {
169+
((IntegrationObjectSupport) handler).setComponentName(
170+
handlerBeanName.substring(0,
171+
handlerBeanName.indexOf(IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX)));
172+
}
167173
this.beanFactory.registerSingleton(handlerBeanName, handler);
168174
handler = (MessageHandler) this.beanFactory.initializeBean(handler, handlerBeanName);
169175
if (handler instanceof DisposableBean && this.disposables != null) {
@@ -396,11 +402,11 @@ protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint,
396402

397403
if (StringUtils.hasText(ref)) {
398404
Assert.state(!StringUtils.hasText(triggerRef)
399-
&& !StringUtils.hasText(executorRef)
400-
&& !StringUtils.hasText(cron)
401-
&& !StringUtils.hasText(fixedDelayValue)
402-
&& !StringUtils.hasText(fixedRateValue)
403-
&& !StringUtils.hasText(maxMessagesPerPollValue), // NOSONAR boolean complexity
405+
&& !StringUtils.hasText(executorRef)
406+
&& !StringUtils.hasText(cron)
407+
&& !StringUtils.hasText(fixedDelayValue)
408+
&& !StringUtils.hasText(fixedRateValue)
409+
&& !StringUtils.hasText(maxMessagesPerPollValue), // NOSONAR boolean complexity
404410
"The '@Poller' 'ref' attribute is mutually exclusive with other attributes.");
405411
pollerMetadata = this.beanFactory.getBean(ref, PollerMetadata.class);
406412
}

spring-integration-core/src/test/java/org/springframework/integration/endpoint/BeanNameTests.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
package org.springframework.integration.endpoint;
1818

19-
import org.junit.Test;
20-
import org.junit.runner.RunWith;
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import org.junit.jupiter.api.Test;
2122

2223
import org.springframework.beans.factory.annotation.Autowired;
2324
import org.springframework.beans.factory.annotation.Qualifier;
@@ -31,20 +32,23 @@
3132
import org.springframework.integration.config.EnableIntegrationManagement;
3233
import org.springframework.integration.core.MessageSource;
3334
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
35+
import org.springframework.integration.handler.ReplyProducingMessageHandlerWrapper;
3436
import org.springframework.messaging.Message;
3537
import org.springframework.messaging.MessageHandler;
3638
import org.springframework.test.annotation.DirtiesContext;
37-
import org.springframework.test.context.junit4.SpringRunner;
39+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3840

3941
import io.micrometer.core.instrument.MeterRegistry;
4042
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
4143

4244
/**
4345
* @author Gary Russell
46+
* @author Artem Bilan
47+
*
4448
* @since 5.0.4
4549
*
4650
*/
47-
@RunWith(SpringRunner.class)
51+
@SpringJUnitConfig
4852
@DirtiesContext
4953
public class BeanNameTests {
5054

@@ -75,6 +79,10 @@ public class BeanNameTests {
7579
@Qualifier("eipBean2.handler")
7680
private MessageHandler eipBean2Handler;
7781

82+
@Autowired
83+
@Qualifier("eipBean2.handler.wrapper")
84+
private ReplyProducingMessageHandlerWrapper eipBean2HandlerWrapper;
85+
7886
@SuppressWarnings("unused")
7987
@Autowired
8088
private SourcePollingChannelAdapter eipMethodSource;
@@ -95,7 +103,7 @@ public class BeanNameTests {
95103

96104
@Test
97105
public void contextLoads() {
98-
106+
assertThat(this.eipBean2HandlerWrapper.getComponentName()).isEqualTo("eipBean2");
99107
}
100108

101109
@Configuration

0 commit comments

Comments
 (0)