Added 'default-output-channel' attribute to the <router/> element (INT-367).

This commit is contained in:
Mark Fisher
2008-09-11 17:04:11 +00:00
parent 78d349df75
commit 82574606e1
5 changed files with 50 additions and 1 deletions

View File

@@ -106,6 +106,7 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio
ManagedList interceptors = parser.parseInterceptors(interceptorsElement, parserContext);
builder.addPropertyValue("interceptors", interceptors);
}
this.postProcess(element, parserContext, builder);
}
private String parseAdapter(String ref, String method, Element element, ParserContext parserContext) {
@@ -118,6 +119,12 @@ public abstract class AbstractEndpointParser extends AbstractSingleBeanDefinitio
return adapterBeanName;
}
/**
* Subclasses may implement this method to provide additional configuration.
*/
protected void postProcess(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
}
protected abstract Class<? extends MessageEndpoint> getEndpointClass();
protected abstract Class<?> getMethodInvokingAdapterClass();

View File

@@ -16,6 +16,10 @@
package org.springframework.integration.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.endpoint.MessageEndpoint;
import org.springframework.integration.router.MethodInvokingChannelResolver;
import org.springframework.integration.router.RouterEndpoint;
@@ -37,4 +41,9 @@ public class RouterParser extends AbstractEndpointParser {
return MethodInvokingChannelResolver.class;
}
@Override
protected void postProcess(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
}
}

View File

@@ -333,12 +333,19 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="router" type="inputEndpointType">
<xsd:element name="router">
<xsd:annotation>
<xsd:documentation>
Defines a Router.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="inputEndpointType">
<xsd:attribute name="default-output-channel" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="splitter" type="inputOutputEndpointType">

View File

@@ -50,4 +50,20 @@ public class RouterParserTests {
assertNull(output1.receive(0));
}
@Test
public void testRouterWithDefaultOutputChannel() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"routerParserTests.xml", this.getClass());
context.start();
MessageChannel input = (MessageChannel) context.getBean("inputForRouterWithDefaultOutput");
PollableChannel output1 = (PollableChannel) context.getBean("output1");
PollableChannel output2 = (PollableChannel) context.getBean("output2");
PollableChannel defaultOutput = (PollableChannel) context.getBean("defaultOutput");
input.send(new StringMessage("99"));
assertNull(output1.receive(0));
assertNull(output2.receive(0));
Message<?> result = defaultOutput.receive(0);
assertEquals("99", result.getPayload());
}
}

View File

@@ -11,6 +11,8 @@
<channel id="input"/>
<channel id="inputForRouterWithDefaultOutput"/>
<channel id="output1">
<queue capacity="1"/>
</channel>
@@ -19,8 +21,16 @@
<queue capacity="1"/>
</channel>
<channel id="defaultOutput">
<queue capacity="2"/>
</channel>
<router id="router" ref="pojo" method="route" input-channel="input"/>
<router id="routerWithDefaultOutputChannel" ref="pojo" method="route"
input-channel="inputForRouterWithDefaultOutput"
default-output-channel="defaultOutput"/>
<beans:bean id="pojo" class="org.springframework.integration.router.config.TestRouter"/>
</beans:beans>