INT-1076 added support for the 'ignore-channel-name-resolution-failures' attribute on <xpath-router/> elements.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -23,13 +23,15 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
|
||||
import org.springframework.integration.xml.router.XPathMultiChannelRouter;
|
||||
import org.springframework.integration.xml.router.XPathSingleChannelRouter;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <xpath-router/> element.
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class XPathRouterParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
@@ -48,29 +50,19 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
@Override
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
boolean multiChannel = Boolean.parseBoolean(element.getAttribute("multi-channel"));
|
||||
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
|
||||
String channelResolver = element.getAttribute("channel-resolver");
|
||||
String resolutionRequired = element.getAttribute("resolution-required");
|
||||
String defaultOutputChannel = element.getAttribute("default-output-channel");
|
||||
|
||||
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(
|
||||
element.getNamespaceURI(), "xpath-expression");
|
||||
Assert.isTrue(xPathExpressionNodes.getLength() < 2,
|
||||
"Only one xpath-expression child can be specified.");
|
||||
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
|
||||
boolean xPathExpressionChildPresent = (xPathExpressionNodes.getLength() == 1);
|
||||
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
|
||||
|
||||
Assert.isTrue(xPathExpressionChildPresent ^ xPathReferencePresent,
|
||||
"Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
|
||||
if (multiChannel) {
|
||||
builder.getBeanDefinition().setBeanClass(XPathMultiChannelRouter.class);
|
||||
}
|
||||
else {
|
||||
builder.getBeanDefinition().setBeanClass(XPathSingleChannelRouter.class);
|
||||
}
|
||||
boolean multiChannel = Boolean.parseBoolean(element.getAttribute("multi-channel"));
|
||||
String classname = "org.springframework.integration.xml.router." +
|
||||
((multiChannel) ? "XPathMultiChannelRouter" : "XPathSingleChannelRouter");
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(classname);
|
||||
if (xPathExpressionChildPresent) {
|
||||
BeanDefinition beanDefinition = this.xpathParser.parse(
|
||||
(Element) xPathExpressionNodes.item(0), parserContext);
|
||||
@@ -79,19 +71,10 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
|
||||
else {
|
||||
builder.addConstructorArgReference(xPathExpressionRef);
|
||||
}
|
||||
|
||||
if(StringUtils.hasText(resolutionRequired)){
|
||||
builder.addPropertyValue("resolutionRequired", Boolean.parseBoolean(resolutionRequired));
|
||||
}
|
||||
|
||||
if(StringUtils.hasText(channelResolver)){
|
||||
builder.addPropertyReference("channelResolver", channelResolver);
|
||||
}
|
||||
|
||||
if(StringUtils.hasText(defaultOutputChannel)){
|
||||
builder.addPropertyReference("defaultOutputChannel", defaultOutputChannel);
|
||||
}
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-channel-name-resolution-failures");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel-resolver");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,20 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resolution-required" type="xsd:boolean" use="optional"/>
|
||||
<xsd:attribute name="resolution-required" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify whether this router should always be required to return at least one channel or name.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignore-channel-name-resolution-failures" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify whether a failure to resolve a channel name returned by this router should be ignored.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="default-output-channel" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
public class TestXmlApplicationContextHelper {
|
||||
@@ -34,11 +35,11 @@ public class TestXmlApplicationContextHelper {
|
||||
+ "'http://www.springframework.org/schema/beans "
|
||||
+ "http://www.springframework.org/schema/beans/spring-beans.xsd "
|
||||
+ "http://www.springframework.org/schema/integration "
|
||||
+ "http://www.springframework.org/schema/integration/spring-integration-1.0.xsd "
|
||||
+ "http://www.springframework.org/schema/integration/spring-integration.xsd "
|
||||
+ "http://www.springframework.org/schema/integration/xml "
|
||||
+ "http://www.springframework.org/schema/integration/xml/spring-integration-xml-1.0.xsd "
|
||||
+ "http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd "
|
||||
+ "http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd " +
|
||||
"http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd' >" +
|
||||
"http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd' >" +
|
||||
"<context:annotation-config/>";
|
||||
|
||||
private final static String footer = "</beans>";
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@ContextConfiguration
|
||||
public class XPathRouterParserTests {
|
||||
@@ -155,7 +156,32 @@ public class XPathRouterParserTests {
|
||||
assertEquals("Resolution required not set to true ", true, resolutionRequired);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreChannelNameResolutionFailuresFalse() throws Exception {
|
||||
StringBuffer contextBuffer = new StringBuffer(
|
||||
"<si-xml:xpath-router id='router' ignore-channel-name-resolution-failures='false' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
|
||||
EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
|
||||
Object handler = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(handler);
|
||||
Object ignoreChannelNameResolutionFailures = accessor.getPropertyValue("ignoreChannelNameResolutionFailures");
|
||||
assertEquals("ignoreChannelNameResolutionFailures not set to false", false, ignoreChannelNameResolutionFailures);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIgnoreChannelNameResolutionFailuresTrue() throws Exception {
|
||||
StringBuffer contextBuffer = new StringBuffer(
|
||||
"<si-xml:xpath-router id='router' ignore-channel-name-resolution-failures='true' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
|
||||
EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
|
||||
Object handler = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(handler);
|
||||
Object ignoreChannelNameResolutionFailures = accessor.getPropertyValue("ignoreChannelNameResolutionFailures");
|
||||
assertEquals("ignoreChannelNameResolutionFailures not set to true ", true, ignoreChannelNameResolutionFailures);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDefaultOutputChannel() throws Exception {
|
||||
StringBuffer contextBuffer = new StringBuffer("<si-xml:xpath-router id='router' default-output-channel='defaultOutput' input-channel='test-input'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
|
||||
|
||||
Reference in New Issue
Block a user