resolves INT-577 by adding namespace support for setting of default output channel

This commit is contained in:
Jonas Partner
2009-02-19 10:08:55 +00:00
parent de0a85b31a
commit 59ed94a3da
3 changed files with 35 additions and 1 deletions

View File

@@ -54,6 +54,7 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
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");
@@ -87,6 +88,9 @@ public class XPathRouterParser extends AbstractConsumerEndpointParser {
builder.addPropertyReference("channelResolver", channelResolver);
}
if(StringUtils.hasText(defaultOutputChannel)){
builder.addPropertyReference("defaultOutputChannel", defaultOutputChannel);
}
return builder;
}

View File

@@ -189,6 +189,16 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="resolution-required" type="xsd:boolean" use="optional"/>
<xsd:attribute name="default-output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@@ -29,6 +29,7 @@ import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.test.context.ContextConfiguration;
import org.w3c.dom.Document;
@@ -39,7 +40,8 @@ import org.w3c.dom.Document;
@ContextConfiguration
public class XPathRouterParserTests {
String channelConfig = "<si:channel id='test-input'/> <si:channel id='outputOne'><si:queue capacity='10'/></si:channel>";
String channelConfig = "<si:channel id='test-input'/> <si:channel id='outputOne'><si:queue capacity='10'/></si:channel>" +
"<si:channel id='defaultOutput'><si:queue capacity='10'/></si:channel>";
@Autowired @Qualifier("test-input")
MessageChannel inputChannel;
@@ -47,6 +49,10 @@ public class XPathRouterParserTests {
@Autowired @Qualifier("outputOne")
QueueChannel outputChannel;
@Autowired @Qualifier("defaultOutput")
QueueChannel defaultOutput;
ConfigurableApplicationContext appContext;
public EventDrivenConsumer buildContext(String routerDef){
@@ -154,4 +160,18 @@ public class XPathRouterParserTests {
assertEquals("Resolution required not set to true ", true, resolutionRequired);
}
@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>");
EventDrivenConsumer consumer = buildContext(contextBuffer.toString());
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
Object handler = accessor.getPropertyValue("handler");
accessor = new DirectFieldAccessor(handler);
Object defaultOutputChannelValue = accessor.getPropertyValue("defaultOutputChannel");
assertEquals("Default output channel not correctly set ", defaultOutput, defaultOutputChannelValue);
inputChannel.send(MessageBuilder.withPayload("<unrelated/>").build());
assertEquals("Wrong count of messages on default output channel",1, defaultOutput.getMesssageCount());
}
}