The <router/> element now creates its own endpoint (i.e. it is no longer necessary to create a <handler-endpoint/> as well) (INT-284).

This commit is contained in:
Mark Fisher
2008-07-06 18:08:31 +00:00
parent a83e39b6ce
commit b7f31fcbf0
10 changed files with 69 additions and 70 deletions

View File

@@ -200,17 +200,32 @@
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="handlerEndpointType">
<xsd:extension base="inputOutputHandlerEndpointType">
<xsd:attribute name="reply-handler" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="handlerEndpointType">
<xsd:complexType name="inputOutputHandlerEndpointType">
<xsd:annotation>
<xsd:documentation>
Base type for handler endpoint elements.
Base type for handler endpoint elements that accept Messages from an input-channel
and also produce Messages to be sent to an output-channel.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="inputHandlerEndpointType">
<xsd:attribute name="output-channel" type="xsd:string"/>
<xsd:attribute name="return-address-overrides" type="xsd:boolean" default="false"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="inputHandlerEndpointType">
<xsd:annotation>
<xsd:documentation>
Base type for handler endpoint elements that accept Messages from an input-channel.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
@@ -222,9 +237,7 @@
<xsd:attribute name="ref" type="xsd:string" use="required"/>
<xsd:attribute name="method" type="xsd:string"/>
<xsd:attribute name="input-channel" type="xsd:string" use="required"/>
<xsd:attribute name="output-channel" type="xsd:string"/>
<xsd:attribute name="selector" type="xsd:string"/>
<xsd:attribute name="return-address-overrides" type="xsd:boolean" default="false"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -318,20 +331,15 @@
<xsd:attribute name="keep-alive" type="xsd:int"/>
</xsd:complexType>
<xsd:element name="router">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
<xsd:element name="router" type="inputHandlerEndpointType">
<xsd:annotation>
<xsd:documentation>
Defines a Router.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:ID"/>
<xsd:attribute name="ref" type="xsd:string" use="required"/>
<xsd:attribute name="method" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="splitter" type="handlerEndpointType">
<xsd:element name="splitter" type="inputOutputHandlerEndpointType">
<xsd:annotation>
<xsd:documentation>
Defines a Splitter.

View File

@@ -24,6 +24,7 @@ import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.Lifecycle;
import org.springframework.integration.ConfigurationException;
@@ -231,7 +232,16 @@ public abstract class AbstractEndpoint implements MessageEndpoint, BeanNameAware
throw new MessageHandlerNotRunningException(message);
}
if (message.getPayload() instanceof EndpointVisitor) {
((EndpointVisitor) message.getPayload()).visitEndpoint(this);
MessageEndpoint endpoint = null;
try {
endpoint = (MessageEndpoint) AopContext.currentProxy();
}
catch (IllegalStateException e) {
if (logger.isDebugEnabled()) {
logger.debug("The currenty proxy is not exposed.");
}
}
((EndpointVisitor) message.getPayload()).visitEndpoint((endpoint != null) ? endpoint : this);
return true;
}
if (!this.supports(message)) {

View File

@@ -54,6 +54,9 @@ public class RouterMessageHandlerAdapter extends AbstractMessageHandlerAdapter i
this.setMethodName(methodName);
}
public RouterMessageHandlerAdapter() {
}
public void setChannelRegistry(ChannelRegistry channelRegistry) {
this.channelRegistry = channelRegistry;

View File

@@ -16,36 +16,20 @@
package org.springframework.integration.router.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.config.AbstractHandlerEndpointParser;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.router.RouterMessageHandlerAdapter;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;router/&gt; element.
*
* @author Mark Fisher
*/
public class RouterParser extends AbstractSingleBeanDefinitionParser {
public class RouterParser extends AbstractHandlerEndpointParser {
@Override
protected Class<?> getBeanClass(Element element) {
protected Class<? extends MessageHandler> getHandlerAdapterClass() {
return RouterMessageHandlerAdapter.class;
}
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
String ref = element.getAttribute("ref");
String methodName = element.getAttribute("method");
if (!StringUtils.hasText(ref) || !StringUtils.hasText(methodName)) {
throw new ConfigurationException(
"The 'ref' and 'method' attributes are both required.");
}
builder.addConstructorArgReference(ref);
builder.addConstructorArgValue(methodName);
}
}

View File

@@ -15,9 +15,7 @@
<channel id="output2"/>
<handler-endpoint ref="router" input-channel="input"/>
<router id="router" ref="pojo" method="route"/>
<router id="router" ref="pojo" method="route" input-channel="input"/>
<beans:bean id="pojo" class="org.springframework.integration.router.config.TestRouter"/>