From 1b2ff13413ed38f9f13301e0c280648e1c31223b Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 10 Mar 2010 05:00:46 +0000 Subject: [PATCH] INT-930 falling back to a default ConversionService so that a bean does not have to be defined for common cases --- ...ractChannelNameResolvingMessageRouter.java | 29 ++++++++++++------- ...alueRouterConvertibleTypeTests-context.xml | 2 -- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java index 8015f1e71b..5a84437257 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.ConversionServiceFactory; import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolutionException; import org.springframework.integration.channel.ChannelResolver; @@ -140,17 +141,13 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract else if (channelIndicator instanceof Collection) { addToCollection(channels, (Collection) channelIndicator, message); } + else if (this.getConversionService().canConvert(channelIndicator.getClass(), String.class)) { + addChannelFromString(channels, + this.getConversionService().convert(channelIndicator, String.class), message); + } else { - if (this.conversionService == null && this.beanFactory != null) { - this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory); - } - if (this.conversionService != null - && this.conversionService.canConvert(channelIndicator.getClass(), String.class)) { - addChannelFromString(channels, this.conversionService.convert(channelIndicator, String.class), message); - } - else { - throw new MessagingException("unsupported return type for router [" + channelIndicator.getClass() + "]"); - } + throw new MessagingException( + "unsupported return type for router [" + channelIndicator.getClass() + "]"); } } } @@ -168,6 +165,18 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract } } + private ConversionService getConversionService() { + if (this.conversionService == null) { + if (this.beanFactory != null) { + this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory); + } + if (this.conversionService == null) { + this.conversionService = ConversionServiceFactory.createDefaultConversionService(); + } + } + return this.conversionService; + } + /** * Subclasses must implement this method to return the channel indicators. */ diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests-context.xml index 653451807c..e2b89166eb 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/HeaderValueRouterConvertibleTypeTests-context.xml @@ -20,6 +20,4 @@ - -