Groovy supportWith Spring Integration 2.0 we've added Groovy support allowing you to
- use Groovy scripting language to provide integration and business logic for
- various integration components similar to the way Spring Expression Language
- (SpEL) is use to implement routing, transformation and other integration
- concerns. For more information about Groovy please refer to Groovy
+ use the Groovy scripting language to provide the logic for
+ various integration components similar to the way the Spring Expression Language
+ (SpEL) is supported for routing, transformation and other integration
+ concerns. For more information about Groovy please refer to the Groovy
documentation which you can find
on the project website
@@ -20,13 +20,14 @@
Depending on the complexity of your integration requirements Groovy
scripts could be provided inline as CDATA in XML configuration or as a
- reference to a file containing Groovy script. To enable Groovy support
- Spring Integration defines
+ reference to a file containing the Groovy script. To enable Groovy support
+ Spring Integration defines a
GroovyScriptExecutingMessageProcessor which will
- create a groovy Binding object identifying Message Payload as
- payload variable and Message Headers as headers
- variable. All that is left for you to do is write script that uses these
- variables. Below are couple of sample configurations:
+ bind the Message Payload as a
+ payload variable and the Message Headers as a headers
+ variable within the script execution context. All that is left for you to do is
+ write a script that uses those
+ variables. Below are a couple of sample configurations:
Filter<filter input-channel="referencedScriptInput">
<groovy:script location="some/path/to/groovy/file/GroovyFilterTests.groovy"/>
@@ -36,30 +37,43 @@
<groovy:script><![CDATA[
return payload == 'good'
]]></groovy:script>
-</filter> You see that script could be included inline
- or via location attribute using the groovy namespace
- sport.
+</filter>
+
+ Here, you see that the script can be included inline
+ or via the location attribute using the groovy namespace
+ support.
Other supported elements are router, service-activator,
- transformer, splitter
+ transformer, and splitter. The configuration would look identical to that
+ above other than the main element's name.
+
+ Another interesting aspect of using Groovy support is the framework's
+ ability to update (reload) scripts without restarting the Application
+ Context. To accomplish this, all you need to do is specify
+ the refresh-check-delay attribute on the script
+ element.
+
+ <groovy:script location="..." refresh-check-delay="5000"/>
+
+ In the above example any invocations that occur within the 5 seconds immediately following the
+ updating of the script would still be using the old script. However, any invocation that occurs
+ after those 5 seconds have elapsed will
+ result in execution of the new script. This is a good example where 'near real
+ time' is acceptable.
+
+ <groovy:script location="..." refresh-check-delay="0"/>
+
+ In the above example the context will be updated with any script modifications
+ as soon as such modification occurs. Basically this is an example of
+ 'real-time' configuration and might not be the most efficient option (but could be useful during development).
+
+ <groovy:script location="..." refresh-check-delay="-1"/>
- Another interesting aspect of using Groovy support is framework's
- ability to update (reload) scripts without restarting the Application
- Context. To accomplish this all you need is specify
- refresh-check-delay attribute on script
- element. The reason for this attribute is to make reloading of the script
- more efficient. <groovy:script location="..." refresh-check-delay="5000"/>
- In the above example for the next 5 seconds after you update the script
- you'll still be using the old script and after 5 seconds the context will
- be updated with the new script. This is a good example where 'near real
- time' is acceptable. <groovy:script location="..." refresh-check-delay="0"/>
- In the above example the context will be updated with the new script every
- time the script is modified. Basically this is the example of the
- 'real-time' and might not be the most efficient way. <groovy:script location="..." refresh-check-delay="-1"/>
Any negative number value means the script will never be refreshed after
- initial initialization of application context. DEFAULT BEHAVIOR
- Inline defined script can not be reloaded.
+ initial initialization of the application context. This is the default behavior.
+ In this case, the "dynamic" aspect of Groovy is not being used, but the syntax
+ might be the primary reason that Groovy has been chosen in the first place.
+ Inline defined scripts can not be reloaded.
@@ -80,7 +94,9 @@
The groovy control bus executes messages on the input channel as
Groovy scripts. It takes a message, compiles the body to a Script,
customizes it with a GroovyObjectCustomizer, and then executes it. The
- default customizer just exposes all the beans in the application context
- as script context objects.
+ Control Bus' customizer exposes all the beans in the application context
+ that are annotated with @ManagedResource, implement Spring's
+ Lifecycle interface or extend Spring's CustomizableThreadCreator base class
+ (e.g. several of the TaskExecutor and TaskScheduler implementations).
diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/BeanFactoryContextBindingCustomizer.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/BeanFactoryContextBindingCustomizer.java
deleted file mode 100644
index 3486fe963c..0000000000
--- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/BeanFactoryContextBindingCustomizer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2002-2010 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-
-package org.springframework.integration.groovy;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyObject;
-import groovy.lang.Script;
-
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import org.springframework.beans.factory.ListableBeanFactory;
-import org.springframework.scripting.groovy.GroovyObjectCustomizer;
-
-/**
- * @author Dave Syer
- * @since 2.0
- */
-public class BeanFactoryContextBindingCustomizer implements GroovyObjectCustomizer, BeanFactoryAware {
-
- private ListableBeanFactory beanFactory;
-
-
- public BeanFactoryContextBindingCustomizer() {
- this(null);
- }
-
- public BeanFactoryContextBindingCustomizer(BeanFactory beanFactory) {
- setBeanFactory(beanFactory);
- }
-
-
- public void setBeanFactory(BeanFactory beanFactory) {
- this.beanFactory = (beanFactory instanceof ListableBeanFactory) ? (ListableBeanFactory) beanFactory : null;
- }
-
- public void customize(GroovyObject goo) {
- if (this.beanFactory != null) {
- Binding binding = ((Script) goo).getBinding();
- for (String name : this.beanFactory.getBeanDefinitionNames()) {
- binding.setVariable(name, this.beanFactory.getBean(name));
- }
- }
- }
-
-}
diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessor.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessor.java
deleted file mode 100644
index 8c3830897a..0000000000
--- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptPayloadMessageProcessor.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2002-2010 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-
-package org.springframework.integration.groovy;
-
-import groovy.lang.GString;
-
-import java.util.Map;
-
-import org.springframework.integration.Message;
-import org.springframework.integration.handler.AbstractScriptExecutingMessageProcessor;
-import org.springframework.scripting.ScriptSource;
-import org.springframework.scripting.groovy.GroovyObjectCustomizer;
-import org.springframework.scripting.groovy.GroovyScriptFactory;
-import org.springframework.scripting.support.StaticScriptSource;
-import org.springframework.util.Assert;
-
-/**
- * @author Dave Syer
- * @author Mark Fisher
- * @since 2.0
- */
-public class GroovyScriptPayloadMessageProcessor extends AbstractScriptExecutingMessageProcessor