INT-1784 added support for the 'customizer' attribute in the namespace, for both <script> elements and the groovy <control-bus>
This commit is contained in:
@@ -27,6 +27,7 @@ import org.springframework.integration.groovy.GroovyCommandMessageProcessor;
|
||||
import org.springframework.integration.handler.ServiceActivatingHandler;
|
||||
import org.springframework.integration.scripting.ScriptVariableGenerator;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.scripting.groovy.GroovyObjectCustomizer;
|
||||
import org.springframework.util.CustomizableThreadCreator;
|
||||
|
||||
/**
|
||||
@@ -34,20 +35,31 @@ import org.springframework.util.CustomizableThreadCreator;
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public class GroovyControlBusFactoryBean extends AbstractSimpleMessageHandlerFactoryBean {
|
||||
|
||||
private volatile Long sendTimeout;
|
||||
|
||||
private volatile GroovyObjectCustomizer customizer;
|
||||
|
||||
|
||||
public void setSendTimeout(Long sendTimeout) {
|
||||
this.sendTimeout = sendTimeout;
|
||||
}
|
||||
|
||||
public void setCustomizer(GroovyObjectCustomizer customizer) {
|
||||
this.customizer = customizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MessageHandler createHandler() {
|
||||
ManagedBeansScriptVariableGenerator scriptVariableGenerator = new ManagedBeansScriptVariableGenerator(this.getBeanFactory());
|
||||
GroovyCommandMessageProcessor processor = new GroovyCommandMessageProcessor(scriptVariableGenerator);
|
||||
if (this.customizer != null) {
|
||||
processor.setCustomizer(this.customizer);
|
||||
}
|
||||
return this.configureHandler(new ServiceActivatingHandler(processor));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
@@ -29,6 +29,7 @@ public class GroovyControlBusParser extends AbstractConsumerEndpointParser {
|
||||
@Override
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GroovyControlBusFactoryBean.class);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "customizer");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "order");
|
||||
return builder;
|
||||
|
||||
@@ -68,7 +68,7 @@ public class GroovyScriptParser extends AbstractSingleBeanDefinitionParser {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(scriptVariableGeneratorName) && variableElements.size() > 0){
|
||||
if (StringUtils.hasText(scriptVariableGeneratorName) && variableElements.size() > 0) {
|
||||
parserContext.getReaderContext().error("'script-variable-generator' and 'variable' sub-elements are mutualy exclusive.", element);
|
||||
return;
|
||||
}
|
||||
@@ -106,6 +106,7 @@ public class GroovyScriptParser extends AbstractSingleBeanDefinitionParser {
|
||||
scriptVariableGeneratorBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
}
|
||||
builder.addConstructorArgReference(scriptVariableGeneratorName);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "customizer");
|
||||
}
|
||||
|
||||
private Object resolveScriptLocation(Element element, XmlReaderContext readerContext, String scriptLocation) {
|
||||
|
||||
@@ -20,27 +20,27 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Allows you to define custom Groovy variable bindings. The use of this sub-element is mutually
|
||||
exclusive with 'script-variable-generator' attribute
|
||||
exclusive with the 'script-variable-generator' attribute.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="name" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Name of the Groovy binding variable
|
||||
Name of the Groovy variable.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="value" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Value of the Groovy binding variable
|
||||
Value of the Groovy variable as a literal.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ref" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Value of the Groovy binding variable pointing to a bean reference
|
||||
Value of the Groovy variable as a bean reference.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:expected-type type="java.lang.Object"/>
|
||||
@@ -54,8 +54,7 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Resource location path for the Script. Either this or an inline script
|
||||
as body text should be
|
||||
provided, but not both.
|
||||
as body text should be provided, but not both.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -63,10 +62,20 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to the ScriptVariableGenerator bean. This attribute is mutually
|
||||
exclusive with 'variable' sub-element
|
||||
exclusive with any 'variable' sub-elements.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:expected-type type="rg.springframework.integration.groovy.ScriptVariableGenerator"/>
|
||||
<tool:expected-type type="org.springframework.integration.scripting.ScriptVariableGenerator"/>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="customizer" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a GroovyObjectCustomizer bean to be applied to this script.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:expected-type type="org.springframework.scripting.groovy.GroovyObjectCustomizer"/>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -74,8 +83,7 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Refresh delay for the script contents if specified as a resource
|
||||
location (defaults to never
|
||||
refresh).
|
||||
location (defaults to -1, never refresh).
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
@@ -95,6 +103,16 @@
|
||||
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:all>
|
||||
<xsd:attributeGroup ref="integration:inputOutputChannelGroup" />
|
||||
<xsd:attribute name="customizer" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Reference to a GroovyObjectCustomizer bean to be applied to each script payload.
|
||||
</xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:expected-type type="org.springframework.scripting.groovy.GroovyObjectCustomizer"/>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user