This page last changed on May 31, 2006 by tcarlson.

As of Mule 1.2 the Groovy component is no longer included in the distribution. Instead users should use the JSR-223 Scripting components.

Groovy Components

Groovy scripts can be invoked as Mule managed components by using org.mule.extras.groovy.GroovyComponent.

<mule-descriptor name="GroovyUMO"
    inboundEndpoint="jms://localhost/groovy.queue"
    implementation="org.mule.extras.groovy.GroovyComponent">
    <properties>
        <property name="script" value="test1.groovy"/>
        <property name="methodName" value="receive"/>
        <property name="autoReload" value="true"/>
        <property name="reloadInterval" value="60000"/>
    </properties>
</mule-descriptor>
Property Description
script The location of the groovy script to load. This can be on the local filesystem or classpath. If a classpath resource is set the autoReload property is set to false. If this property is not set it defaults to the name of the component with a .groovy extension i.e. GroovyUMO.groovy.
methodName the method to call on the component when an event is received for it. If this property is not set it is defaulted to onCall().
autoReload Determines if the script should be monitored and the component reloaded when it changes. This doesn't apply if the script is loaded from the classpath. the default value is true.
reloadInterval Determines the frequency in milliseconds the script is checked for changes. This property is ignored if autoReload is false. The default for this property is 60000.

Groovy Configuration Builder

The GroovyConfigurationBuilder allows developers to create a mule instance from a groovy script. To load the manager from a script for code -

GroovyConfigurationBuilder builder = new GroovyConfigurationBuilder();
UMOManager manager = builder.configure("../conf/mule-config.groovy");

Or to start the server from the command line -

java -cp ... org.mule.MuleServer 
-builder org.mule.extras.groovy.config.GroovyConfigurationBuilder 
-config ../conf/mule-config.groovy

For more information about configuring a Mule instance from code or script see Configuring Mule Programmatically.

Groovy Transformers

Groovy support currently provides transformers to enable Mule users to transform events using groovy scripts.
Here is an example groovy script that provides methods for ptransforming comma separated strings to Lists and vice versa.

class StringListTransformer {
  toList(src) {
    return src.toString().tokenize(",");
  }
  
  toString(src) {
    result="";
    src.each { t | result+= "," + t };
    return result.substring(1);
  }
}

the configuration for the transformer would look like -

<transformer name="StringToList" className="org.mule.extras.groovy.GroovyTransformer" 
    returnClass="java.util.List">
    <properties>
        <property name="sourceType" value="java.lang.String"/>
        <property name="script" value="./groovy/StringListTransformer.groovy"/>
        <property name="methodName" value="toList"/>
    </properties>
</transformer>

The sourceType property tells the transformer only to accept source objects of type string. This property can be set multiple times to register different source types.

The methodName property specifies which method to call on the script. The default is 'transform'.

The script property specifies the location and name of the script. If this value is not set, it will default to the name of the the transformer with the groovy extension. So to simplify configuration you may want to have one groovy script per transform with a single method called transform.

Document generated by Confluence on Oct 03, 2006 09:23