INT-910 adding base support for 'script' elements in the core (XSD, Parser, and FactoryBeans)
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -124,7 +125,12 @@ abstract class AbstractMessageHandlerFactoryBean implements FactoryBean<MessageH
|
||||
if (this.targetObject != null) {
|
||||
Assert.state(this.expression == null,
|
||||
"The 'targetObject' and 'expression' properties are mutually exclusive.");
|
||||
this.handler = this.createMethodInvokingHandler(this.targetObject, this.targetMethodName);
|
||||
if (this.targetObject instanceof MessageProcessor) {
|
||||
this.handler = this.createMessageProcessingHandler((MessageProcessor) this.targetObject);
|
||||
}
|
||||
else {
|
||||
this.handler = this.createMethodInvokingHandler(this.targetObject, this.targetMethodName);
|
||||
}
|
||||
}
|
||||
else if (this.expression != null) {
|
||||
this.handler = this.createExpressionEvaluatingHandler(this.expression);
|
||||
@@ -156,6 +162,10 @@ abstract class AbstractMessageHandlerFactoryBean implements FactoryBean<MessageH
|
||||
throw new UnsupportedOperationException(this.getClass().getName() + " does not support expressions.");
|
||||
}
|
||||
|
||||
MessageHandler createMessageProcessingHandler(MessageProcessor processor) {
|
||||
return this.createMethodInvokingHandler(processor, "processMessage");
|
||||
}
|
||||
|
||||
MessageHandler createDefaultHandler() {
|
||||
throw new IllegalArgumentException(
|
||||
"Exactly one of the 'targetObject' or 'expression' property is required.");
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.handler.ServiceActivatingHandler;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -50,6 +51,11 @@ public class ServiceActivatorFactoryBean extends AbstractMessageHandlerFactoryBe
|
||||
return this.configureHandler(new ServiceActivatingHandler(processor));
|
||||
}
|
||||
|
||||
@Override
|
||||
MessageHandler createMessageProcessingHandler(MessageProcessor processor) {
|
||||
return this.configureHandler(new ServiceActivatingHandler(processor));
|
||||
}
|
||||
|
||||
private ServiceActivatingHandler configureHandler(ServiceActivatingHandler handler) {
|
||||
if (this.sendTimeout != null) {
|
||||
handler.setSendTimeout(sendTimeout);
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,7 @@ abstract class AbstractDelegatingConsumerEndpointParser extends AbstractConsumer
|
||||
String expression = element.getAttribute(EXPRESSION_ATTRIBUTE);
|
||||
boolean hasRef = StringUtils.hasText(ref);
|
||||
boolean hasExpression = StringUtils.hasText(expression);
|
||||
Element scriptElement = DomUtils.getChildElementByTagName(element, "script");
|
||||
if (innerDefinition != null) {
|
||||
if (hasRef || hasExpression) {
|
||||
parserContext.getReaderContext().error(
|
||||
@@ -55,6 +59,10 @@ abstract class AbstractDelegatingConsumerEndpointParser extends AbstractConsumer
|
||||
else if (hasExpression) {
|
||||
builder.addPropertyValue("expression", expression);
|
||||
}
|
||||
else if (scriptElement != null) {
|
||||
BeanDefinition scriptBeanDefinition = parserContext.getDelegate().parseCustomElement(scriptElement, builder.getBeanDefinition());
|
||||
builder.addPropertyValue("targetObject", scriptBeanDefinition);
|
||||
}
|
||||
else if (!this.hasDefaultOption()) {
|
||||
parserContext.getReaderContext().error("Exactly one of the 'ref' attribute, 'expression' attribute, " +
|
||||
"or inner bean (<bean/>) definition is required for element " +
|
||||
|
||||
@@ -2229,10 +2229,13 @@
|
||||
<xsd:complexType name="innerEndpointDefinitionAware">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="handlerEndpointType">
|
||||
<xsd:all>
|
||||
<xsd:element ref="beans:bean" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:choice minOccurs="0" maxOccurs="2">
|
||||
<xsd:element name="poller" type="innerPollerType" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:all>
|
||||
<xsd:choice minOccurs="0" maxOccurs="1">
|
||||
<xsd:element ref="beans:bean" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:any namespace="##other" processContents="strict" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:choice>
|
||||
</xsd:choice>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
Reference in New Issue
Block a user