This is a significant update to the build system, including the changes listed below. README.md has been updated with instructions on the most important day-to-day commands. - Eliminate buildSrc submodule In favor of using the new bundlor and docbook-reference plugins. The net effect is a large reduction in number of lines of build code. Common docbook resources, stylesheets, etc are stored directly in the docbook plugin. This means that --recursive is no longer required when cloning and there will never be a need to use `git submodule` commands. README files have been updated to reflect. Use of the new bundlor plugin also means the removal of template.mf files from the source tree in favor of an inline approach. See build.gradle for details. Bundlor 'import templates' are built up programmatically and kept physically close to gradle dependency declarations, leading to more convenience when changing these values and hopefully fewer errors / version inconsistencies over time. Certain tests depended on the presence of template.mf files, all of which have recently been removed from the source tree in favor of the new bundlor plugin which allows for inlining bundlor configuration within the Gradle build script. These tests now create temp files using the java.io.File API instead. - Upgrade to Gradle 1.0-milestone-6 The m6 release is significantly faster when resolving dependencies and has a number of valuable new features over the earlier m3 version. Review the release notes for Gradle 1.0-milestone-6 online for full details. - Switch to repo.springsource.org repository Previously the project build declared as many repositories as necessary to resolve all project dependencies. Now depending on a single 'virtual repository' defined within the SpringSource Artifactory instance at http://repo.springsource.org. Currently, the virtual repository in use is 'libs-milestone', which allows for the resolution of all "milestone-or-better" versions of all S2 and third-party dependencies. Should snapshot dependencies become required, this value may be changed from 'libs-milestone' to 'libs-snapshot'. To build only against GA releases, change the value to 'libs-release'. - New build plan(s) Spring Integration build plans have been updated to use the Artifactory Bamboo plugin and publish to repo.springsource.org. Build plans have names like 2.1.x to reflect the version under development, not necessarily the name of the branch, as this may change over time and across major releases. - Improve release process As mentioned above, Spring Integration will now use the Artifactory Bamboo plugin to publish releases and also use Artifactory's support for pushing builds directly into Maven Central via oss.sonatype.org. Generate poms that contain all necessary fields for onboarding at Maven central (scm, developers, organization, licenses, etc). Generate -source and -javadoc poms to comply with Maven Central onboarding rules (and for general good practice anyway). Generation of PGP signatures, sha1 and md5 checksums are all handled automatically by Artifactory. These are also requirements for automated entry into Maven Central. - Remove source-level pom generation Automatic generation of Maven poms suitable for use in building Spring Integration is no longer supported. Generation and publication of poms for the purpose of dependency management remains supported. Sonar support has to date depended on these poms, but will be switched over to use the Gradle Sonar plugin shortly. - Eliminate docs subproject Move docs/src to the root of the project and eliminate docs as a formal subproject. This simplifies the build in a number of ways, including removing the need for distinguishing between 'subprojects' and 'javaprojects' as well as allowing users to build both 'api' and 'reference' docs without qualifying with a ':docs' prefix. Also rename the src/info directory to src/dist to better reflect that these files are packaged with the distribution. For example, the readme.txt there is really the distribution readme, distinct from the README.md at the root of the project which is for building from source, etc.
127 lines
7.6 KiB
XML
127 lines
7.6 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<section version="5.0" xml:id="scripting" xmlns="http://docbook.org/ns/docbook"
|
||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||
xmlns:ns5="http://www.w3.org/1999/xhtml"
|
||
xmlns:ns4="http://www.w3.org/1998/Math/MathML"
|
||
xmlns:ns3="http://www.w3.org/2000/svg"
|
||
xmlns:ns="http://docbook.org/ns/docbook">
|
||
<title>Scripting support</title>
|
||
|
||
<para>With Spring Integration 2.1 we've added support for the <ulink url="http://jcp.org/aboutJava/communityprocess/pr/jsr223/">
|
||
JSR223 Scripting for Java specification</ulink>,
|
||
introduced in Java version 6. This allows you to use scripts written in any supported language including
|
||
Ruby/JRuby, Javascript and Groovy to provide the logic for various integration components similar to the way
|
||
the Spring Expression Language (SpEL) is used in Spring Integration. For more information about JSR223 please refer to the
|
||
<ulink url="http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/">documentation</ulink>
|
||
<important>
|
||
Note that this feature requires Java 6 or higher. Sun developed a JSR223 reference implementation which works with
|
||
Java 5 but it is not officially supported and we have not tested it with Spring Integration.
|
||
</important>
|
||
</para>
|
||
<para>
|
||
In order to use a JVM scripting language, a JSR223 implementation for that language must be included in your class path. Java 6 natively
|
||
supports Javascript. The <ulink url="http://groovy.codehaus.org">Groovy</ulink> and
|
||
<ulink url="http://jruby.org/">JRuby</ulink> projects provide JSR233 support in their standard distribution.
|
||
Other language implementations may be available or under development. Please refer to the appropriate project website for more information.
|
||
<important>
|
||
Various JSR223 language implementations have been developed by third parties. A particular implementation's compatibility
|
||
with Spring Integration depends on how well it conforms to the specification and/or the implementer's interpretation of the specification.
|
||
</important>
|
||
<tip>If you plan to use Groovy as your scripting language, we recommended you use <xref linkend="groovy">Spring-Integration's Groovy Support</xref>
|
||
as it offers additional features specific to Groovy. <emphasis>However you will find this section relevant as well</emphasis>.
|
||
</tip>
|
||
</para>
|
||
|
||
<section id="scripting-config">
|
||
<title>Script configuration</title>
|
||
|
||
<para>Depending on the complexity of your integration requirements
|
||
scripts may be provided inline as CDATA in XML configuration or as a
|
||
reference to a Spring resource containing the script. To enable scripting support
|
||
Spring Integration defines a
|
||
<classname>ScriptExecutingMessageProcessor</classname> which will
|
||
bind the Message Payload to a
|
||
variable named <code>payload</code> and the Message Headers to a <code>headers</code>
|
||
variable, both accessible within the script execution context. All that is left for you to do is
|
||
write a script that uses these variables. Below are a couple of sample configurations:</para>
|
||
|
||
<para><emphasis>Filter</emphasis> <programlisting language="xml"><int:filter input-channel="referencedScriptInput">
|
||
<int-script:script lang="ruby" location="some/path/to/ruby/script/RubyFilterTests.rb"/>
|
||
</int:filter>
|
||
|
||
<int:filter input-channel="inlineScriptInput">
|
||
<int-script:script lang="groovy"><![CDATA[
|
||
return payload == 'good'
|
||
]]></int-script:script>
|
||
</int:filter></programlisting>
|
||
|
||
Here, you see that the script can be included inline
|
||
or can reference a resource location via the <code>location</code> attribute. Additionally the <code>lang</code> attribute
|
||
corresponds to the language name (or JSR223 alias)</para>
|
||
|
||
<para>Other Spring Integration endpoint elements which support scripting include <emphasis>router</emphasis>, <emphasis>service-activator</emphasis>,
|
||
<emphasis>transformer</emphasis>, and <emphasis>splitter</emphasis>. The scripting configuration in each case would be identical to the above
|
||
(besides the endpoint element).
|
||
</para>
|
||
|
||
<para>Another useful feature of Scripting support is the ability to update (reload) scripts without
|
||
having to restart the Application Context. To accomplish this, specify the <code>refresh-check-delay</code>
|
||
attribute on the <emphasis>script</emphasis> element:
|
||
|
||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="5000"/></programlisting>
|
||
|
||
In the above example, the script location will be checked for updates every 5 seconds. If the script is updated,
|
||
any invocation that occurs later than 5 seconds since the update will result in execution of the new script.
|
||
|
||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="0"/></programlisting>
|
||
|
||
In the above example the context will be updated with any script modifications
|
||
as soon as such modification occurs, providing a simple mechanism for 'real-time' configuration.
|
||
|
||
Any negative number value means the script will not be reloaded after initialization of the application context.
|
||
This is the default behavior. <important>Inline scripts can not be reloaded.</important></para>
|
||
|
||
<programlisting language="xml"><int-script:script location="..." refresh-check-delay="-1"/></programlisting>
|
||
|
||
<para><emphasis>Script variable bindings</emphasis> </para>
|
||
|
||
<para>
|
||
Variable bindings are required to enable the script to reference variables externally provided to the script's execution context.
|
||
As we have seen, <code>payload</code> and <code>headers</code> are used as binding variables by default. You can bind additional variables
|
||
to a script via <code><variable></code> sub-elements:
|
||
<programlisting language="xml"><![CDATA[<script:script lang="js" location="foo/bar/MyScript.js">
|
||
<script:variable name="foo" value="foo"/>
|
||
<script:variable name="bar" value="bar"/>
|
||
<script:variable name="date" ref="date"/>
|
||
</script:script>]]></programlisting>
|
||
As shown in the above example, you can bind a script variable either to a scalar value or a Spring bean reference. Note that
|
||
<code>payload</code> and <code>headers</code> will still be included as binding variables.
|
||
|
||
</para>
|
||
<para>
|
||
If you need more control over how variables are generated, you can implement your own Java class
|
||
using the <classname>ScriptVariableGenerator</classname> strategy:
|
||
<programlisting language="java"><![CDATA[public interface ScriptVariableGenerator {
|
||
|
||
Map<String, Object> generateScriptVariables(Message<?> message);
|
||
|
||
}]]></programlisting>
|
||
|
||
This interface requires you to implement the method <code>generateScriptVariables(Message)</code>. The Message
|
||
argument allows you to access any data available in the Message payload and headers and the return value is
|
||
the Map of bound variables. This method will be called every time the script is executed for a Message. All you need to do is
|
||
provide an implementation of <classname>ScriptVariableGenerator</classname> and reference it with the <code>script-variable-generator</code>
|
||
attribute:
|
||
<programlisting language="xml"><![CDATA[<int-script:script location="foo/bar/MyScript.groovy"
|
||
script-variable-generator="variableGenerator"/>
|
||
|
||
<bean id="variableGenerator" class="foo.bar.MyScriptVariableGenerator"/>]]></programlisting>
|
||
|
||
<important>
|
||
You cannot provide both the <code>script-variable-generator</code> attribute and <code><variable></code> sub-element(s)
|
||
as they are mutually exclusive. Also, custom variable bindings cannot be used with an inline script.
|
||
</important>
|
||
</para>
|
||
</section>
|
||
</section>
|