INT-1377 - first round of Router hierarchy refactoring to make them more dynamic, moved every router under ACNRMR (later ACNRMR will be merged with AMR), removed type preloading in PTR parser, fixed tests, removed MapBasedChannelResolver and related tests. fixed test for other components that were dependent on MapBasedChannelResolver
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2009 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.channel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.support.channel.ChannelResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link ChannelResolver} implementation that resolves {@link MessageChannel}
|
||||
* instances by matching the channel name against keys within a Map.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MapBasedChannelResolver implements ChannelResolver {
|
||||
|
||||
private volatile Map<String, ? extends MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
|
||||
/**
|
||||
* Empty constructor for use when providing the channel map via
|
||||
* {@link #setChannelMap(Map)}.
|
||||
*/
|
||||
public MapBasedChannelResolver() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link ChannelResolver} that uses the provided Map.
|
||||
* Each String key will resolve to the associated channel value.
|
||||
*/
|
||||
public MapBasedChannelResolver(Map<String, ? extends MessageChannel> channelMap) {
|
||||
this.setChannelMap(channelMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a map of channels to be used by this resolver.
|
||||
* Each String key will resolve to the associated channel value.
|
||||
*/
|
||||
public void setChannelMap(Map<String, ? extends MessageChannel> channelMap) {
|
||||
Assert.notNull(channelMap, "channelMap must not be null");
|
||||
this.channelMap = channelMap;
|
||||
}
|
||||
|
||||
public MessageChannel resolveChannelName(String channelName) {
|
||||
return this.channelMap.get(channelName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -31,10 +33,13 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Jonas Partner
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class RouterFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
|
||||
private volatile ChannelResolver channelResolver;
|
||||
|
||||
private volatile Map<String, String> channelIdentifierMap;
|
||||
|
||||
private volatile MessageChannel defaultOutputChannel;
|
||||
|
||||
@@ -75,6 +80,10 @@ public class RouterFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
public void setIgnoreSendFailures(Boolean ignoreSendFailures) {
|
||||
this.ignoreSendFailures = ignoreSendFailures;
|
||||
}
|
||||
|
||||
public void setChannelIdentifierMap(Map<String, String> channelIdentifierMap) {
|
||||
this.channelIdentifierMap = channelIdentifierMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
|
||||
@@ -138,6 +147,9 @@ public class RouterFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
if (this.channelResolver != null && router instanceof AbstractChannelNameResolvingMessageRouter) {
|
||||
((AbstractChannelNameResolvingMessageRouter) router).setChannelResolver(this.channelResolver);
|
||||
}
|
||||
if (this.channelIdentifierMap != null && router instanceof AbstractChannelNameResolvingMessageRouter) {
|
||||
((AbstractChannelNameResolvingMessageRouter) router).setChannelIdentifierMap(this.channelIdentifierMap);
|
||||
}
|
||||
if (this.defaultOutputChannel != null) {
|
||||
router.setDefaultOutputChannel(this.defaultOutputChannel);
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Base parser for routers that create instances that are subclasses of AbstractChannelNameResolvingMessageRouter.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public abstract class AbstractChannelNameResolvingRouterParser extends AbstractRouterParser {
|
||||
|
||||
@@ -42,13 +42,23 @@ public abstract class AbstractChannelNameResolvingRouterParser extends AbstractR
|
||||
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "mapping");
|
||||
if (childElements != null && childElements.size() > 0) {
|
||||
BeanDefinitionBuilder channelResolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.MapBasedChannelResolver");
|
||||
ManagedMap<String, RuntimeBeanReference> channelMap = new ManagedMap<String, RuntimeBeanReference>();
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".support.channel.BeanFactoryChannelResolver");
|
||||
ManagedMap<String, String> channelMap = new ManagedMap<String, String>();
|
||||
for (Element childElement : childElements) {
|
||||
channelMap.put(childElement.getAttribute("value"),
|
||||
new RuntimeBeanReference(childElement.getAttribute("channel")));
|
||||
String beanClassName = beanDefinition.getBeanClassName();
|
||||
String key = null;
|
||||
if (beanClassName.endsWith("PayloadTypeRouter")){
|
||||
key = childElement.getAttribute("type");
|
||||
}
|
||||
else if (beanClassName.endsWith("HeaderValueRouter")){
|
||||
key = childElement.getAttribute("value");
|
||||
}
|
||||
else {
|
||||
throw new BeanCreationException("Building '" + beanClassName + "' is not supported by this parser");
|
||||
}
|
||||
channelMap.put(key, childElement.getAttribute("channel"));
|
||||
}
|
||||
channelResolverBuilder.addPropertyValue("channelMap", channelMap);
|
||||
beanDefinition.getPropertyValues().add("channelIdentifierMap", channelMap);
|
||||
beanDefinition.getPropertyValues().add("channelResolver", channelResolverBuilder.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@ package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
@@ -28,11 +25,13 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <router/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class DefaultRouterParser extends AbstractDelegatingConsumerEndpointParser {
|
||||
|
||||
@@ -60,13 +59,12 @@ public class DefaultRouterParser extends AbstractDelegatingConsumerEndpointParse
|
||||
parserContext.extractSource(element));
|
||||
}
|
||||
BeanDefinitionBuilder channelResolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.MapBasedChannelResolver");
|
||||
ManagedMap<String, RuntimeBeanReference> channelMap = new ManagedMap<String, RuntimeBeanReference>();
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".support.channel.BeanFactoryChannelResolver");
|
||||
ManagedMap<String, String> channelMap = new ManagedMap<String, String>();
|
||||
for (Element mappingElement : mappingElements) {
|
||||
channelMap.put(mappingElement.getAttribute("value"),
|
||||
new RuntimeBeanReference(mappingElement.getAttribute("channel")));
|
||||
channelMap.put(mappingElement.getAttribute("value"), mappingElement.getAttribute("channel"));
|
||||
}
|
||||
channelResolverBuilder.addPropertyValue("channelMap", channelMap);
|
||||
builder.addPropertyValue("channelIdentifierMap", channelMap);
|
||||
builder.addPropertyValue(CHANNEL_RESOLVER_PROPERTY, channelResolverBuilder.getBeanDefinition());
|
||||
}
|
||||
else if (StringUtils.hasText(resolverBeanName)) {
|
||||
|
||||
@@ -16,19 +16,10 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <payload-type-router/> element.
|
||||
@@ -37,27 +28,13 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Mark Fisher
|
||||
* @since 1.0.3
|
||||
*/
|
||||
public class PayloadTypeRouterParser extends AbstractRouterParser {
|
||||
|
||||
public class PayloadTypeRouterParser extends AbstractChannelNameResolvingRouterParser {
|
||||
|
||||
@Override
|
||||
protected BeanDefinition parseRouter(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder payloadTypeRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
protected BeanDefinition doParseRouter(Element element,
|
||||
ParserContext parserContext) {
|
||||
BeanDefinitionBuilder headerValueRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".router.PayloadTypeRouter");
|
||||
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "mapping");
|
||||
Assert.notEmpty(childElements,
|
||||
"Type mapping must be provided (e.g., <mapping type=\"X\" channel=\"channel1\"/>)");
|
||||
ManagedMap<String, BeanMetadataElement> channelMap = new ManagedMap<String, BeanMetadataElement>();
|
||||
for (Element childElement : childElements) {
|
||||
String typeName = childElement.getAttribute("type");
|
||||
ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = ClassUtils.getDefaultClassLoader();
|
||||
}
|
||||
Assert.isTrue(ClassUtils.isPresent(typeName, classLoader), typeName + " can not be loaded");
|
||||
channelMap.put(typeName, new RuntimeBeanReference(childElement.getAttribute("channel")));
|
||||
}
|
||||
payloadTypeRouterBuilder.addPropertyValue("payloadTypeChannelMap", channelMap);
|
||||
return payloadTypeRouterBuilder.getBeanDefinition();
|
||||
return headerValueRouterBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,10 +53,9 @@ public class PublishingInterceptorParser extends AbstractBeanDefinitionParser {
|
||||
spelSourceBuilder.addPropertyValue("headerExpressionMap", mappings.get("headers"));
|
||||
}
|
||||
BeanDefinitionBuilder chResolverBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
"org.springframework.integration.channel.MapBasedChannelResolver");
|
||||
"org.springframework.integration.support.channel.BeanFactoryChannelResolver");
|
||||
if (mappings.get("channels") != null){
|
||||
spelSourceBuilder.addPropertyValue("channelMap", mappings.get("channels"));
|
||||
chResolverBuilder.addConstructorArgValue(mappings.get("resolvableChannels"));
|
||||
}
|
||||
String chResolverName =
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(chResolverBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -39,6 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Jonas Partner
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public abstract class AbstractChannelNameResolvingMessageRouter extends AbstractMessageRouter {
|
||||
|
||||
@@ -49,6 +51,8 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract
|
||||
private volatile ChannelResolver channelResolver;
|
||||
|
||||
private volatile boolean ignoreChannelNameResolutionFailures;
|
||||
|
||||
protected volatile Map<String, String> channelIdentifierMap;
|
||||
|
||||
|
||||
/**
|
||||
@@ -155,32 +159,58 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract
|
||||
}
|
||||
}
|
||||
|
||||
private void addChannelFromString(Collection<MessageChannel> channels, String channelName, Message<?> message) {
|
||||
if (channelName.indexOf(',') != -1) {
|
||||
for (String name : StringUtils.commaDelimitedListToStringArray(channelName)) {
|
||||
private void addChannelFromString(Collection<MessageChannel> channels, String channelIdentifier, Message<?> message) {
|
||||
if (channelIdentifier.indexOf(',') != -1) {
|
||||
for (String name : StringUtils.commaDelimitedListToStringArray(channelIdentifier)) {
|
||||
addChannelFromString(channels, name, message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.prefix != null) {
|
||||
channelName = this.prefix + channelName;
|
||||
channelIdentifier = this.prefix + channelIdentifier;
|
||||
}
|
||||
if (this.suffix != null) {
|
||||
channelName = channelName + suffix;
|
||||
channelIdentifier = channelIdentifier + suffix;
|
||||
}
|
||||
MessageChannel channel = resolveChannelForName(channelName, message);
|
||||
if (channel != null) {
|
||||
channels.add(channel);
|
||||
/*
|
||||
* Some routers due to their complex nature will already resolve 'channelIdentifier'
|
||||
* to 'channelName' (e.g., PTR, EMETR)
|
||||
*/
|
||||
String channelName = channelIdentifier;
|
||||
if (channelIdentifierMap != null && channelIdentifierMap.containsKey(channelIdentifier)){
|
||||
channelName = channelIdentifierMap.get(channelIdentifier);
|
||||
}
|
||||
|
||||
if (this.channelResolver != null){
|
||||
MessageChannel channel = resolveChannelForName(channelName, message);
|
||||
if (channel != null) {
|
||||
channels.add(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ConversionService getRequiredConversionService() {
|
||||
protected ConversionService getRequiredConversionService() {
|
||||
if (this.getConversionService() == null) {
|
||||
this.setConversionService(ConversionServiceFactory.createDefaultConversionService());
|
||||
}
|
||||
return this.getConversionService();
|
||||
}
|
||||
|
||||
public Map<String, String> getChannelIdentifierMap() {
|
||||
return channelIdentifierMap;
|
||||
}
|
||||
|
||||
public void setChannelIdentifierMap(Map<String, String> channelIdentifierMap) {
|
||||
this.channelIdentifierMap = channelIdentifierMap;
|
||||
}
|
||||
|
||||
public void setChannelMapping(String channelIdentifier, String channelName){
|
||||
this.channelIdentifierMap.put(channelIdentifier, channelName);
|
||||
}
|
||||
|
||||
public void removeChannelMapping(String channelIdentifier){
|
||||
this.channelIdentifierMap.remove(channelIdentifier);
|
||||
}
|
||||
/**
|
||||
* Subclasses must implement this method to return the channel indicators.
|
||||
*/
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A Message Router that resolves the target {@link MessageChannel} for
|
||||
@@ -29,34 +28,26 @@ import org.springframework.util.Assert;
|
||||
* the most specific cause of the error for which a channel-mapping exists.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ErrorMessageExceptionTypeRouter extends AbstractSingleChannelRouter {
|
||||
|
||||
private volatile Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new ConcurrentHashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
|
||||
|
||||
public void setExceptionTypeChannelMap(Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap) {
|
||||
Assert.notNull(exceptionTypeChannelMap, "exceptionTypeChannelMap must not be null");
|
||||
this.exceptionTypeChannelMap = exceptionTypeChannelMap;
|
||||
}
|
||||
|
||||
public class ErrorMessageExceptionTypeRouter extends AbstractChannelNameResolvingMessageRouter {
|
||||
|
||||
@Override
|
||||
protected MessageChannel determineTargetChannel(Message<?> message) {
|
||||
MessageChannel channel = null;
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
String channelName = null;
|
||||
String channelIdentifier = null;
|
||||
Object payload = message.getPayload();
|
||||
if (payload != null && (payload instanceof Throwable)) {
|
||||
Throwable mostSpecificCause = (Throwable) payload;
|
||||
while (mostSpecificCause != null) {
|
||||
MessageChannel mappedChannel = this.exceptionTypeChannelMap.get(mostSpecificCause.getClass());
|
||||
if (mappedChannel != null) {
|
||||
channel = mappedChannel;
|
||||
channelIdentifier = mostSpecificCause.getClass().getName();
|
||||
if (channelIdentifierMap != null){
|
||||
String tempChannelName = channelIdentifierMap.get(channelIdentifier);
|
||||
channelName = tempChannelName == null ? channelName : tempChannelName;
|
||||
}
|
||||
mostSpecificCause = mostSpecificCause.getCause();
|
||||
}
|
||||
}
|
||||
return channel;
|
||||
return Collections.singletonList((Object)channelName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,39 +16,54 @@
|
||||
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.util.ClassUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A Message Router that resolves the {@link MessageChannel} based on the
|
||||
* {@link Message Message's} payload type.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class PayloadTypeRouter extends AbstractSingleChannelRouter {
|
||||
|
||||
private volatile Map<Class<?>, MessageChannel> payloadTypeChannelMap =
|
||||
new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
|
||||
|
||||
public void setPayloadTypeChannelMap(Map<Class<?>, MessageChannel> payloadTypeChannelMap) {
|
||||
Assert.notNull(payloadTypeChannelMap, "payloadTypeChannelMap must not be null");
|
||||
this.payloadTypeChannelMap = payloadTypeChannelMap;
|
||||
}
|
||||
public class PayloadTypeRouter extends AbstractChannelNameResolvingMessageRouter {
|
||||
|
||||
@Override
|
||||
protected MessageChannel determineTargetChannel(Message<?> message) {
|
||||
Class<?> closestMatch = ClassUtils.findClosestMatch(
|
||||
message.getPayload().getClass(), this.payloadTypeChannelMap.keySet(), true);
|
||||
if (closestMatch != null) {
|
||||
return this.payloadTypeChannelMap.get(closestMatch);
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
Class<?> firstInterfaceMatch = null;
|
||||
Class<?> type = message.getPayload().getClass();
|
||||
|
||||
while (type != null) {
|
||||
Class<?>[] interfaces = type.getInterfaces();
|
||||
// first try to find a match amongst the interfaces and also check if there is more then one
|
||||
for (Class<?> interfase : interfaces) {
|
||||
if (channelIdentifierMap.containsKey(interfase.getName())){
|
||||
if (firstInterfaceMatch != null){
|
||||
throw new IllegalStateException("Unresolvable ambiguity while attempting to find closest match for [" +
|
||||
type.getName() + "]. Candidate types [" + firstInterfaceMatch.getName() + "] and [" + interfase.getName() +
|
||||
"] have equal weight.");
|
||||
}
|
||||
else {
|
||||
firstInterfaceMatch = interfase;
|
||||
}
|
||||
}
|
||||
}
|
||||
// the actual type should favor the possible interface match
|
||||
String channelName = channelIdentifierMap.get(type.getName());
|
||||
if (!StringUtils.hasText(channelName)){
|
||||
if (firstInterfaceMatch != null){
|
||||
return Collections.singletonList((Object)channelIdentifierMap.get(firstInterfaceMatch.getName()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Collections.singletonList((Object)channelName);
|
||||
}
|
||||
type = type.getSuperclass();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,17 +20,17 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -39,14 +39,16 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
*/
|
||||
public class MessagePublishingInterceptorTests {
|
||||
|
||||
private final MapBasedChannelResolver channelResolver = new MapBasedChannelResolver();
|
||||
private ChannelResolver channelResolver;
|
||||
|
||||
private final QueueChannel testChannel = new QueueChannel();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
channelResolver.setChannelMap(Collections.singletonMap("c", testChannel));
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
channelResolver = new BeanFactoryChannelResolver(beanFactory);
|
||||
beanFactory.registerSingleton("c", testChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,19 +37,19 @@
|
||||
</property>
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="setName" value="channel" />
|
||||
<entry key="setName" value="messagePublishingInterceptorUsageTestChannel" />
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
<property name="channelResolver">
|
||||
<bean
|
||||
class="org.springframework.integration.channel.MapBasedChannelResolver">
|
||||
<property name="channelMap">
|
||||
<map>
|
||||
<entry key="channel" value-ref="messagePublishingInterceptorUsageTestChannel" />
|
||||
</map>
|
||||
</property>
|
||||
class="org.springframework.integration.support.channel.BeanFactoryChannelResolver">
|
||||
<!-- <property name="channelMap">-->
|
||||
<!-- <map>-->
|
||||
<!-- <entry key="channel" value-ref="messagePublishingInterceptorUsageTestChannel" />-->
|
||||
<!-- </map>-->
|
||||
<!-- </property>-->
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.channel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.MessageChannel;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MapBasedChannelResolverTests {
|
||||
|
||||
@Test
|
||||
public void mapContainsChannel() {
|
||||
MessageChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("testChannel");
|
||||
assertNotNull(result);
|
||||
assertEquals(testChannel, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapDoesNotContainChannel() {
|
||||
MessageChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("noSuchChannel");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyMap() {
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(channelMap);
|
||||
MessageChannel result = resolver.resolveChannelName("testChannel");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nullMapRejected() {
|
||||
MapBasedChannelResolver resolver = new MapBasedChannelResolver();
|
||||
resolver.setChannelMap(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
<bean id="payloadTypeRouter" class="org.springframework.integration.router.PayloadTypeRouter">
|
||||
<property name="resolutionRequired" value="true"/>
|
||||
<property name="payloadTypeChannelMap">
|
||||
<property name="channelIdentifierMap">
|
||||
<map>
|
||||
<entry key="java.lang.String" value-ref="strings"/>
|
||||
<entry key="java.lang.String" value="strings"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -31,12 +31,12 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
@@ -45,6 +45,7 @@ import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.support.converter.SimpleMessageConverter;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
@@ -306,9 +307,12 @@ public class MessagingTemplateTests {
|
||||
@Test
|
||||
public void sendByChannelNameWithCustomChannelResolver() {
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
// Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
// channelMap.put("testChannel", testChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("testChannel", testChannel);
|
||||
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(beanFactory);
|
||||
// MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
MessagingTemplate template = new MessagingTemplate();
|
||||
template.setChannelResolver(channelResolver);
|
||||
template.afterPropertiesSet();
|
||||
@@ -352,11 +356,11 @@ public class MessagingTemplateTests {
|
||||
@Test
|
||||
public void receiveByChannelNameWithCustomChannelResolver() {
|
||||
QueueChannel testChannel = new QueueChannel();
|
||||
Map<String, MessageChannel> channelMap = new HashMap<String, MessageChannel>();
|
||||
channelMap.put("testChannel", testChannel);
|
||||
MapBasedChannelResolver channelResolver = new MapBasedChannelResolver(channelMap);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("testChannel", testChannel);
|
||||
|
||||
MessagingTemplate template = new MessagingTemplate();
|
||||
template.setChannelResolver(channelResolver);
|
||||
template.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
template.afterPropertiesSet();
|
||||
Message<?> message = MessageBuilder.withPayload("test").build();
|
||||
testChannel.send(message);
|
||||
|
||||
@@ -22,20 +22,24 @@ import static org.junit.Assert.assertNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ErrorMessageExceptionTypeRouterTests {
|
||||
|
||||
private DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
|
||||
private QueueChannel illegalArgumentChannel = new QueueChannel();
|
||||
|
||||
@@ -46,6 +50,15 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
private QueueChannel messageDeliveryExceptionChannel = new QueueChannel();
|
||||
|
||||
private QueueChannel defaultChannel = new QueueChannel();
|
||||
|
||||
@Before
|
||||
public void prepare(){
|
||||
beanFactory.registerSingleton("illegalArgumentChannel", illegalArgumentChannel);
|
||||
beanFactory.registerSingleton("runtimeExceptionChannel", runtimeExceptionChannel);
|
||||
beanFactory.registerSingleton("messageHandlingExceptionChannel", messageHandlingExceptionChannel);
|
||||
beanFactory.registerSingleton("messageDeliveryExceptionChannel", messageDeliveryExceptionChannel);
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@@ -56,12 +69,14 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
@@ -78,11 +93,12 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "runtimeExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(runtimeExceptionChannel.receive(1000));
|
||||
@@ -99,10 +115,10 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(messageHandlingExceptionChannel.receive(1000));
|
||||
@@ -135,10 +151,10 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(MessageDeliveryException.class, messageDeliveryExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(MessageDeliveryException.class.getName(), "messageDeliveryExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setResolutionRequired(true);
|
||||
router.handleMessage(message);
|
||||
}
|
||||
@@ -151,12 +167,12 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
Message<?> message = new GenericMessage<Exception>(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(RuntimeException.class, runtimeExceptionChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(RuntimeException.class.getName(), "runtimeExceptionChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
@@ -173,11 +189,11 @@ public class ErrorMessageExceptionTypeRouterTests {
|
||||
MessageHandlingException error = new MessageHandlingException(failedMessage, "failed", middleCause);
|
||||
ErrorMessage message = new ErrorMessage(error);
|
||||
ErrorMessageExceptionTypeRouter router = new ErrorMessageExceptionTypeRouter();
|
||||
Map<Class<? extends Throwable>, MessageChannel> exceptionTypeChannelMap =
|
||||
new HashMap<Class<? extends Throwable>, MessageChannel>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class, illegalArgumentChannel);
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class, messageHandlingExceptionChannel);
|
||||
router.setExceptionTypeChannelMap(exceptionTypeChannelMap);
|
||||
Map<String, String> exceptionTypeChannelMap = new HashMap<String, String>();
|
||||
exceptionTypeChannelMap.put(IllegalArgumentException.class.getName(), "illegalArgumentChannel");
|
||||
exceptionTypeChannelMap.put(MessageHandlingException.class.getName(), "messageHandlingExceptionChannel");
|
||||
router.setChannelIdentifierMap(exceptionTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
router.handleMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
|
||||
@@ -20,19 +20,19 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.MapBasedChannelResolver;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class HeaderValueRouterTests {
|
||||
|
||||
@@ -76,12 +76,13 @@ public class HeaderValueRouterTests {
|
||||
public void resolveChannelNameFromMap() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
ManagedMap channelMap = new ManagedMap();
|
||||
channelMap.put("testKey", new RuntimeBeanReference("testChannel"));
|
||||
RootBeanDefinition channelResolverBeanDefinition = new RootBeanDefinition(MapBasedChannelResolver.class);
|
||||
channelResolverBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue(channelMap);
|
||||
channelMap.put("testKey", "testChannel");
|
||||
RootBeanDefinition channelResolverBeanDefinition = new RootBeanDefinition(BeanFactoryChannelResolver.class);
|
||||
channelResolverBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue(context);
|
||||
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
|
||||
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("channelIdentifierMap", channelMap);
|
||||
routerBeanDefinition.getPropertyValues().addPropertyValue("channelResolver", new RuntimeBeanReference("resolver"));
|
||||
context.registerBeanDefinition("resolver", channelResolverBeanDefinition);
|
||||
context.registerBeanDefinition("router", routerBeanDefinition);
|
||||
|
||||
@@ -18,16 +18,19 @@ package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -81,6 +84,7 @@ public class MultiChannelRouterTests {
|
||||
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"});
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
router.handleMessage(message);
|
||||
}
|
||||
|
||||
@@ -25,15 +25,17 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class PayloadTypeRouterTests {
|
||||
|
||||
@@ -41,15 +43,24 @@ public class PayloadTypeRouterTests {
|
||||
public void resolveExactMatch() {
|
||||
QueueChannel stringChannel = new QueueChannel();
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
MessageChannel result1 = router.determineTargetChannel(message1);
|
||||
MessageChannel result2 = router.determineTargetChannel(message2);
|
||||
MessageChannel result1 = router.determineTargetChannels(message1).iterator().next();
|
||||
MessageChannel result2 = router.determineTargetChannels(message2).iterator().next();
|
||||
//MessageChannel result1 = router.determineTargetChannel(message1);
|
||||
//MessageChannel result2 = router.determineTargetChannel(message2);
|
||||
assertEquals(stringChannel, result1);
|
||||
assertEquals(integerChannel, result2);
|
||||
}
|
||||
@@ -60,10 +71,15 @@ public class PayloadTypeRouterTests {
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
QueueChannel numberChannel = new QueueChannel();
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -81,11 +97,20 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
integerChannel.setBeanName("integerChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -102,10 +127,18 @@ public class PayloadTypeRouterTests {
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -123,11 +156,20 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -146,11 +188,20 @@ public class PayloadTypeRouterTests {
|
||||
serializableChannel.setBeanName("serializableChannel");
|
||||
QueueChannel comparableChannel = new QueueChannel();
|
||||
comparableChannel.setBeanName("comparableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Serializable.class, serializableChannel);
|
||||
payloadTypeChannelMap.put(Comparable.class, comparableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("serializableChannel", serializableChannel);
|
||||
beanFactory.registerSingleton("comparableChannel", comparableChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
|
||||
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<String> message = new GenericMessage<String>("test");
|
||||
try {
|
||||
@@ -169,11 +220,22 @@ public class PayloadTypeRouterTests {
|
||||
numberChannel.setBeanName("numberChannel");
|
||||
QueueChannel serializableChannel = new QueueChannel();
|
||||
serializableChannel.setBeanName("serializableChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(Number.class, numberChannel);
|
||||
payloadTypeChannelMap.put(Serializable.class, serializableChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
beanFactory.registerSingleton("numberChannel", numberChannel);
|
||||
beanFactory.registerSingleton("serializableChannel", serializableChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
|
||||
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
|
||||
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<Integer> message = new GenericMessage<Integer>(99);
|
||||
router.handleMessage(message);
|
||||
@@ -190,11 +252,19 @@ public class PayloadTypeRouterTests {
|
||||
QueueChannel integerChannel = new QueueChannel();
|
||||
stringChannel.setBeanName("stringChannel");
|
||||
integerChannel.setBeanName("integerChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
payloadTypeChannelMap.put(Integer.class, integerChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("integerChannel", integerChannel);
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
router.handleMessage(message1);
|
||||
@@ -211,10 +281,19 @@ public class PayloadTypeRouterTests {
|
||||
stringChannel.setBeanName("stringChannel");
|
||||
QueueChannel defaultChannel = new QueueChannel();
|
||||
defaultChannel.setBeanName("defaultChannel");
|
||||
Map<Class<?>, MessageChannel> payloadTypeChannelMap = new ConcurrentHashMap<Class<?>, MessageChannel>();
|
||||
payloadTypeChannelMap.put(String.class, stringChannel);
|
||||
|
||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||
beanFactory.registerSingleton("stringChannel", stringChannel);
|
||||
beanFactory.registerSingleton("defaultChannel", defaultChannel);
|
||||
|
||||
|
||||
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
|
||||
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
|
||||
PayloadTypeRouter router = new PayloadTypeRouter();
|
||||
router.setPayloadTypeChannelMap(payloadTypeChannelMap);
|
||||
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(beanFactory));
|
||||
router.setChannelIdentifierMap(payloadTypeChannelMap);
|
||||
|
||||
router.setDefaultOutputChannel(defaultChannel);
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
@@ -32,6 +34,7 @@ import org.springframework.integration.MessagingException;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.TestChannelResolver;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
@@ -148,6 +151,7 @@ public class RouterTests {
|
||||
return "notImportant";
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
router.handleMessage(new GenericMessage<String>("this should fail"));
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ public class RouterTests {
|
||||
return CollectionUtils.arrayToList(new String[] { "notImportant" });
|
||||
}
|
||||
};
|
||||
router.setChannelResolver(new BeanFactoryChannelResolver(mock(BeanFactory.class)));
|
||||
router.handleMessage(new GenericMessage<String>("this should fail"));
|
||||
}
|
||||
|
||||
|
||||
@@ -61,15 +61,6 @@ public class PayloadTypeRouterParserTests {
|
||||
assertTrue(chanel2.receive(0).getPayload() instanceof Integer);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testFakeTypes(){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(routerConfigFakeType.getBytes());
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
|
||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||
reader.loadBeanDefinitions(new InputStreamResource(stream));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testNoMappingElement(){
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(routerConfigNoMaping.getBytes());
|
||||
|
||||
Reference in New Issue
Block a user