INT-3672: Fix IdempotentReceiver for MH @Beans
JIRA: https://jira.spring.io/browse/INT-3672 Previously the `IdempotentReceiverInterceptor` has been applied only for the `MessageHandler`s which were registered with `.handler` suffix. Rework `IdempotentReceiverAutoProxyCreatorInitializer` and `IdempotentReceiverAutoProxyCreator` to get deal with **direct** `MessageHandler`s which can be resulted from `@Bean` methods. Use the `MessageHandler` real bean name instead of `endpoint pattern` in that case **Cherry-pick to 4.1.x**
This commit is contained in:
committed by
Gary Russell
parent
056b17aaa7
commit
f686c21b00
@@ -62,8 +62,7 @@ class IdempotentReceiverAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||
for (Map.Entry<String, List<String>> entry : this.idempotentEndpoints.entrySet()) {
|
||||
List<String> mappedNames = entry.getValue();
|
||||
for (String mappedName : mappedNames) {
|
||||
String pattern = mappedName + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
|
||||
if (isMatch(pattern, beanName)) {
|
||||
if (isMatch(mappedName, beanName)) {
|
||||
DefaultBeanFactoryPointcutAdvisor idempotentReceiverInterceptor
|
||||
= new DefaultBeanFactoryPointcutAdvisor();
|
||||
idempotentReceiverInterceptor.setAdviceBeanName(entry.getKey());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,8 +28,10 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
import org.springframework.core.type.StandardMethodMetadata;
|
||||
import org.springframework.integration.annotation.IdempotentReceiver;
|
||||
import org.springframework.integration.handler.advice.IdempotentReceiverInterceptor;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -66,7 +68,8 @@ public class IdempotentReceiverAutoProxyCreatorInitializer implements Integratio
|
||||
String[] endpoints = StringUtils.tokenizeToStringArray(mapping, ",");
|
||||
for (String endpoint : endpoints) {
|
||||
Map<String, String> idempotentEndpoint = new ManagedMap<String, String>();
|
||||
idempotentEndpoint.put(beanName, beanFactory.resolveEmbeddedValue(endpoint));
|
||||
idempotentEndpoint.put(beanName,
|
||||
beanFactory.resolveEmbeddedValue(endpoint) + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX);
|
||||
idempotentEndpointsMapping.add(idempotentEndpoint);
|
||||
}
|
||||
}
|
||||
@@ -78,12 +81,17 @@ public class IdempotentReceiverAutoProxyCreatorInitializer implements Integratio
|
||||
Object value = beanMethod.getAnnotationAttributes(annotationType).get("value");
|
||||
if (value != null) {
|
||||
String[] interceptors = (String[]) value;
|
||||
/*
|
||||
MessageHandler beans, populated from @Bean methods, have a complex id,
|
||||
including @Configuration bean name, method name and the Messaging annotation name.
|
||||
The following pattern matches the bean name, regardless of the annotation name.
|
||||
*/
|
||||
String endpoint = beanDefinition.getFactoryBeanName() + "." + beanName + ".*";
|
||||
String endpoint = beanName;
|
||||
if (!MessageHandler.class.isAssignableFrom(
|
||||
((StandardMethodMetadata) beanMethod).getIntrospectedMethod().getReturnType())) {
|
||||
/*
|
||||
MessageHandler beans, populated from @Bean methods, have a complex id,
|
||||
including @Configuration bean name, method name and the Messaging annotation name.
|
||||
The following pattern matches the bean name, regardless of the annotation name.
|
||||
*/
|
||||
endpoint = beanDefinition.getFactoryBeanName() + "." + beanName +
|
||||
".*" + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
|
||||
}
|
||||
for (String interceptor : interceptors) {
|
||||
Map<String, String> idempotentEndpoint = new ManagedMap<String, String>();
|
||||
idempotentEndpoint.put(interceptor, endpoint);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -106,7 +106,7 @@ public class IdempotentReceiverParserTests {
|
||||
List<String> endpoints = idempotentEndpoints.get("selectorInterceptor");
|
||||
assertNotNull(endpoints);
|
||||
assertFalse(endpoints.isEmpty());
|
||||
assertTrue(endpoints.contains("foo"));
|
||||
assertTrue(endpoints.contains("foo.handler"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,7 +124,7 @@ public class IdempotentReceiverParserTests {
|
||||
List<String> endpoints = idempotentEndpoints.get("strategyInterceptor");
|
||||
assertNotNull(endpoints);
|
||||
assertFalse(endpoints.isEmpty());
|
||||
assertTrue(endpoints.contains("foo"));
|
||||
assertTrue(endpoints.contains("foo.handler"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,8 +142,8 @@ public class IdempotentReceiverParserTests {
|
||||
List<String> endpoints = idempotentEndpoints.get("expressionInterceptor");
|
||||
assertNotNull(endpoints);
|
||||
assertFalse(endpoints.isEmpty());
|
||||
assertTrue(endpoints.contains("foo"));
|
||||
assertTrue(endpoints.contains("bar*"));
|
||||
assertTrue(endpoints.contains("foo.handler"));
|
||||
assertTrue(endpoints.contains("bar*.handler"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user