INT-697, added namespace support for RecipientListRouter

This commit is contained in:
Oleg Zhurakousky
2009-07-02 00:05:57 +00:00
parent f2529d1dc2
commit 6817d053d9
5 changed files with 158 additions and 0 deletions

View File

@@ -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());

View File

@@ -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<Element> childElements = DomUtils.getChildElementsByTagName(element, "recipient");
Assert.notEmpty(childElements,
"Recipient channel(s) must be defined (e.g., <recipient channel=\"channel1\"/>)");
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;
}
}

View File

@@ -883,6 +883,27 @@
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="recipient-list-router">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines a Recipient List Router.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="routerType">
<xsd:sequence>
<xsd:element name="recipient" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="channel" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="payload-type-router">
<xsd:annotation>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<channel id="channel1">
<queue capacity="1" />
</channel>
<channel id="channel2">
<queue capacity="1" />
</channel>
<channel id="routingChannel" />
<recipient-list-router input-channel="routingChannel" timeout="1000">
<recipient channel="channel1"/>
<recipient channel="channel2"/>
</recipient-list-router>
</beans:beans>

View File

@@ -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 &lt;recipient-list-router/&gt; 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<Integer>(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));
}
}