Removed support for <handler/> sub-element for <endpoint/> since the 'handler-ref' attribute is sufficient.
This commit is contained in:
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -34,7 +31,6 @@ import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
|
||||
import org.springframework.integration.handler.MessageHandlerChain;
|
||||
import org.springframework.integration.scheduling.PollingSchedule;
|
||||
import org.springframework.integration.scheduling.Schedule;
|
||||
import org.springframework.integration.scheduling.Subscription;
|
||||
@@ -61,14 +57,8 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
|
||||
private static final String SELECTORS_PROPERTY = "messageSelectors";
|
||||
|
||||
private static final String HANDLER_ELEMENT = "handler";
|
||||
|
||||
private static final String REF_ATTRIBUTE = "ref";
|
||||
|
||||
private static final String METHOD_ATTRIBUTE = "method";
|
||||
|
||||
private static final String HANDLERS_PROPERTY = "handlers";
|
||||
|
||||
private static final String HANDLER_REF_ATTRIBUTE = "handler-ref";
|
||||
|
||||
private static final String HANDLER_METHOD_ATTRIBUTE = "handler-method";
|
||||
@@ -95,6 +85,10 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
|
||||
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
String handlerRef = element.getAttribute(HANDLER_REF_ATTRIBUTE);
|
||||
if (!StringUtils.hasText(handlerRef)) {
|
||||
throw new ConfigurationException("The 'handler-ref' attribute is required.");
|
||||
}
|
||||
RootBeanDefinition endpointDef = new RootBeanDefinition(HandlerEndpoint.class);
|
||||
endpointDef.setSource(parserContext.extractSource(element));
|
||||
String inputChannel = element.getAttribute(INPUT_CHANNEL_ATTRIBUTE);
|
||||
@@ -104,7 +98,6 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
endpointDef.getPropertyValues().addPropertyValue(DEFAULT_OUTPUT_CHANNEL_PROPERTY, defaultOutputChannel);
|
||||
}
|
||||
ManagedList selectors = new ManagedList();
|
||||
List<String> childHandlerRefs = new ArrayList<String>();
|
||||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node child = childNodes.item(i);
|
||||
@@ -117,16 +110,6 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
String ref = ((Element) child).getAttribute(REF_ATTRIBUTE);
|
||||
selectors.add(new RuntimeBeanReference(ref));
|
||||
}
|
||||
else if (HANDLER_ELEMENT.equals(localName)) {
|
||||
String ref = ((Element) child).getAttribute(REF_ATTRIBUTE);
|
||||
String method = ((Element) child).getAttribute(METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(method)) {
|
||||
childHandlerRefs.add(this.parseHandlerAdapter(ref, method, parserContext));
|
||||
}
|
||||
else {
|
||||
childHandlerRefs.add(ref);
|
||||
}
|
||||
}
|
||||
else if (SCHEDULE_ELEMENT.equals(localName)) {
|
||||
schedule = this.parseSchedule((Element) child);
|
||||
}
|
||||
@@ -145,36 +128,13 @@ public class EndpointParser implements BeanDefinitionParser {
|
||||
if (selectors.size() > 0) {
|
||||
endpointDef.getPropertyValues().addPropertyValue(SELECTORS_PROPERTY, selectors);
|
||||
}
|
||||
if (childHandlerRefs.size() > 0) {
|
||||
if (childHandlerRefs.size() == 1) {
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(childHandlerRefs.get(0)));
|
||||
}
|
||||
else {
|
||||
RootBeanDefinition handlerChainDef = new RootBeanDefinition(MessageHandlerChain.class);
|
||||
List handlerList = new ManagedList();
|
||||
for (String ref : childHandlerRefs) {
|
||||
handlerList.add(new RuntimeBeanReference(ref));
|
||||
}
|
||||
handlerChainDef.getPropertyValues().addPropertyValue(HANDLERS_PROPERTY, handlerList);
|
||||
String chainBeanName = parserContext.getReaderContext().generateBeanName(handlerChainDef);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerChainDef, chainBeanName));
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(chainBeanName));
|
||||
}
|
||||
String handlerMethod = element.getAttribute(HANDLER_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(handlerMethod)) {
|
||||
String adapterBeanName = this.parseHandlerAdapter(handlerRef, handlerMethod, parserContext);
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(adapterBeanName));
|
||||
}
|
||||
String handlerRef = element.getAttribute(HANDLER_REF_ATTRIBUTE);
|
||||
if (StringUtils.hasText(handlerRef)) {
|
||||
if (childHandlerRefs.size() > 0) {
|
||||
throw new ConfigurationException(
|
||||
"The 'handler-ref' attribute is only supported when no 'handler' child elements are present");
|
||||
}
|
||||
String handlerMethod = element.getAttribute(HANDLER_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(handlerMethod)) {
|
||||
String adapterBeanName = this.parseHandlerAdapter(handlerRef, handlerMethod, parserContext);
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(adapterBeanName));
|
||||
}
|
||||
else {
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(handlerRef));
|
||||
}
|
||||
else {
|
||||
endpointDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(handlerRef));
|
||||
}
|
||||
String errorHandlerRef = element.getAttribute(ERROR_HANDLER_ATTRIBUTE);
|
||||
if (StringUtils.hasText(errorHandlerRef)) {
|
||||
|
||||
@@ -136,11 +136,10 @@
|
||||
<xsd:element ref="schedule" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="concurrency" type="concurrencyType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="selector" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xsd:element ref="handler" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="input-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="default-output-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="handler-ref" type="xsd:string"/>
|
||||
<xsd:attribute name="handler-ref" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="handler-method" type="xsd:string"/>
|
||||
<xsd:attribute name="error-handler" type="xsd:string"/>
|
||||
<xsd:attribute name="reply-handler" type="xsd:string"/>
|
||||
|
||||
@@ -55,19 +55,6 @@ public class EndpointParserTests {
|
||||
assertEquals("test", handler.getMessageString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndpointWithChildHandler() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithHandlerChildElement.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
TestHandler handler = (TestHandler) context.getBean("testHandler");
|
||||
assertNull(handler.getMessageString());
|
||||
channel.send(new GenericMessage<String>(1, "test"));
|
||||
handler.getLatch().await(50, TimeUnit.MILLISECONDS);
|
||||
assertEquals("test", handler.getMessageString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlerAdapterEndpoint() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?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-core-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel" capacity="50"/>
|
||||
|
||||
<endpoint input-channel="testChannel">
|
||||
<schedule period="100"/>
|
||||
<handler ref="testHandler"/>
|
||||
</endpoint>
|
||||
|
||||
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
|
||||
<beans:constructor-arg value="1"/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
@@ -11,10 +11,9 @@
|
||||
|
||||
<channel id="testChannel" capacity="50"/>
|
||||
|
||||
<endpoint id="endpoint" input-channel="testChannel">
|
||||
<endpoint id="endpoint" input-channel="testChannel" handler-ref="testHandler">
|
||||
<schedule period="100"/>
|
||||
<selector ref="typeSelector"/>
|
||||
<handler ref="testHandler"/>
|
||||
</endpoint>
|
||||
|
||||
<beans:bean id="typeSelector" class="org.springframework.integration.message.selector.PayloadTypeSelector">
|
||||
|
||||
Reference in New Issue
Block a user