ChannelFactory is no longer tied to the MessageBus. Instead it will be discovered based on the bean name ("channelFactory"). The DefaultChannelFactoryBean no longer creates proxies. This also fixes INT-322.
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.integration.channel.config;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -71,7 +67,7 @@ public class ChannelParserTests {
|
||||
MessageChannel channel = (MessageChannel) context.getBean("queueChannelByDefault");
|
||||
//called to initialize the channel instance
|
||||
channel.getName();
|
||||
assertEquals(QueueChannel.class, extractProxifiedChannel(channel).getClass());
|
||||
assertEquals(QueueChannel.class, channel.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,14 +220,4 @@ public class ChannelParserTests {
|
||||
assertTrue(threwException);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MessageChannel extractProxifiedChannel (Object channelProxy) {
|
||||
InvocationHandler handler = Proxy.getInvocationHandler(channelProxy);
|
||||
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
|
||||
AtomicReference<MessageChannel> reference =
|
||||
(AtomicReference<MessageChannel>) handlerAccessor.getPropertyValue("targetChannelReference");
|
||||
return reference.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.channel.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class DefaultChannelParserTests {
|
||||
public void testDefaultChannel() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("defaultChannelParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("defaultChannel");
|
||||
assertTrue(StubChannel.class.isAssignableFrom(ChannelParserTests.extractProxifiedChannel(channel).getClass()));
|
||||
assertEquals(StubChannel.class, channel.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus channel-factory="stubChannelFactory"/>
|
||||
|
||||
<beans:bean id="stubChannelFactory" class="org.springframework.integration.channel.factory.StubChannelFactory"/>
|
||||
<beans:bean id="channelFactory" class="org.springframework.integration.channel.factory.StubChannelFactory"/>
|
||||
|
||||
<channel id="defaultChannel"/>
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.bus.DefaultChannelFactoryBean;
|
||||
import org.springframework.integration.bus.DefaultMessageBus;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.ChannelInterceptor;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.integration.channel.PriorityChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.RendezvousChannel;
|
||||
import org.springframework.integration.channel.ThreadLocalChannel;
|
||||
import org.springframework.integration.channel.config.ChannelParserTests;
|
||||
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
@@ -105,20 +103,16 @@ public class ChannelFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultChannelFactoryBean() throws Exception{
|
||||
DefaultMessageBus messageBus = new DefaultMessageBus();
|
||||
ChannelFactory channelFactory = new StubChannelFactory();
|
||||
messageBus.setChannelFactory(channelFactory);
|
||||
StaticApplicationContext applicationContext = new StaticApplicationContext();
|
||||
BeanDefinitionBuilder messageBusDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessageBus.class);
|
||||
messageBusDefinitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("channelFactory", channelFactory);
|
||||
applicationContext.registerBeanDefinition("messageBus", messageBusDefinitionBuilder.getBeanDefinition());
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(StubChannelFactory.class);
|
||||
applicationContext.registerBeanDefinition("channelFactory", builder.getBeanDefinition());
|
||||
DefaultChannelFactoryBean channelFactoryBean = new DefaultChannelFactoryBean();
|
||||
channelFactoryBean.setBeanName("testChannel");
|
||||
channelFactoryBean.setApplicationContext(applicationContext);
|
||||
channelFactoryBean.setInterceptors(interceptors);
|
||||
MessageChannel channel = (MessageChannel) channelFactoryBean.getObject();
|
||||
channel.getName();
|
||||
assertEquals(StubChannel.class, ChannelParserTests.extractProxifiedChannel(channel).getClass());
|
||||
assertEquals(StubChannel.class, channel.getClass());
|
||||
assertEquals("testChannel", channel.getName());
|
||||
channel.send(MessageBuilder.fromPayload("").build());
|
||||
assertTrue(appliedInterceptors.get(0) == interceptors.get(0));
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.springframework.integration.bus.TestMessageBusStopInterceptor;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.config.ChannelParserTests;
|
||||
import org.springframework.integration.endpoint.DefaultEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.handler.TestHandlers;
|
||||
@@ -135,8 +134,7 @@ public class MessageBusParserTests {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithChannelFactory.xml",
|
||||
this.getClass());
|
||||
((MessageChannel)context.getBean("defaultTypeChannel")).getName();
|
||||
assertEquals(DirectChannel.class,
|
||||
ChannelParserTests.extractProxifiedChannel(context.getBean("defaultTypeChannel")).getClass());
|
||||
assertEquals(DirectChannel.class, context.getBean("defaultTypeChannel").getClass());
|
||||
assertEquals(QueueChannel.class, context.getBean("specifiedTypeChannel").getClass());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus channel-factory="directChannelFactory"/>
|
||||
<message-bus/>
|
||||
|
||||
<beans:bean id="directChannelFactory" class="org.springframework.integration.channel.factory.DirectChannelFactory"/>
|
||||
<beans:bean id="channelFactory" class="org.springframework.integration.channel.factory.DirectChannelFactory"/>
|
||||
|
||||
<channel id="defaultTypeChannel"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user