From dd66c98f6111c82efda64f4a50d9ae1f8f3ff1d8 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 20 Dec 2011 12:42:14 -0500 Subject: [PATCH] INT-2319 changed logic behind default group id for QueueChannel to be messageStoreId:channelId added support for resolving value if it is a placeholder --- .../config/xml/PointToPointChannelParser.java | 36 ++++++++++--------- ...nelWithMessageStoreParserTests-context.xml | 15 ++++---- .../ChannelWithMessageStoreParserTests.java | 2 +- .../integration/config/ms.properties | 1 + 4 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/config/ms.properties diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java index 5385da3851..be8934d43f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 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. @@ -18,11 +18,19 @@ package org.springframework.integration.config.xml; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Element; + +import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.ExecutorChannel; +import org.springframework.integration.channel.PriorityChannel; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.channel.RendezvousChannel; +import org.springframework.integration.store.MessageGroupQueue; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; /** * Parser for the <channel> element. @@ -33,12 +41,6 @@ import org.w3c.dom.Element; */ public class PointToPointChannelParser extends AbstractChannelParser { - private static final String CHANNEL_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".channel"; - - //private static final String DISPATCHER_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".dispatcher"; - - private static final String STORE_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".store"; - private final Log logger = LogFactory.getLog(this.getClass()); @Override @@ -48,7 +50,7 @@ public class PointToPointChannelParser extends AbstractChannelParser { // configure a queue-based channel if any queue sub-element is defined if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) { - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".QueueChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class); boolean hasStoreRef = this.parseStoreRef(builder, queueElement, element.getAttribute(ID_ATTRIBUTE)); boolean hasQueueRef = this.parseQueueRef(builder, queueElement); if (!hasStoreRef) { @@ -66,7 +68,7 @@ public class PointToPointChannelParser extends AbstractChannelParser { } } else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) { - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".PriorityChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class); this.parseQueueCapacity(builder, queueElement); String comparatorRef = queueElement.getAttribute("comparator"); if (StringUtils.hasText(comparatorRef)) { @@ -74,7 +76,7 @@ public class PointToPointChannelParser extends AbstractChannelParser { } } else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) { - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".RendezvousChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class); } Element dispatcherElement = DomUtils.getChildElementByTagName(element, "dispatcher"); @@ -110,7 +112,7 @@ public class PointToPointChannelParser extends AbstractChannelParser { if (hasDispatcherAttribute) { // this attribute is deprecated, but if set, we need to create a DirectChannel // without any LoadBalancerStrategy and the failover flag set to true (default). - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); if ("failover".equals(dispatcherAttribute)) { // round-robin dispatcher is used by default, the "failover" value simply disables it builder.addConstructorArgValue(null); @@ -118,17 +120,17 @@ public class PointToPointChannelParser extends AbstractChannelParser { } else if (dispatcherElement == null) { // configure the default DirectChannel with a RoundRobinLoadBalancingStrategy - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); } else { // configure either an ExecutorChannel or DirectChannel based on existence of 'task-executor' String taskExecutor = dispatcherElement.getAttribute("task-executor"); if (StringUtils.hasText(taskExecutor)) { - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".ExecutorChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(ExecutorChannel.class); builder.addConstructorArgReference(taskExecutor); } else { - builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".DirectChannel"); + builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); } // unless the 'load-balancer' attribute is explicitly set to 'none', // configure the default RoundRobinLoadBalancingStrategy @@ -163,9 +165,9 @@ public class PointToPointChannelParser extends AbstractChannelParser { String storeRef = queueElement.getAttribute("message-store"); if (StringUtils.hasText(storeRef)) { BeanDefinitionBuilder queueBuilder = BeanDefinitionBuilder - .genericBeanDefinition(STORE_PACKAGE + ".MessageGroupQueue"); + .genericBeanDefinition(MessageGroupQueue.class); queueBuilder.addConstructorArgReference(storeRef); - queueBuilder.addConstructorArgValue(STORE_PACKAGE + ":" + channel); + queueBuilder.addConstructorArgValue(new TypedStringValue(storeRef).getValue() + ":" + channel); parseQueueCapacity(queueBuilder, queueElement); builder.addConstructorArgValue(queueBuilder.getBeanDefinition()); return true; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests-context.xml index 42f6e6e49a..baaf3ee30b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests-context.xml @@ -1,13 +1,16 @@ - + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + + - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java index 84a2fe5d92..eb32cd091c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ChannelWithMessageStoreParserTests.java @@ -64,7 +64,7 @@ public class ChannelWithMessageStoreParserTests { handler.getLatch().await(100, TimeUnit.MILLISECONDS); assertEquals("The message payload is not correct", "123", handler.getMessageString()); // The group id for buffered messages is the channel name - assertEquals(1, messageGroupStore.getMessageGroup(BASE_PACKAGE+".store:output").size()); + assertEquals(1, messageGroupStore.getMessageGroup("messageStore:output").size()); Message result = output.receive(100); assertEquals("hello", result.getPayload()); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/ms.properties b/spring-integration-core/src/test/java/org/springframework/integration/config/ms.properties new file mode 100644 index 0000000000..7521049ed4 --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/ms.properties @@ -0,0 +1 @@ +ms=messageStore \ No newline at end of file