org.jboss.soa.esb.actions.scripting
Class GroovyActionProcessor

java.lang.Object
  extended by org.jboss.soa.esb.actions.scripting.GroovyActionProcessor
All Implemented Interfaces:
ActionLifecycle, ActionPipelineProcessor

public class GroovyActionProcessor
extends java.lang.Object
implements ActionPipelineProcessor

Groovy Scripting action processor.

 <action name="groovy" class="org.jboss.soa.esb.actions.scripting.GroovyActionProcessor">
     <property name="script" value="/scripts/helloWorld.groovy" />
 </action>
 

The message is bound on the script under the name "message" and the configuration is bound under the name "config".

The script can also be supplied to this action as the message payload, allowing you to dynamically supply the action script. For message based scripts to be executable, the "script" action property must be omitted and the "supportMessageBasedScripting" property must be set to "true". There are obvious security issues around executing message based scripts, so use this feature controlled manner.

Author:
Gregory Pierce., tom.fennelly@jboss.com

Field Summary
protected  ConfigTree configTree
           
protected  groovy.util.GroovyScriptEngine scriptEngine
           
 
Fields inherited from interface org.jboss.soa.esb.actions.ActionPipelineProcessor
PROCESS_EXCEPTION_METHOD, PROCESS_METHOD, PROCESS_SUCCESS_METHOD
 
Constructor Summary
GroovyActionProcessor(ConfigTree config)
           
 
Method Summary
 void destroy()
          Destroy the action instance.
protected  groovy.lang.Script getScript(Message message)
           
static java.lang.String getScriptFromClasspath(java.lang.String scriptPath)
          Get the input stream for the Groovy script (from the classpath).
 void initialise()
          Initialise the action instance.
 Message process(Message message)
          Processes an ESB message.
 void processException(Message message, java.lang.Throwable th)
          Process an exception generated by the pipeline processing.
 void processSuccess(Message message)
          Process a successful pipeline process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configTree

protected ConfigTree configTree

scriptEngine

protected groovy.util.GroovyScriptEngine scriptEngine
Constructor Detail

GroovyActionProcessor

public GroovyActionProcessor(ConfigTree config)
                      throws ConfigurationException
Throws:
ConfigurationException
Method Detail

initialise

public void initialise()
                throws ActionLifecycleException
Description copied from interface: ActionLifecycle
Initialise the action instance.

This method is called after the action instance has been instantiated so that configuration options can be validated.

Specified by:
initialise in interface ActionLifecycle
Throws:
ActionLifecycleException - for errors during initialisation.

getScriptFromClasspath

public static java.lang.String getScriptFromClasspath(java.lang.String scriptPath)
                                               throws java.io.IOException
Get the input stream for the Groovy script (from the classpath).

Parameters:
scriptPath - The script classpath.
Returns:
An input
Throws:
java.io.IOException

destroy

public void destroy()
             throws ActionLifecycleException
Description copied from interface: ActionLifecycle
Destroy the action instance.

This method is called prior to the release of the action instance. All resources associated with this action instance should be released as the instance will no longer be used.

Specified by:
destroy in interface ActionLifecycle
Throws:
ActionLifecycleException

process

public Message process(Message message)
                throws ActionProcessingException
Processes an ESB message. Configuration is via two properties of this ESB element scriptPath - The path to the script that will be run script - the name of the script that will be run (include .groovy exception)

Specified by:
process in interface ActionPipelineProcessor
Parameters:
message - The current message being processed.
Returns:
The message to be passed to the next stage of the pipeline.
Throws:
ActionProcessingException - for errors during processing.

getScript

protected groovy.lang.Script getScript(Message message)
                                throws ActionProcessingException
Throws:
ActionProcessingException

processException

public void processException(Message message,
                             java.lang.Throwable th)
Description copied from interface: ActionPipelineProcessor
Process an exception generated by the pipeline processing. Invoked when the processing of a subsequent stage of the pipeline generates an exception.

Specified by:
processException in interface ActionPipelineProcessor
Parameters:
message - The original message.
th - The throwable raised by the pipeline processing

processSuccess

public void processSuccess(Message message)
Description copied from interface: ActionPipelineProcessor
Process a successful pipeline process. Invoked when the pipeline processing completes successfully.

Specified by:
processSuccess in interface ActionPipelineProcessor
Parameters:
message - The original message.