INT-2567: Improvement & refactor Groovy component

Introduce VariableResolver, BeanFilter, FilteredBeanFactoryDecorator, GroovyVariableResolverBinding, refactoring ManagedBeansScriptVariableGenerator for usage GroovyVariableResolverBinding.
GroovyVariableResolverBindingTests.
additional tests for GroovyControlBus.
add 'spring-web' dependency for tests about 'request' custom scope.
Manual: change description about 'Groovy Control Bus' scripts limitation'.

INT-2567: Improve & refacror Groovy Control Bus

Introduce separate BindingOverwriteGroovyObjectCustomizerDecorator
Internal GroovyControlBusFactoryBean$ManagedBeansBinding with delegation to provided BeanFactory
Inline ScriptVariableGenerator implementation just for Message 'headers' variable
Tests for new GroovyScriptPayloadMessageProcessor logic about binding
Integration tests for managed beans in the custom scope
Reference Manual: polishing description about Control Bus' behavior

INT-2567 polishing added @link to javadocs
This commit is contained in:
Artem Bilan
2011-11-13 16:31:50 +02:00
committed by Oleg Zhurakousky
parent 5750c69142
commit 74b4638eb9
11 changed files with 355 additions and 90 deletions

View File

@@ -17,14 +17,14 @@
<section id="groovy-config">
<title>Groovy configuration</title>
<para>
<para>
With Spring Integration 2.1, Groovy Support's configuration namespace
is an extension of Spring Integration's Scripting Support and shares the core configuration
and behavior described in detail in the
is an extension of Spring Integration's Scripting Support and shares the core configuration
and behavior described in detail in the
<xref linkend="scripting">Scripting Support</xref> section. Even though Groovy scripts are
well supported by generic Scripting Support, Groovy Support provides the
<emphasis>Groovy</emphasis> configuration namespace which is backed by the Spring Framework's
<classname>org.springframework.scripting.groovy.GroovyScriptFactory</classname> and related components,
well supported by generic Scripting Support, Groovy Support provides the
<emphasis>Groovy</emphasis> configuration namespace which is backed by the Spring Framework's
<classname>org.springframework.scripting.groovy.GroovyScriptFactory</classname> and related components,
offering extended capabilities for using Groovy. Below are a couple of sample configurations:</para>
<para><emphasis>Filter</emphasis> <programlisting language="xml">&lt;int:filter input-channel="referencedScriptInput"&gt;
&lt;int-groovy:script location="some/path/to/groovy/file/GroovyFilterTests.groovy"/&gt;
@@ -35,20 +35,20 @@
return payload == 'good'
]]&gt;&lt;/int-groovy:script&gt;
&lt;/int:filter&gt;</programlisting>
As the above examples show, the configuration looks identical to the general Scripting Support configuration. The only
difference is the use of the Groovy namespace as indicated in the examples by the <emphasis>int-groovy</emphasis> namespace prefix.
Also note that the <code>lang</code> attribute on the <code>&lt;script&gt;</code> tag is not valid in this namespace.
As the above examples show, the configuration looks identical to the general Scripting Support configuration. The only
difference is the use of the Groovy namespace as indicated in the examples by the <emphasis>int-groovy</emphasis> namespace prefix.
Also note that the <code>lang</code> attribute on the <code>&lt;script&gt;</code> tag is not valid in this namespace.
</para>
<para><emphasis>Groovy object customization</emphasis> </para>
<para>
If you need to customize the Groovy object itself, beyond setting variables, you can reference
a bean that implements <classname>org.springframework.scripting.groovy.GroovyObjectCustomizer</classname> via the
<code>customizer</code> attribute. For example, this might be useful if you want to implement a domain-specific
language (DSL) by modifying the MetaClass and registering functions to be available within the script:
<programlisting language="xml"><![CDATA[<int:service-activator input-channel="groovyChannel">
<int-groovy:script location="foo/SomeScript.groovy" customizer="groovyCustomizer"/>
</int:service-activator>
@@ -78,28 +78,28 @@
<para>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 <classname>GroovyObjectCustomizer</classname>, and then executes it. The
Control Bus' customizer exposes all the beans in the application context
Control Bus' <classname>MessageProcessor</classname> exposes all beans in the application context
that are annotated with <code>@ManagedResource</code>, implement Spring's
<classname>Lifecycle</classname> interface or extend Spring's <classname>CustomizableThreadCreator</classname> base class
(e.g. several of the <classname>TaskExecutor</classname> and <classname>TaskScheduler</classname> implementations).</para>
<para>
<important>
Be careful about using managed beans with custom scopes (e.g. 'request') in the Control Bus' command scripts, especially
inside an <emphasis>async</emphasis> message flow. If <emphasis>The Control Bus' customizer</emphasis> can't expose a bean
from the application context, it skips that bean. For example, if a custom scope's context is not established, the attempt
to get a bean within that scope will trigger a <classname>BeanCreationException</classname>. In that case, such a bean
will be ignored, and the customizer will continue with other beans.
inside an <emphasis>async</emphasis> message flow. If The Control Bus' <classname>MessageProcessor</classname>
can't expose a bean from the application context, you may end up with some <classname>BeansException</classname>
during <emphasis>command script's</emphasis> executing. For example, if a custom scope's context is not established,
the attempt to get a bean within that scope will trigger a <classname>BeanCreationException</classname>.
</important>
</para>
<para>
If you need to further customize the Groovy objects, you can also provide a reference to a bean
that implements <classname>org.springframework.scripting.groovy.GroovyObjectCustomizer</classname> via
the <code>customizer</code> attribute.
<programlisting language="xml"><![CDATA[<int-groovy:control-bus input-channel="input"
output-channel="output"
customizer="groovyCustomizer"/>
<beans:bean id="groovyCustomizer" class="org.foo.MyGroovyObjectCustomizer"/>]]></programlisting>
</para>
</section>