diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java index bb0880403a..edff86dd19 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java @@ -82,6 +82,7 @@ public class IntegrationNamespaceHandler implements NamespaceHandler { registerBeanDefinitionParser("router", new DefaultRouterParser()); registerBeanDefinitionParser("header-value-router", new HeaderValueRouterParser()); registerBeanDefinitionParser("payload-type-router", new PayloadTypeRouterParser()); + registerBeanDefinitionParser("recipient-list-router", new RecipientListRouterParser()); registerBeanDefinitionParser("splitter", new SplitterParser()); registerBeanDefinitionParser("aggregator", new AggregatorParser()); registerBeanDefinitionParser("resequencer", new ResequencerParser()); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java new file mode 100644 index 0000000000..4f8c67167c --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/RecipientListRouterParser.java @@ -0,0 +1,55 @@ +/* + * 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.config.xml; + +import java.util.List; + +import org.springframework.beans.factory.config.RuntimeBeanReference; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.Assert; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +/** + * Parser for the <recipient-list-router/> element. + * + * @author Oleg Zhurakousky + * @since 1.0.3 + */ +public class RecipientListRouterParser extends AbstractConsumerEndpointParser { + + @Override + protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { + BeanDefinitionBuilder recipientListRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition( + IntegrationNamespaceUtils.BASE_PACKAGE + ".router.RecipientListRouter"); + List childElements = DomUtils.getChildElementsByTagName(element, "recipient"); + Assert.notEmpty(childElements, + "Recipient channel(s) must be defined (e.g., )"); + + ManagedList channelList = new ManagedList(); + for (Element childElement : childElements) { + channelList.add(new RuntimeBeanReference(childElement.getAttribute("channel"))); + } + recipientListRouterBuilder.addPropertyValue("channels", channelList); + IntegrationNamespaceUtils.setValueIfAttributeDefined(recipientListRouterBuilder, element, "timeout"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(recipientListRouterBuilder, element, "ignore-send-failures"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(recipientListRouterBuilder, element, "apply-sequence"); + return recipientListRouterBuilder; + } + +} diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd index 2cee56b77c..37f646489a 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd @@ -883,6 +883,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests-context.xml new file mode 100644 index 0000000000..7ee05d7c79 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests-context.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java new file mode 100644 index 0000000000..d62d6e904f --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/router/config/RecipientListRouterParserTests.java @@ -0,0 +1,60 @@ +/* + * 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.router.config; +/** + * Parser for the <recipient-list-router/> element. + * + * @author Oleg Zhurakousky + * @since 1.0.3 + */ +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.integration.channel.PollableChannel; +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.message.GenericMessage; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class RecipientListRouterParserTests { + @Autowired + private ConfigurableApplicationContext context; + @Autowired + @Qualifier("routingChannel") + private MessageChannel channel; + + @Test + public void testRecipientListRouterNamespaceConfig() { + context.start(); + + Message message = new GenericMessage(1); + channel.send(message); + + PollableChannel chanel1 = (PollableChannel) context.getBean("channel1"); + PollableChannel chanel2 = (PollableChannel) context.getBean("channel2"); + assertTrue(chanel1.receive().getPayload().equals(1)); + assertTrue(chanel2.receive().getPayload().equals(1)); + + } + + +}