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.

INT-3300: Get rid of Spring Boot dependency

Remove test case that introduced a cyclic dependency.
This commit is contained in:
Artem Bilan
2014-02-18 13:38:56 +02:00
committed by Gary Russell
parent 71f194a9b9
commit 6a840783e7
5 changed files with 38 additions and 56 deletions

View File

@@ -97,7 +97,6 @@ subprojects { subproject ->
servletApiVersion = '3.1.0'
smackVersion = '3.2.1'
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.3.0.M2'
springBootVersion = '1.0.0.RC1'
springDataMongoVersion = '1.1.1.RELEASE'
springDataRedisVersion = '1.1.1.RELEASE'
springGemfireVersion = '1.3.1.RELEASE'
@@ -229,9 +228,6 @@ project('spring-integration-core') {
compile("com.jayway.jsonpath:json-path:$jsonpathVersion", optional)
testCompile ("org.aspectj:aspectjweaver:$aspectjVersion")
testCompile ("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion") {
exclude group: 'org.springframework'
}
}
}

View File

@@ -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);

View File

@@ -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>

View File

@@ -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;
@@ -34,6 +35,7 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageDispatchingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
@@ -294,6 +296,20 @@ 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 final String message = "hello";

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.configuration.boot;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.integration.context.IntegrationContextUtils;
/**
* @author Artem Bilan
* @since 4.0
*/
public class IntegrationAutoConfigurationTests {
@Test
public void testIntegrationAutoConfiguration() {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Configuration.class);
assertTrue(applicationContext.containsBean(IntegrationContextUtils.CHANNEL_INITIALIZER_BEAN_NAME));
assertTrue(applicationContext.containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME));
assertTrue(applicationContext.containsBean(IntegrationContextUtils.MESSAGING_ANNOTATION_POSTPROCESSOR_NAME));
assertTrue(applicationContext.containsBean("jsonPath"));
assertFalse(applicationContext.containsBean("xpath"));
}
@EnableAutoConfiguration
public static class Configuration {
}
}