INT-3300: Fix MS ref Regression for i-c-adapter
JIRA: https://jira.springsource.org/browse/INT-3300 The change introduced by https://jira.springsource.org/browse/INT-3147 (Registration of `MessageSource<?>` as a bean with suffix `.source`) broke the case where `MessageSource<?>` is a reference to an existing bean. Add check to the `AbstractPollingInboundChannelAdapterParser` for the type of `source` and apply the appropriate logic. Conflicts: spring-integration-core/src/test/java/org/springframework/integration/config/ChannelAdapterParserTests.java Resolved.
This commit is contained in:
committed by
Gary Russell
parent
1eb501d272
commit
181b1b9c5f
@@ -20,6 +20,7 @@ import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -45,9 +46,19 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac
|
||||
BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(SourcePollingChannelAdapterFactoryBean.class);
|
||||
|
||||
String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext);
|
||||
String sourceBeanName = channelAdapterId + ".source";
|
||||
parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source);
|
||||
String sourceBeanName = null;
|
||||
|
||||
if (source instanceof BeanDefinition) {
|
||||
String channelAdapterId = this.resolveId(element, adapterBuilder.getRawBeanDefinition(), parserContext);
|
||||
sourceBeanName = channelAdapterId + ".source";
|
||||
parserContext.getRegistry().registerBeanDefinition(sourceBeanName, (BeanDefinition) source);
|
||||
}
|
||||
else if (source instanceof RuntimeBeanReference) {
|
||||
sourceBeanName = ((RuntimeBeanReference) source).getBeanName();
|
||||
}
|
||||
else {
|
||||
parserContext.getReaderContext().error("Wrong 'source' type: must be 'BeanDefinition' or 'RuntimeBeanReference'", source);
|
||||
}
|
||||
|
||||
adapterBuilder.addPropertyReference("source", sourceBeanName);
|
||||
adapterBuilder.addPropertyReference("outputChannel", channelName);
|
||||
|
||||
@@ -65,4 +65,12 @@
|
||||
|
||||
<inbound-channel-adapter channel="channelAdapter2Channel" ref="counter2" method="incrementAndGet"/>
|
||||
|
||||
<beans:bean id="testMessageSource" class="org.springframework.integration.config.TestSource"/>
|
||||
|
||||
<channel id="messageSourceRefChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<inbound-channel-adapter id="adapterWithMessageSourceRef" channel="messageSourceRefChannel" ref="testMessageSource"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -37,6 +38,7 @@ import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageDispatchingException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
@@ -294,8 +296,22 @@ public class ChannelAdapterParserTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSourceRef() {
|
||||
PollableChannel channel = this.applicationContext.getBean("messageSourceRefChannel", PollableChannel.class);
|
||||
|
||||
Message<?> message = channel.receive(5000);
|
||||
assertNotNull(message);
|
||||
assertEquals("test", message.getPayload());
|
||||
|
||||
MessageSource<?> testMessageSource = this.applicationContext.getBean("testMessageSource", MessageSource.class);
|
||||
SourcePollingChannelAdapter adapterWithMessageSourceRef = this.applicationContext.getBean("adapterWithMessageSourceRef", SourcePollingChannelAdapter.class);
|
||||
MessageSource<?> source = TestUtils.getPropertyValue(adapterWithMessageSourceRef, "source", MessageSource.class);
|
||||
assertSame(testMessageSource, source);
|
||||
}
|
||||
|
||||
public static class SampleBean {
|
||||
private String message = "hello";
|
||||
private final String message = "hello";
|
||||
|
||||
String getMessage() {
|
||||
return message;
|
||||
|
||||
Reference in New Issue
Block a user