Invoking a script

A scipt has a unique name and needs parameters for invocation.

There are two ways to invoke a script - invoking the GroovyService directly or using the GroovyRunnable.

        
Object result = null;
Object[] args = { new Integer(2) };
result = groovyService.execute( "test.groovy", args );
        
      
        
Object result = null;
Object[] args = { new Integer(2) };
GroovyRunnable runnable = groovyService.createGroovyRunnable( "test.groovy" );
runnable.setArgs( args1 );
runnable.run();
result = runnable.getResult();
        
      

Accessing the GroovyAvalonContext from a Groovy Script

The Fulcrum Groovy Service passes a GroovyAvalonContext to the script

A little example how to use those Java objects within a Groovy script taken from 'src/test/scripts/test.groovy'

        
System.out.println( avalonContext.getApplicationDir() );
avalonContext.getLogger().debug( "Logging from within a Groovy script ...:-)" );
        
      

A Real World Example

Our IT20one Invoice20one Enterprise Server creates digitally signed invoices and SMIME messages using X.509 certificates. Due to legal requirements we need to archive those documents using commercial archiving systems.

What we don't know at this point are the fields and the format for the index files since this depends on the customer and the archiving system being used.

Therefore the archiving is done using an event listener which maps the archiving event to the name of a Groovy script. The corresponding Groovy script can be easily customized without going through the whole release cycle.

And the Groovy scripts looks like Java and behaves like Java - voila!