Removed the name parameter from channelRegistry.registerChannel() since the MessageChannel interface already defines getName(). Removed the setName() method from the MessageChannel interface. Removed the 'error-channel' attribute from the <message-bus/> element and the setErrorChannel() method from MessageBus. The "errorChannel" name is now sufficient for configuration.

This commit is contained in:
Mark Fisher
2008-08-14 19:00:44 +00:00
parent 824fff8381
commit 73a848046a
30 changed files with 177 additions and 153 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.bus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.RendezvousChannel;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
@@ -36,6 +37,7 @@ public class DefaultErrorChannel extends RendezvousChannel {
public DefaultErrorChannel() {
this.addInterceptor(new ErrorLoggingInterceptor());
this.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
}

View File

@@ -173,7 +173,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
String channelName = entry.getKey();
MessageChannel previousChannel = this.lookupChannel(channelName);
if (previousChannel == null) {
this.registerChannel(channelName, entry.getValue());
this.registerChannel(entry.getValue());
}
else if (!previousChannel.equals(entry.getValue())) {
throw new ConfigurationException("A different channel instance has already "
@@ -213,7 +213,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
this.taskScheduler = new ProviderTaskScheduler(new SimpleScheduleServiceProvider(executor));
}
if (this.getErrorChannel() == null) {
this.setErrorChannel(new DefaultErrorChannel());
this.registerChannel(new DefaultErrorChannel());
}
this.initialized = true;
this.initializing = false;
@@ -224,30 +224,22 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
return this.lookupChannel(ERROR_CHANNEL_NAME);
}
public void setErrorChannel(MessageChannel errorChannel) {
this.registerChannel(ERROR_CHANNEL_NAME, errorChannel);
}
public MessageChannel lookupChannel(String channelName) {
MessageChannel channel = this.channelRegistry.lookupChannel(channelName);
if (channel == null && this.applicationContext != null && this.applicationContext.containsBean(channelName)) {
Object bean = this.applicationContext.getBean(channelName);
if (bean instanceof MessageChannel) {
channel = (MessageChannel) bean;
this.registerChannel(channelName, channel);
this.registerChannel(channel);
}
}
return channel;
}
public void registerChannel(String name, MessageChannel channel) {
if (!this.initialized) {
this.initialize();
}
channel.setName(name);
this.channelRegistry.registerChannel(name, channel);
public void registerChannel(MessageChannel channel) {
this.channelRegistry.registerChannel(channel);
if (logger.isInfoEnabled()) {
logger.info("registered channel '" + name + "'");
logger.info("registered channel '" + channel.getName() + "'");
}
}
@@ -354,7 +346,7 @@ public class DefaultMessageBus implements MessageBus, ApplicationContextAware, A
logger.info("auto-creating channel '" + channelName + "'");
}
channel = channelFactory.getChannel(channelName, null);
this.registerChannel(channelName, channel);
this.registerChannel(channel);
}
return channel;
}

View File

@@ -33,7 +33,7 @@ public class AbstractChannelAdapter extends AbstractMessageChannel {
public AbstractChannelAdapter(String name, MessageTarget target) {
Assert.notNull(name, "name must not be null");
this.setName(name);
this.setBeanName(name);
this.target = target;
}

View File

@@ -44,9 +44,10 @@ public abstract class AbstractMessageChannel implements MessageChannel, BeanName
/**
* Set the name of this channel.
* Set the name of this channel. This will be invoked automatically whenever
* the channel is configured explicitly with a bean definition.
*/
public void setName(String name) {
public void setBeanName(String name) {
this.name = name;
}
@@ -57,15 +58,6 @@ public abstract class AbstractMessageChannel implements MessageChannel, BeanName
return this.name;
}
/**
* Set the name of this channel to its bean name. This will be invoked
* automatically whenever the channel is configured explicitly with a bean
* definition.
*/
public void setBeanName(String beanName) {
this.setName(beanName);
}
/**
* Set the list of channel interceptors. This will clear any existing
* interceptors.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -26,7 +26,7 @@ public interface ChannelRegistry {
static final String ERROR_CHANNEL_NAME = "errorChannel";
void registerChannel(String name, MessageChannel channel);
void registerChannel(MessageChannel channel);
MessageChannel unregisterChannel(String name);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.
@@ -35,10 +35,10 @@ public class DefaultChannelRegistry implements ChannelRegistry {
return this.channels.get(channelName);
}
public void registerChannel(String name, MessageChannel channel) {
Assert.notNull(name, "'name' must not be null");
public void registerChannel(MessageChannel channel) {
Assert.notNull(channel, "'channel' must not be null");
this.channels.put(name, channel);
Assert.notNull(channel.getName(), "channel name must not be null");
this.channels.put(channel.getName(), channel);
}
public MessageChannel unregisterChannel(String name) {

View File

@@ -31,9 +31,4 @@ public interface MessageChannel extends MessageSource, BlockingTarget {
*/
String getName();
/**
* Set the name of this channel.
*/
void setName(String name);
}

View File

@@ -40,7 +40,7 @@ public abstract class AbstractChannelFactory implements ChannelFactory {
channel.setInterceptors(interceptors);
}
if (name != null && channel.getName() == null) {
channel.setName(name);
channel.setBeanName(name);
}
return channel;
}

View File

@@ -28,15 +28,13 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.core.Conventions;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.bus.DefaultMessageBus;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor;
import org.springframework.util.StringUtils;
/**
* Parser for the <em>message-bus</em> element of the integration namespace.
* Parser for the &lt;message-bus&gt; element of the integration namespace.
*
* @author Mark Fisher
* @author Marius Bogoevici
@@ -47,8 +45,6 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME = "internal.MessageBusAwareBeanPostProcessor";
private static final String ERROR_CHANNEL_ATTRIBUTE = "error-channel";
private static final String CHANNEL_FACTORY_ATTRIBUTE = "channel-factory";
private static final String INTERCEPTOR_ELEMENT = "interceptor";
@@ -75,28 +71,18 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !ERROR_CHANNEL_ATTRIBUTE.equals(attributeName) &&
!CHANNEL_FACTORY_ATTRIBUTE.equals(attributeName) &&
return !CHANNEL_FACTORY_ATTRIBUTE.equals(attributeName) &&
super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
String errorChannelRef = element.getAttribute(ERROR_CHANNEL_ATTRIBUTE);
if (StringUtils.hasText(errorChannelRef)) {
beanDefinition.addPropertyReference(Conventions.attributeNameToPropertyName(
ERROR_CHANNEL_ATTRIBUTE), errorChannelRef);
}
String channelFactoryRef = element.getAttribute(CHANNEL_FACTORY_ATTRIBUTE);
if (StringUtils.hasText(channelFactoryRef)) {
beanDefinition.addPropertyReference(Conventions.attributeNameToPropertyName(
CHANNEL_FACTORY_ATTRIBUTE), channelFactoryRef);
}
this.processChildElements(beanDefinition, element);
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, CHANNEL_FACTORY_ATTRIBUTE);
this.processChildElements(builder, element);
}
@SuppressWarnings("unchecked")
private void processChildElements(BeanDefinitionBuilder beanDefinition, Element element) {
private void processChildElements(BeanDefinitionBuilder builder, Element element) {
NodeList childNodes = element.getChildNodes();
ManagedList interceptors = new ManagedList();
for (int i = 0; i < childNodes.getLength(); i++) {
@@ -109,7 +95,7 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser {
}
}
if (interceptors.size() > 0) {
beanDefinition.addPropertyValue(INTERCEPTORS_PROPERTY, interceptors);
builder.addPropertyValue(INTERCEPTORS_PROPERTY, interceptors);
}
}

View File

@@ -50,7 +50,7 @@ public class PollableAnnotationPostProcessor extends AbstractAnnotationMethodPos
if (channelAdapterAnnotation != null) {
String channelName = channelAdapterAnnotation.value();
PollableChannelAdapter adapter = new PollableChannelAdapter(channelName, source, null);
this.getMessageBus().registerChannel(channelName, adapter);
this.getMessageBus().registerChannel(adapter);
}
return source;
}

View File

@@ -49,7 +49,7 @@ public class TargetAnnotationPostProcessor extends AbstractAnnotationMethodPostP
if (channelAdapterAnnotation != null) {
String channelName = channelAdapterAnnotation.value();
PollableChannelAdapter adapter = new PollableChannelAdapter(channelName, null, target);
this.getMessageBus().registerChannel(channelName, adapter);
this.getMessageBus().registerChannel(adapter);
}
return target;
}

View File

@@ -34,7 +34,6 @@
<xsd:attribute name="auto-startup" type="xsd:boolean"/>
<xsd:attribute name="auto-create-channels" type="xsd:boolean"/>
<xsd:attribute name="channel-factory" type="xsd:string"/>
<xsd:attribute name="error-channel" type="xsd:string"/>
<xsd:attribute name="dispatcher-pool-size" type="xsd:int"/>
<xsd:attribute name="configure-async-event-multicaster" type="xsd:boolean"/>
</xsd:complexType>

View File

@@ -37,8 +37,9 @@ public class PublisherAnnotationAdvisorTests {
@Test
public void testPublisherAnnotation() {
final QueueChannel channel = new QueueChannel();
channel.setBeanName("testChannel");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("testChannel", channel);
channelRegistry.registerChannel(channel);
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
proxy.publisherTest();
@@ -50,8 +51,9 @@ public class PublisherAnnotationAdvisorTests {
@Test
public void testNoPublisherAnnotation() {
final QueueChannel channel = new QueueChannel();
channel.setBeanName("testChannel");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("testChannel", channel);
channelRegistry.registerChannel(channel);
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor(channelRegistry);
TestService proxy = (TestService) this.createProxy(new TestServiceImpl("hello world"), advisor);
proxy.noPublisherTest();

View File

@@ -28,7 +28,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.channel.PollableChannelAdapter;
import org.springframework.integration.channel.PublishSubscribeChannel;
@@ -53,11 +53,13 @@ public class DefaultMessageBusTests {
DefaultMessageBus bus = new DefaultMessageBus();
QueueChannel sourceChannel = new QueueChannel();
QueueChannel targetChannel = new QueueChannel();
bus.registerChannel("sourceChannel", sourceChannel);
sourceChannel.setBeanName("sourceChannel");
targetChannel.setBeanName("targetChannel");
bus.registerChannel(sourceChannel);
Message<String> message = MessageBuilder.fromPayload("test")
.setReturnAddress("targetChannel").build();
sourceChannel.send(message);
bus.registerChannel("targetChannel", targetChannel);
bus.registerChannel(targetChannel);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
return message;
@@ -78,11 +80,13 @@ public class DefaultMessageBusTests {
MessageBus bus = new DefaultMessageBus();
QueueChannel sourceChannel = new QueueChannel();
QueueChannel targetChannel = new QueueChannel();
bus.registerChannel("sourceChannel", sourceChannel);
sourceChannel.setBeanName("sourceChannel");
targetChannel.setBeanName("targetChannel");
bus.registerChannel(sourceChannel);
Message<String> message = MessageBuilder.fromPayload("test")
.setReturnAddress("targetChannel").build();
sourceChannel.send(message);
bus.registerChannel("targetChannel", targetChannel);
bus.registerChannel(targetChannel);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
return message;
@@ -102,10 +106,12 @@ public class DefaultMessageBusTests {
public void testChannelsWithoutHandlers() {
MessageBus bus = new DefaultMessageBus();
QueueChannel sourceChannel = new QueueChannel();
sourceChannel.setBeanName("sourceChannel");
sourceChannel.send(new StringMessage("test"));
QueueChannel targetChannel = new QueueChannel();
bus.registerChannel("sourceChannel", sourceChannel);
bus.registerChannel("targetChannel", targetChannel);
targetChannel.setBeanName("targetChannel");
bus.registerChannel(sourceChannel);
bus.registerChannel(targetChannel);
bus.start();
Message<?> result = targetChannel.receive(100);
assertNull(result);
@@ -143,9 +149,12 @@ public class DefaultMessageBusTests {
}
};
MessageBus bus = new DefaultMessageBus();
bus.registerChannel("input", inputChannel);
bus.registerChannel("output1", outputChannel1);
bus.registerChannel("output2", outputChannel2);
inputChannel.setBeanName("input");
outputChannel1.setBeanName("output1");
outputChannel2.setBeanName("output2");
bus.registerChannel(inputChannel);
bus.registerChannel(outputChannel1);
bus.registerChannel(outputChannel2);
DefaultEndpoint<MessageHandler> endpoint1 = new DefaultEndpoint<MessageHandler>(handler1);
endpoint1.setBeanName("testEndpoint1");
endpoint1.setSource(inputChannel);
@@ -185,9 +194,12 @@ public class DefaultMessageBusTests {
}
};
MessageBus bus = new DefaultMessageBus();
bus.registerChannel("input", inputChannel);
bus.registerChannel("output1", outputChannel1);
bus.registerChannel("output2", outputChannel2);
inputChannel.setBeanName("input");
outputChannel1.setBeanName("output1");
outputChannel2.setBeanName("output2");
bus.registerChannel(inputChannel);
bus.registerChannel(outputChannel1);
bus.registerChannel(outputChannel2);
DefaultEndpoint<MessageHandler> endpoint1 = new DefaultEndpoint<MessageHandler>(handler1);
endpoint1.setBeanName("testEndpoint1");
endpoint1.setSource(inputChannel);
@@ -240,17 +252,19 @@ public class DefaultMessageBusTests {
@Test
public void testErrorChannelRegistration() {
MessageChannel errorChannel = new QueueChannel();
DefaultMessageBus bus = new DefaultMessageBus();
bus.setErrorChannel(errorChannel);
QueueChannel errorChannel = new QueueChannel();
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
bus.registerChannel(errorChannel);
assertEquals(errorChannel, bus.getErrorChannel());
}
@Test
public void testHandlerSubscribedToErrorChannel() throws InterruptedException {
MessageChannel errorChannel = new QueueChannel();
DefaultMessageBus bus = new DefaultMessageBus();
bus.setErrorChannel(errorChannel);
QueueChannel errorChannel = new QueueChannel();
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
bus.registerChannel(errorChannel);
final CountDownLatch latch = new CountDownLatch(1);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {

View File

@@ -23,8 +23,8 @@ import org.junit.Test;
import org.springframework.integration.annotation.Handler;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.channel.ChannelRegistry;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.channel.ThreadLocalChannel;
import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor;
@@ -41,15 +41,17 @@ public class DirectChannelSubscriptionTests {
private DefaultMessageBus bus = new DefaultMessageBus();
private MessageChannel sourceChannel = new DirectChannel();
private DirectChannel sourceChannel = new DirectChannel();
private ThreadLocalChannel targetChannel = new ThreadLocalChannel();
@Before
public void setupChannels() {
bus.registerChannel("sourceChannel", sourceChannel);
bus.registerChannel("targetChannel", targetChannel);
sourceChannel.setBeanName("sourceChannel");
targetChannel.setBeanName("targetChannel");
bus.registerChannel(sourceChannel);
bus.registerChannel(targetChannel);
}
@@ -83,7 +85,8 @@ public class DirectChannelSubscriptionTests {
@Test(expected=RuntimeException.class)
public void testExceptionThrownFromRegisteredEndpoint() {
QueueChannel errorChannel = new QueueChannel();
bus.setErrorChannel(errorChannel);
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
bus.registerChannel(errorChannel);
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>(new MessageHandler() {
public Message<?> handle(Message<?> message) {
throw new RuntimeException("intentional test failure");
@@ -100,7 +103,8 @@ public class DirectChannelSubscriptionTests {
@Test(expected=MessagingException.class)
public void testExceptionThrownFromAnnotatedEndpoint() {
QueueChannel errorChannel = new QueueChannel();
bus.setErrorChannel(errorChannel);
errorChannel.setBeanName(ChannelRegistry.ERROR_CHANNEL_NAME);
bus.registerChannel(errorChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(bus);
postProcessor.afterPropertiesSet();
FailingTestEndpoint endpoint = new FailingTestEndpoint();

View File

@@ -30,8 +30,9 @@ public class DefaultChannelRegistryTests {
@Test
public void testLookupRegisteredChannel() {
QueueChannel testChannel = new QueueChannel();
testChannel.setBeanName("testChannel");
DefaultChannelRegistry registry = new DefaultChannelRegistry();
registry.registerChannel("testChannel", testChannel);
registry.registerChannel(testChannel);
MessageChannel lookedUpChannel = registry.lookupChannel("testChannel");
assertNotNull(testChannel);
assertSame(testChannel, lookedUpChannel);
@@ -47,8 +48,9 @@ public class DefaultChannelRegistryTests {
@Test
public void testLookupUnregisteredChannel() {
QueueChannel testChannel = new QueueChannel();
testChannel.setBeanName("testChannel");
DefaultChannelRegistry registry = new DefaultChannelRegistry();
registry.registerChannel("testChannel", testChannel);
registry.registerChannel(testChannel);
MessageChannel lookedUpChannel1 = registry.lookupChannel("testChannel");
assertNotNull(lookedUpChannel1);
assertSame(testChannel, lookedUpChannel1);

View File

@@ -55,10 +55,10 @@ public class MessageBusParserTests {
@Test
public void testErrorChannelReference() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"messageBusWithErrorChannelReference.xml", this.getClass());
"messageBusWithErrorChannel.xml", this.getClass());
DefaultMessageBus bus = (DefaultMessageBus) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME);
bus.initialize();
assertEquals(context.getBean("testErrorChannel"), bus.getErrorChannel());
assertEquals(context.getBean("errorChannel"), bus.getErrorChannel());
}
@Test

View File

@@ -268,10 +268,12 @@ public class MessagingAnnotationPostProcessorTests {
@Test
public void testMessageEndpointAnnotationInheritedFromInterface() {
MessageBus messageBus = new DefaultMessageBus();
MessageChannel inputChannel = new QueueChannel();
QueueChannel inputChannel = new QueueChannel();
QueueChannel outputChannel = new QueueChannel();
messageBus.registerChannel("inputChannel", inputChannel);
messageBus.registerChannel("outputChannel", outputChannel);
inputChannel.setBeanName("inputChannel");
outputChannel.setBeanName("outputChannel");
messageBus.registerChannel(inputChannel);
messageBus.registerChannel(outputChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
postProcessor.afterPropertiesSet();
postProcessor.postProcessAfterInitialization(new SimpleAnnotatedEndpointImplementation(), "impl");
@@ -299,10 +301,12 @@ public class MessagingAnnotationPostProcessorTests {
@Test
public void testMessageEndpointAnnotationInheritedFromInterfaceWithProxy() {
MessageBus messageBus = new DefaultMessageBus();
MessageChannel inputChannel = new QueueChannel();
QueueChannel inputChannel = new QueueChannel();
QueueChannel outputChannel = new QueueChannel();
messageBus.registerChannel("inputChannel", inputChannel);
messageBus.registerChannel("outputChannel", outputChannel);
inputChannel.setBeanName("inputChannel");
outputChannel.setBeanName("outputChannel");
messageBus.registerChannel(inputChannel);
messageBus.registerChannel(outputChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
postProcessor.afterPropertiesSet();
ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpointImplementation());
@@ -319,8 +323,10 @@ public class MessagingAnnotationPostProcessorTests {
MessageBus messageBus = new DefaultMessageBus();
QueueChannel input = new QueueChannel();
QueueChannel output = new QueueChannel();
messageBus.registerChannel("input", input);
messageBus.registerChannel("output", output);
input.setBeanName("input");
output.setBeanName("output");
messageBus.registerChannel(input);
messageBus.registerChannel(output);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
postProcessor.afterPropertiesSet();
SplitterAnnotationTestEndpoint endpoint = new SplitterAnnotationTestEndpoint();
@@ -346,7 +352,8 @@ public class MessagingAnnotationPostProcessorTests {
public void testEndpointWithNoHandlerMethod() {
MessageBus messageBus = new DefaultMessageBus();
QueueChannel testChannel = new QueueChannel();
messageBus.registerChannel("testChannel", testChannel);
testChannel.setBeanName("testChannel");
messageBus.registerChannel(testChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
postProcessor.afterPropertiesSet();
AnnotatedEndpointWithNoHandlerMethod endpoint = new AnnotatedEndpointWithNoHandlerMethod();
@@ -357,7 +364,8 @@ public class MessagingAnnotationPostProcessorTests {
public void testEndpointWithPollerAnnotation() {
MessageBus messageBus = new DefaultMessageBus();
QueueChannel testChannel = new QueueChannel();
messageBus.registerChannel("testChannel", testChannel);
testChannel.setBeanName("testChannel");
messageBus.registerChannel(testChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor(messageBus);
postProcessor.afterPropertiesSet();
AnnotatedEndpointWithPolledAnnotation endpoint = new AnnotatedEndpointWithPolledAnnotation();

View File

@@ -7,8 +7,8 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<channel id="testErrorChannel"/>
<channel id="errorChannel"/>
<message-bus error-channel="testErrorChannel"/>
<message-bus/>
</beans:beans>

View File

@@ -95,8 +95,9 @@ public class DefaultEndpointTests {
@Test
public void returnAddressHeaderWithChannelName() {
QueueChannel channel = new QueueChannel(1);
channel.setBeanName("testChannel");
ChannelRegistry channelRegistry = new DefaultMessageBus();
channelRegistry.registerChannel("testChannel", channel);
channelRegistry.registerChannel(channel);
MessageHandler handler = new TestHandler();
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>(handler);
endpoint.setChannelRegistry(channelRegistry);
@@ -112,8 +113,9 @@ public class DefaultEndpointTests {
QueueChannel channel1 = new QueueChannel(1);
QueueChannel channel2 = new QueueChannel(1);
QueueChannel channel3 = new QueueChannel(1);
channel1.setBeanName("testChannel");
ChannelRegistry channelRegistry = new DefaultMessageBus();
channelRegistry.registerChannel("testChannel", channel1);
channelRegistry.registerChannel(channel1);
MessageHandler handler = new TestNextTargetSettingHandler("testChannel");
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>(handler);
endpoint.setChannelRegistry(channelRegistry);
@@ -133,8 +135,9 @@ public class DefaultEndpointTests {
public void dynamicReplyChannel() throws Exception {
final QueueChannel replyChannel1 = new QueueChannel();
final QueueChannel replyChannel2 = new QueueChannel();
replyChannel2.setBeanName("replyChannel2");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("replyChannel2", replyChannel2);
channelRegistry.registerChannel(replyChannel2);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
return new StringMessage("foo" + message.getPayload());

View File

@@ -85,7 +85,7 @@ public class ReturnAddressTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"returnAddressTests.xml", this.getClass());
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
PollableChannel errorChannel = (PollableChannel) context.getBean("customErrorChannel");
PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
context.start();
StringMessage message = new StringMessage("*");
channel3.send(message);
@@ -98,7 +98,7 @@ public class ReturnAddressTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"returnAddressTests.xml", this.getClass());
MessageChannel channel3 = (MessageChannel) context.getBean("channel3WithOverride");
PollableChannel errorChannel = (PollableChannel) context.getBean("customErrorChannel");
PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
context.start();
StringMessage message = new StringMessage("*");
channel3.send(message);

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<si:message-bus error-channel="customErrorChannel"/>
<si:message-bus/>
<si:channel id="channel1"/>
<si:channel id="channel2"/>
@@ -16,7 +16,7 @@
<si:channel id="channel1WithOverride"/>
<si:channel id="channel3WithOverride"/>
<si:channel id="replyChannel"/>
<si:channel id="customErrorChannel"/>
<si:channel id="errorChannel"/>
<si:service-activator input-channel="channel1WithOverride" ref="testBean" method="duplicate"
output-channel="channel2" return-address-overrides="true"/>

View File

@@ -94,11 +94,12 @@ public class MethodInvokingTargetTests {
target.setMethodName("foo");
target.afterPropertiesSet();
QueueChannel channel = new QueueChannel();
channel.setBeanName("channel");
Message<String> message = new GenericMessage<String>("testing");
channel.send(message);
assertNull(queue.poll());
MessageBus bus = new DefaultMessageBus();
bus.registerChannel("channel", channel);
bus.registerChannel(channel);
MessageEndpoint endpoint = new DefaultEndpoint<MethodInvokingTarget>(target);
endpoint.setBeanName("testEndpoint");
endpoint.setSource(channel);

View File

@@ -24,6 +24,7 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.bus.DefaultMessageBus;
@@ -31,28 +32,26 @@ import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.DefaultEndpoint;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageExchangeTemplate;
import org.springframework.integration.message.MessageTarget;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class MessageExchangeTemplateTests {
private final QueueChannel requestChannel = new QueueChannel();
private QueueChannel requestChannel;
public MessageExchangeTemplateTests() {
@Before
public void setUp() {
this.requestChannel = new QueueChannel();
this.requestChannel.setBeanName("requestChannel");
MessageHandler testHandler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
return new StringMessage(message.getPayload().toString().toUpperCase());
}
};
MessageBus bus = new DefaultMessageBus();
bus.registerChannel("requestChannel", requestChannel);
bus.registerChannel(requestChannel);
DefaultEndpoint<MessageHandler> endpoint = new DefaultEndpoint<MessageHandler>(testHandler);
endpoint.setBeanName("testEndpoint");
endpoint.setSource(requestChannel);

View File

@@ -72,9 +72,11 @@ public class MultiChannelRouterTests {
};
QueueChannel channel1 = new QueueChannel();
QueueChannel channel2 = new QueueChannel();
channel1.setBeanName("channel1");
channel2.setBeanName("channel2");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("channel1", channel1);
channelRegistry.registerChannel("channel2", channel2);
channelRegistry.registerChannel(channel1);
channelRegistry.registerChannel(channel2);
MultiChannelRouter router = new MultiChannelRouter();
router.setChannelNameResolver(channelNameResolver);
router.setChannelRegistry(channelRegistry);

View File

@@ -62,9 +62,11 @@ public class RecipientListRouterTests {
public void testRoutingWithChannelNames() {
QueueChannel channel1 = new QueueChannel();
QueueChannel channel2 = new QueueChannel();
channel1.setBeanName("channel1");
channel2.setBeanName("channel2");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("channel1", channel1);
channelRegistry.registerChannel("channel2", channel2);
channelRegistry.registerChannel(channel1);
channelRegistry.registerChannel(channel2);
RecipientListRouter router = new RecipientListRouter();
router.setChannelNames(new String[] {"channel1", "channel2"});
router.setChannelRegistry(channelRegistry);
@@ -83,9 +85,11 @@ public class RecipientListRouterTests {
public void testRoutingToSingleChannelByName() {
QueueChannel channel1 = new QueueChannel();
QueueChannel channel2 = new QueueChannel();
channel1.setBeanName("channel1");
channel2.setBeanName("channel2");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("channel1", channel1);
channelRegistry.registerChannel("channel2", channel2);
channelRegistry.registerChannel(channel1);
channelRegistry.registerChannel(channel2);
RecipientListRouter router = new RecipientListRouter();
router.setChannelNames(new String[] {"channel1"});
router.setChannelRegistry(channelRegistry);
@@ -103,12 +107,14 @@ public class RecipientListRouterTests {
public void testConfigurationExceptionWhenBothChannelsAndNamesAreProvided() {
QueueChannel channel1 = new QueueChannel();
QueueChannel channel2 = new QueueChannel();
channel1.setBeanName("channel1");
channel2.setBeanName("channel2");
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channel1);
channels.add(channel2);
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("channel1", channel1);
channelRegistry.registerChannel("channel2", channel2);
channelRegistry.registerChannel(channel1);
channelRegistry.registerChannel(channel2);
RecipientListRouter router = new RecipientListRouter();
router.setChannels(channels);
router.setChannelNames(new String[] {"channel1"});

View File

@@ -150,10 +150,12 @@ public class RouterMessageHandlerTests {
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
MessageChannel fooChannel = new QueueChannel();
MessageChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<?> result1 = ((CompositeMessage) handler.handle(fooMessage)).getPayload().get(0);
assertNotNull(result1);
assertEquals("foo", result1.getPayload());
@@ -185,8 +187,10 @@ public class RouterMessageHandlerTests {
private void doTestChannelInstanceResolutionByMessage(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -221,8 +225,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelNameResolutionByPayload(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -267,8 +273,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelNameResolutionByMessage(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -313,8 +321,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelNameArrayResolutionByMessage(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -359,8 +369,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelListResolutionByPayload(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -405,8 +417,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelListResolutionByMessage(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -451,8 +465,10 @@ public class RouterMessageHandlerTests {
private void doTestMultiChannelArrayResolutionByMessage(RouterMessageHandler handler, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
fooChannel.setBeanName("foo-channel");
barChannel.setBeanName("bar-channel");
channelRegistry.registerChannel(fooChannel);
channelRegistry.registerChannel(barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");

View File

@@ -61,8 +61,9 @@ public class SingleChannelRouterTests {
}
};
QueueChannel channel = new QueueChannel();
channel.setBeanName("testChannel");
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("testChannel", channel);
channelRegistry.registerChannel(channel);
SingleChannelRouter router = new SingleChannelRouter();
router.setChannelNameResolver(channelNameResolver);
router.setChannelRegistry(channelRegistry);