diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java index 8a9b33e7c6..764b47afb2 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java @@ -63,7 +63,7 @@ public class FileInboundChannelAdapterParserTests { @Test public void channelName() throws Exception { AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class); - assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getName()); + assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName()); } @Test diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java index 4e411c9428..5bdc482781 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java @@ -69,7 +69,7 @@ public class FileInboundChannelAdapterWithPatternParserTests { @Test public void channelName() { AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class); - assertEquals("adapterWithPattern", channel.getName()); + assertEquals("adapterWithPattern", channel.getComponentName()); } @Test diff --git a/org.springframework.integration.rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java b/org.springframework.integration.rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java index b275b237f1..d843b8453d 100644 --- a/org.springframework.integration.rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java +++ b/org.springframework.integration.rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -21,7 +21,7 @@ import java.rmi.registry.Registry; import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.adapter.RemoteMessageHandler; import org.springframework.integration.adapter.RemotingInboundGatewaySupport; -import org.springframework.integration.channel.AbstractMessageChannel; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageChannel; import org.springframework.remoting.rmi.RmiServiceExporter; import org.springframework.remoting.support.RemoteInvocationExecutor; @@ -58,10 +58,10 @@ public class RmiInboundGateway extends RemotingInboundGatewaySupport implements @Override public void setRequestChannel(MessageChannel requestChannel) { Assert.notNull(requestChannel, "requestChannel must not be null"); - Assert.isTrue(requestChannel instanceof AbstractMessageChannel && - StringUtils.hasText(((AbstractMessageChannel) requestChannel).getName()), + Assert.isTrue(requestChannel instanceof NamedComponent && + StringUtils.hasText(((NamedComponent) requestChannel).getComponentName()), "RmiGateway's request channel must have a name."); - this.requestChannelName = ((AbstractMessageChannel) requestChannel).getName(); + this.requestChannelName = ((NamedComponent) requestChannel).getComponentName(); super.setRequestChannel(requestChannel); } diff --git a/org.springframework.integration.security/src/main/java/org/springframework/integration/security/channel/ChannelInvocationDefinitionSource.java b/org.springframework.integration.security/src/main/java/org/springframework/integration/security/channel/ChannelInvocationDefinitionSource.java index 06625e757b..38bb054a4e 100644 --- a/org.springframework.integration.security/src/main/java/org/springframework/integration/security/channel/ChannelInvocationDefinitionSource.java +++ b/org.springframework.integration.security/src/main/java/org/springframework/integration/security/channel/ChannelInvocationDefinitionSource.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import org.springframework.integration.channel.AbstractMessageChannel; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.MessageChannel; import org.springframework.security.ConfigAttribute; import org.springframework.security.ConfigAttributeDefinition; @@ -70,8 +70,8 @@ public class ChannelInvocationDefinitionSource implements ObjectDefinitionSource Assert.isAssignable(ChannelInvocation.class, object.getClass()); ChannelInvocation invocation = (ChannelInvocation) object; MessageChannel channel = invocation.getChannel(); - Assert.isAssignable(AbstractMessageChannel.class, channel.getClass()); - String channelName = ((AbstractMessageChannel) channel).getName(); + Assert.isAssignable(NamedComponent.class, channel.getClass()); + String channelName = ((NamedComponent) channel).getComponentName(); List attributes = new ArrayList(); for (Map.Entry mapping : this.patternMappings.entrySet()) { Pattern pattern = mapping.getKey(); diff --git a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java index 6bf140e77d..ff2e892a69 100644 --- a/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java +++ b/org.springframework.integration.test/src/main/java/org/springframework/integration/test/util/TestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -29,10 +29,10 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.MessagePublishingErrorHandler; import org.springframework.integration.context.IntegrationContextUtils; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.endpoint.AbstractEndpoint; @@ -129,12 +129,12 @@ public abstract class TestUtils { } public void registerChannel(String channelName, MessageChannel channel) { - if (channel instanceof AbstractMessageChannel && ((AbstractMessageChannel) channel).getName() != null) { + if (channel instanceof NamedComponent && ((NamedComponent) channel).getComponentName() != null) { if (channelName == null) { - channelName = ((AbstractMessageChannel) channel).getName(); + channelName = ((NamedComponent) channel).getComponentName(); } else { - Assert.isTrue(((AbstractMessageChannel) channel).getName().equals(channelName), + Assert.isTrue(((NamedComponent) channel).getComponentName().equals(channelName), "channel name has already been set with a conflicting value"); } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index 94ebee8b1e..efe82457db 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -56,13 +56,6 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im private final ChannelInterceptorList interceptors = new ChannelInterceptorList(); - /** - * Return the name of this channel. - */ - public String getName() { - return this.getBeanName(); - } - @Override public String getComponentType() { return "channel"; @@ -169,7 +162,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im Assert.notNull(message, "message must not be null"); Assert.notNull(message.getPayload(), "message payload must not be null"); message = this.convertPayloadIfNecessary(message); - message.getHeaders().getHistory().addEvent(this.getBeanName(), this.getComponentType()); + message.getHeaders().getHistory().addEvent(this); message = this.interceptors.preSend(message, this); if (message == null) { return false; @@ -188,7 +181,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im throw (MessagingException) e; } throw new MessageDeliveryException(message, - "failed to send Message to channel '" + this.getName() + "'", e); + "failed to send Message to channel '" + this.getComponentName() + "'", e); } } @@ -209,7 +202,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im } } } - throw new MessageDeliveryException(message, "Channel '" + this.getName() + + throw new MessageDeliveryException(message, "Channel '" + this.getComponentName() + "' expected one of the following datataypes [" + StringUtils.arrayToCommaDelimitedString(this.datatypes) + "], but received [" + message.getPayload().getClass() + "]"); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index b392362cb8..bbe8d58ccf 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -24,7 +24,6 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.NamedBean; import org.springframework.core.convert.ConversionService; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolver; @@ -42,7 +41,7 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBean, BeanFactoryAware, InitializingBean { +public abstract class IntegrationObjectSupport implements BeanNameAware, NamedComponent, BeanFactoryAware, InitializingBean { /** Logger that is available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); @@ -62,7 +61,8 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBe this.beanName = beanName; } - public final String getBeanName() { + + public final String getComponentName() { return this.beanName; } @@ -129,7 +129,7 @@ public abstract class IntegrationObjectSupport implements BeanNameAware, NamedBe this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory); if (this.conversionService == null && logger.isDebugEnabled()) { logger.debug("Unable to attempt conversion of Message payload types. Component '" + - this.getBeanName() + "' has no explicit ConversionService reference, " + + this.getComponentName() + "' has no explicit ConversionService reference, " + "and there is no 'integrationConversionService' bean within the context."); } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/context/NamedComponent.java b/org.springframework.integration/src/main/java/org/springframework/integration/context/NamedComponent.java new file mode 100644 index 0000000000..64116f7da7 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/context/NamedComponent.java @@ -0,0 +1,29 @@ +/* + * Copyright 2002-2010 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.context; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public interface NamedComponent { + + String getComponentName(); + + String getComponentType(); + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java index 7865218dc9..9b04d0e045 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/EventDrivenConsumer.java @@ -50,7 +50,7 @@ public class EventDrivenConsumer extends AbstractEndpoint { protected void doStart() { synchronized (this.initializationMonitor) { if (this.handlerInvocationChain == null) { - this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getBeanName()); + this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getComponentName()); } } this.inputChannel.subscribe(this.handlerInvocationChain); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/HandlerInvocationChain.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/HandlerInvocationChain.java index 2d0eac06cc..41435d39fe 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/HandlerInvocationChain.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/HandlerInvocationChain.java @@ -18,6 +18,7 @@ package org.springframework.integration.endpoint; import org.springframework.core.Ordered; import org.springframework.integration.context.IntegrationObjectSupport; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.Message; import org.springframework.integration.message.MessageHandler; @@ -33,16 +34,15 @@ class HandlerInvocationChain implements MessageHandler, Ordered { private final MessageHandler handler; - private final String endpointName; - - private final String handlerType; + private final EndpointNamedComponent namedComponent; public HandlerInvocationChain(MessageHandler handler, String endpointName) { this.handler = handler; - this.endpointName = endpointName; - this.handlerType = (handler instanceof IntegrationObjectSupport) ? + String handlerType = (handler instanceof IntegrationObjectSupport) ? ((IntegrationObjectSupport) this.handler).getComponentType() : null; + this.namedComponent = (endpointName != null) ? + new EndpointNamedComponent(endpointName, handlerType) : null; } @@ -52,10 +52,31 @@ class HandlerInvocationChain implements MessageHandler, Ordered { } public void handleMessage(Message message) { - if (message != null && this.endpointName != null) { - message.getHeaders().getHistory().addEvent(this.endpointName, this.handlerType); + if (message != null && this.namedComponent != null) { + message.getHeaders().getHistory().addEvent(this.namedComponent); } this.handler.handleMessage(message); } + + private static class EndpointNamedComponent implements NamedComponent { + + private final String componentName; + + private final String componentType; + + private EndpointNamedComponent(String componentName, String componentType) { + this.componentName = componentName; + this.componentType = componentType; + } + + public String getComponentName() { + return this.componentName; + } + + public String getComponentType() { + return this.componentType; + } + } + } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java index 7f5a1f5060..0a6709d911 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/MessageProducerSupport.java @@ -50,7 +50,7 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements protected boolean sendMessage(Message message) { if (message != null) { - message.getHeaders().getHistory().addEvent(this.getBeanName(), this.getComponentType()); + message.getHeaders().getHistory().addEvent(this); } return this.channelTemplate.send(message, this.outputChannel); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/PollingConsumer.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/PollingConsumer.java index 94c862fe65..d1faf73b87 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/PollingConsumer.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/PollingConsumer.java @@ -58,7 +58,7 @@ public class PollingConsumer extends AbstractPollingEndpoint { protected void onInit() { synchronized (this.initializationMonitor) { if (!this.initialized) { - this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getBeanName()); + this.handlerInvocationChain = new HandlerInvocationChain(this.handler, this.getComponentName()); } this.initialized = true; } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 52113a2dfc..33bdaf2aac 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -253,10 +253,11 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory private SimpleMessagingGateway createGatewayForMethod(Method method) { SimpleMessagingGateway gateway = new SimpleMessagingGateway( - new ArgumentArrayMessageMapper(method, this.getBeanName()), new SimpleMessageMapper()); + new ArgumentArrayMessageMapper(method), new SimpleMessageMapper()); if (this.getTaskScheduler() != null) { gateway.setTaskScheduler(this.getTaskScheduler()); } + gateway.setBeanName(this.getComponentName()); Gateway gatewayAnnotation = method.getAnnotation(Gateway.class); MessageChannel requestChannel = this.defaultRequestChannel; MessageChannel replyChannel = this.defaultReplyChannel; diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java index 2c5236e86b..8795d238f4 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/SimpleMessagingGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -70,7 +70,11 @@ public class SimpleMessagingGateway extends AbstractMessagingGateway { @Override protected Message toMessage(Object object) { try { - return this.inboundMapper.toMessage(object); + Message message = this.inboundMapper.toMessage(object); + if (message != null) { + message.getHeaders().getHistory().addEvent(this); + } + return message; } catch (Exception e) { if (e instanceof RuntimeException) { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java index f395be978b..4acb954d94 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/ArgumentArrayMessageMapper.java @@ -122,15 +122,11 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper parameterList; - private final String gatewayName; - - public ArgumentArrayMessageMapper(Method method, String gatewayName) { + public ArgumentArrayMessageMapper(Method method) { Assert.notNull(method, "method must not be null"); - Assert.notNull(gatewayName, "gatewayName must not be null"); this.method = method; this.parameterList = this.getMethodParameterList(method); - this.gatewayName = gatewayName; } public Message toMessage(Object[] arguments) { @@ -140,11 +136,7 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper message = this.mapArgumentsToMessage(arguments); - if (message != null) { - message.getHeaders().getHistory().addEvent(this.gatewayName, "gateway"); - } - return message; + return this.mapArgumentsToMessage(arguments); } @SuppressWarnings("unchecked") diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/history/MessageHistory.java b/org.springframework.integration/src/main/java/org/springframework/integration/history/MessageHistory.java index 36e0fe4b40..28e7919719 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/history/MessageHistory.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/history/MessageHistory.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import org.springframework.integration.context.NamedComponent; import org.springframework.util.StringUtils; /** @@ -40,7 +41,9 @@ public class MessageHistory implements Iterable, Serializab /** * Add a new event with the provided component metadata. */ - public MessageHistoryEvent addEvent(String name, String type) { + public MessageHistoryEvent addEvent(NamedComponent component) { + String name = component.getComponentName(); + String type = component.getComponentType(); if (name != null && !StringUtils.startsWithIgnoreCase(name, "org.springframework")) { MessageHistoryEvent event = new MessageHistoryEvent(name, type); this.events.add(event); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java index d1855ef94b..8fda2f44e6 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/SimpleMessagingGatewayTests.java @@ -73,6 +73,7 @@ public class SimpleMessagingGatewayTests { @Test public void sendMessage() { + expect(messageMock.getHeaders()).andReturn(new MessageHeaders(null)); expect(requestChannel.send(messageMock)).andReturn(true); replay(allmocks); this.simpleMessagingGateway.send(messageMock); @@ -81,6 +82,7 @@ public class SimpleMessagingGatewayTests { @Test(expected=MessageDeliveryException.class) public void sendMessage_failure() { + expect(messageMock.getHeaders()).andReturn(new MessageHeaders(null)); expect(requestChannel.send(messageMock)).andReturn(false); replay(allmocks); this.simpleMessagingGateway.send(messageMock); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/handler/ArgumentArrayMessageMapperToMessageTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/handler/ArgumentArrayMessageMapperToMessageTests.java index 41f2b298cd..6b655f2a44 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/handler/ArgumentArrayMessageMapperToMessageTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/handler/ArgumentArrayMessageMapperToMessageTests.java @@ -39,7 +39,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test public void toMessageWithPayload() throws Exception { Method method = TestService.class.getMethod("sendPayload", String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message message = mapper.toMessage(new Object[] { "test" }); assertEquals("test", message.getPayload()); } @@ -47,14 +47,14 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test(expected = IllegalArgumentException.class) public void toMessageWithTooManyParameters() throws Exception { Method method = TestService.class.getMethod("sendPayload", String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); mapper.toMessage(new Object[] { "test" , "oops" }); } @Test(expected = IllegalArgumentException.class) public void toMessageWithEmptyParameterArray() throws Exception { Method method = TestService.class.getMethod("sendPayload", String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); mapper.toMessage(new Object[] {}); } @@ -62,7 +62,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndHeader() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndHeader", String.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message message = mapper.toMessage(new Object[] { "test", "bar" }); assertEquals("test", message.getPayload()); assertEquals("bar", message.getHeaders().get("foo")); @@ -72,7 +72,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndRequiredHeaderButNullValue() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndHeader", String.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); mapper.toMessage(new Object[] { "test", null }); } @@ -80,7 +80,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndOptionalHeaderWithValueProvided() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndOptionalHeader", String.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message message = mapper.toMessage(new Object[] { "test", "bar" }); assertEquals("test", message.getPayload()); assertEquals("bar", message.getHeaders().get("foo")); @@ -90,7 +90,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndOptionalHeaderWithNullValue() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndOptionalHeader", String.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message message = mapper.toMessage(new Object[] { "test", null }); assertEquals("test", message.getPayload()); assertNull(message.getHeaders().get("foo")); @@ -100,7 +100,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndHeadersMap() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndHeadersMap", String.class, Map.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Map headers = new HashMap(); headers.put("abc", 123); headers.put("def", 456); @@ -114,7 +114,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndNullHeadersMap() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndHeadersMap", String.class, Map.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message message = mapper.toMessage(new Object[] { "test", null }); assertEquals("test", message.getPayload()); } @@ -123,7 +123,7 @@ public class ArgumentArrayMessageMapperToMessageTests { public void toMessageWithPayloadAndHeadersMapWithNonStringKey() throws Exception { Method method = TestService.class.getMethod( "sendPayloadAndHeadersMap", String.class, Map.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Map headers = new HashMap(); headers.put(123, "abc"); mapper.toMessage(new Object[] { "test", headers }); @@ -132,7 +132,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test public void toMessageWithMessageParameter() throws Exception { Method method = TestService.class.getMethod("sendMessage", Message.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message inputMessage = MessageBuilder.withPayload("test message").build(); Message message = mapper.toMessage(new Object[] { inputMessage }); assertEquals("test message", message.getPayload()); @@ -141,7 +141,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test public void toMessageWithMessageParameterAndHeader() throws Exception { Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message inputMessage = MessageBuilder.withPayload("test message").build(); Message message = mapper.toMessage(new Object[] { inputMessage, "bar" }); assertEquals("test message", message.getPayload()); @@ -151,7 +151,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test(expected = IllegalArgumentException.class) public void toMessageWithMessageParameterAndRequiredHeaderButNullValue() throws Exception { Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message inputMessage = MessageBuilder.withPayload("test message").build(); mapper.toMessage(new Object[] { inputMessage, null }); } @@ -159,7 +159,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test public void toMessageWithMessageParameterAndOptionalHeaderWithValue() throws Exception { Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message inputMessage = MessageBuilder.withPayload("test message").build(); Message message = mapper.toMessage(new Object[] { inputMessage, "bar" }); assertEquals("test message", message.getPayload()); @@ -169,7 +169,7 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test public void toMessageWithMessageParameterAndOptionalHeaderWithNull() throws Exception { Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); Message inputMessage = MessageBuilder.withPayload("test message").build(); Message message = mapper.toMessage(new Object[] { inputMessage, null }); assertEquals("test message", message.getPayload()); @@ -179,14 +179,14 @@ public class ArgumentArrayMessageMapperToMessageTests { @Test(expected = IllegalArgumentException.class) public void noArgs() throws Exception { Method method = TestService.class.getMethod("noArgs", new Class[] {}); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); mapper.toMessage(new Object[] {}); } @Test(expected = IllegalArgumentException.class) public void onlyHeaders() throws Exception { Method method = TestService.class.getMethod("onlyHeaders", String.class, String.class); - ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method, "testGateway"); + ArgumentArrayMessageMapper mapper = new ArgumentArrayMessageMapper(method); mapper.toMessage(new Object[] { "abc", "def" }); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/history/MessageHistoryTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/history/MessageHistoryTests.java index 93ebbbae69..dc0cb747b6 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/history/MessageHistoryTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/history/MessageHistoryTests.java @@ -22,6 +22,8 @@ import java.util.concurrent.TimeUnit; import org.junit.Test; +import org.springframework.integration.context.NamedComponent; + /** * @author Oleg Zhurakousky * @since 2.0 @@ -36,11 +38,19 @@ public class MessageHistoryTests { public void testConcurrentModificationsOnObjectMethods() throws Exception{ final MessageHistory history = new MessageHistory(); final MessageHistory otherHistory = new MessageHistory(); + final NamedComponent component = new NamedComponent() { + public String getComponentType() { + return "testType"; + } + public String getComponentName() { + return "testName"; + } + }; executor.execute(new Runnable() { public void run() { for (int i = 0; i < times; i++) { - history.addEvent("testName", "testType"); - otherHistory.addEvent("testName", "testType"); + history.addEvent(component); + otherHistory.addEvent(component); } } }); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/test/util/TestUtils.java b/org.springframework.integration/src/test/java/org/springframework/integration/test/util/TestUtils.java index 9c2d4a594e..14c93f828f 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/test/util/TestUtils.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/test/util/TestUtils.java @@ -31,10 +31,10 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.MessagePublishingErrorHandler; import org.springframework.integration.context.IntegrationContextUtils; +import org.springframework.integration.context.NamedComponent; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.endpoint.AbstractEndpoint; @@ -129,12 +129,12 @@ public abstract class TestUtils { } public void registerChannel(String channelName, MessageChannel channel) { - if (channel instanceof AbstractMessageChannel && ((AbstractMessageChannel) channel).getName() != null) { + if (channel instanceof NamedComponent && ((NamedComponent) channel).getComponentName() != null) { if (channelName == null) { - channelName = ((AbstractMessageChannel) channel).getName(); + channelName = ((NamedComponent) channel).getComponentName(); } else { - Assert.isTrue(((AbstractMessageChannel) channel).getName().equals(channelName), + Assert.isTrue(((NamedComponent) channel).getComponentName().equals(channelName), "channel name has already been set with a conflicting value"); } }