diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java index f92082ae5d..34d2532663 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/PointToPointChannelParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * 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. @@ -43,8 +43,12 @@ public class PointToPointChannelParser extends AbstractChannelParser { Element queueElement = null; if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) { builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".QueueChannel"); - this.parseQueueCapacity(builder, queueElement); - this.parseQueueRef(builder, queueElement); + boolean hasCapacity = this.parseQueueCapacity(builder, queueElement); + boolean hasQueueRef = this.parseQueueRef(builder, queueElement); + if (hasCapacity && hasQueueRef) { + parserContext.getReaderContext().error("The 'capacity' attribute is not allowed" + + " when providing a 'ref' to a custom queue.", element); + } } else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) { builder = BeanDefinitionBuilder.genericBeanDefinition(CHANNEL_PACKAGE + ".PriorityChannel"); @@ -78,17 +82,22 @@ public class PointToPointChannelParser extends AbstractChannelParser { // rely on the default for round-robin } - private void parseQueueCapacity(BeanDefinitionBuilder builder, Element queueElement) { + private boolean parseQueueCapacity(BeanDefinitionBuilder builder, Element queueElement) { String capacity = queueElement.getAttribute("capacity"); if (StringUtils.hasText(capacity)) { builder.addConstructorArgValue(capacity); + return true; } + return false; } - private void parseQueueRef(BeanDefinitionBuilder builder, Element queueElement) { + private boolean parseQueueRef(BeanDefinitionBuilder builder, Element queueElement) { String queueRef = queueElement.getAttribute("ref"); if (StringUtils.hasText(queueRef)){ builder.addConstructorArgReference(queueRef); + return true; } + return false; } + } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java index 6eb21d3e83..2503bbf447 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/ChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * 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. @@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -33,6 +34,7 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.channel.PublishSubscribeChannel; +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.TestChannelInterceptor; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; @@ -115,6 +117,17 @@ public class ChannelParserTests { assertEquals(taskExecutorBean, innerExecutor); } + @Test + public void channelWithCustomQueue() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "channelParserTests.xml", this.getClass()); + Object customQueue = context.getBean("customQueue"); + Object channelWithCustomQueue = context.getBean("channelWithCustomQueue"); + assertEquals(QueueChannel.class, channelWithCustomQueue.getClass()); + Object actualQueue = new DirectFieldAccessor(channelWithCustomQueue).getPropertyValue("queue"); + assertSame(customQueue, actualQueue); + } + @Test public void testDatatypeChannelWithCorrectType() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("channelParserTests.xml", this diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/channelParserTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/channelParserTests.xml index 9805bffed8..c62a2e70d4 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/channelParserTests.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/config/channelParserTests.xml @@ -14,6 +14,12 @@ + + + + + +