diff --git a/docs/src/reference/docbook/groovy.xml b/docs/src/reference/docbook/groovy.xml index a1124fbebd..b11bc2b6a4 100644 --- a/docs/src/reference/docbook/groovy.xml +++ b/docs/src/reference/docbook/groovy.xml @@ -116,6 +116,21 @@ not be used when using inline script, only when pointing to the script via location attribute. + + If you need control over customization of the Groovy object itself which goes beyond setting variables + (e.g., properties, MetaObject etc.) you can also register a GroovyObjectCustomizer which is an implementation of + org.springframework.scripting.groovy.GroovyObjectCustomizer via 'customizer' attribute. + + + + + +]]> + +Setting custom GroovyObjectCustomizer is NOT mutually exclusive to &ly;variable> sub-element and/or script-variable-generator + and is allowed with inline scripting. @@ -142,5 +157,19 @@ 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). + + + If you need control over customization of the Groovy object itself which goes beyond setting variables + (e.g., properties, MetaObject etc.) you can also register a GroovyObjectCustomizer which is an implementation of + org.springframework.scripting.groovy.GroovyObjectCustomizer via 'customizer' attribute. + + + + + +]]> + diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests-context.xml b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests-context.xml index 0127e39c43..c87645db84 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests-context.xml +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests-context.xml @@ -12,8 +12,13 @@ - + + + + diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java index 9b164bc7a9..075b31e74c 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyControlBusTests.java @@ -16,9 +16,14 @@ package org.springframework.integration.groovy.config; +import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import groovy.lang.GroovyObject; + +import java.util.concurrent.atomic.AtomicBoolean; + import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +34,7 @@ import org.springframework.integration.core.PollableChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; +import org.springframework.scripting.groovy.GroovyObjectCustomizer; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -45,13 +51,18 @@ public class GroovyControlBusTests { @Autowired private PollableChannel output; + + @Autowired + private MyGroovyCustomizer groovyCustomizer; @Test public void testOperationOfControlBus() { // long is > 3 + this.groovyCustomizer.executed = false; Message message = MessageBuilder.withPayload("def result = service.convert('aardvark'); def foo = headers.foo; result+foo").setHeader("foo", "bar").build(); this.input.send(message); assertEquals("catbar", output.receive(0).getPayload()); assertNull(output.receive(0)); + assertTrue(this.groovyCustomizer.executed); } @ManagedResource @@ -62,5 +73,14 @@ public class GroovyControlBusTests { return "cat"; } } + + public static class MyGroovyCustomizer implements GroovyObjectCustomizer{ + private volatile boolean executed; + + public void customize(GroovyObject goo) { + this.executed = true; + } + + } }