Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The ServiceMix Scripting component provides support for processing scripts using JSR-223.

Note
titleAvailability

Note that this component is only available in releases >= 3.3.

What is JSR-223

Scripting for the Java Plaform (JSR-223) is a API that standardizes the way scripting language are integrated within a Java application. Have a look at the project site to get an overview what languages are available and what dependencies they have (https://scripting.dev.java.net/).

Info
Integrated Engines
Integrated Engines

The servicemix-scripting engine is packaged with the following engines:

  • Groovy (1.5.6)
  • JRuby (1.1.2)
  • Rhino JavaScript (1.7R1)

You don't need to care about dependencies for these 3 languages. For every other language take care to put the dependencies into your SU or the container classpath.

Installation

Installing the servicemix-scripting component can be done in several ways:

  • drop the installer zip in an hotdeploy directory monitored by ServiceMix
  • using ant tasks

Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.

Creation

Maven Archetype

You can use Maven servicemix-scripting-service-unit archetype to create a Scripting service unit.:

Code Block
mvn archetype:create \
    -DarchetypeGroupId=org.apache.servicemix.tooling \
    -DarchetypeArtifactId=servicemix-scripting-service-unit \
    -DarchetypeVersion=2010.01 \
    -DgroupId=comyour.mycompanygroup.myproductid \
    -DartifactId=mycomponentyour.artifact

or simply use the smx-arch tool from ServiceMix's bin folder.

...

.id \
    -Dversion=your-version

Once you've customized the service unit, simply install the SU:

Code Block

mvn install
Info

Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
To add your SU in a SA, you need to define it in the dependency sets:

Code Block

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>your.artifact.id</artifactId>
  <version>your-version</version>
</dependency>

Endpoint Configuration

Code Block
langxml
titleScripting Endpoint for InOut MEP
<scripting:endpoint service="test:myScriptingService" 
                    endpoint="scriptingEndpoint"
                    script="classpath:MyGroovyScript.groovy" /> 
Code Block
langxml
titleScripting Endpoint for InOnly MEP
<scripting:endpoint service="test:myScriptingService" 
                    endpoint="scriptingEndpoint"
                    script="classpath:MyGroovyScript.groovy" 
                    targetService="test:anotherService"/> 

The following table shows the additional configuration possibilities of the endpoint.

Info
titleendpoint attributesScripting Endpoint Attributes
borderStylesolidbgColor='lighblue'

Name

Type

Description

Default

marshaler

class

org.apache.servicemix.scripting.ScriptingMarshalerSupport

DefaultScriptingMarshaler

script

String

Spring Resource for the script file

null (must be spec'd)

language

String

script language to use (groovy, jruby, js etc)

autodetect (via file extension)

logResourceBundle

String

Log Resource Bundle for Script Logger

null

scriptLogger

class

java.util.logging.Logger

null

disableOutput

boolean

flag if no out message should be sent

false

copyProperties

boolean

flag if the message header will be copied to out message

false

copyAttachments

boolean

flag if the message attachments will be copied to out message

false true

bindings

class

java.util.Map

null

targetInterface

QName

the target interface

null

targetOperation

QName

the target operation

null

targetService

QName

the target service

null

targetEndpoint

String

the target endpoint

null

targetUri

String

target uri

null

...

The script resource

The script resource can be defined in different ways:

...