...
The ServiceMix Scripting component provides support for processing scripts using JSR-223.
Note | ||
---|---|---|
| ||
Note that this component is only available in releases >= 3.3. |
What is JSR-223
Scripting for the Java Plaform (JSR-223 is some kind of abstraction layer for using different scripting languages from inside java. You can code the script caller class once and use it with
every available JSR-223 compliant script engine / language.) 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 | ||||
---|---|---|---|---|
| ||||
The servicemix-scripting engine is packaged with the following engines:
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.
|
Endpoint Configuration
Code Block | ||||
---|---|---|---|---|
| ||||
<scripting:endpoint service="test:myScriptingService" endpoint="scriptingEndpoint" script="classpath:MyGroovyScript.groovy" /> |
Code Block | ||||
---|---|---|---|---|
| ||||
The endpoint can handle InOnly and InOut MEP. |
The following table shows the additional configuration possibilities of the endpoint.
| |
<scripting:endpoint service="test:myScriptingService"
endpoint="scriptingEndpoint"
script="classpath:MyGroovyScript.groovy"
targetService="test:anotherService"/>
|
Info | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
Info | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
...
|
The script resource
The script resource can be defined in different ways:
...
No Format |
---|
<beans xmlns:scripting="http://servicemix.apache.org/scripting/1.0" xmlns:test="http://servicemix.apache.org/test" xmlns:util="http://www.springframework.org/schema/util"> <!-- JavaScript JSR-223 Endpoint --> <scripting:endpoint service="test:js-jsr223" endpoint="endpoint" script="classpath:MyJavaScriptFile.js" bindings="#myCustomBindings"> </scripting:endpoint>/> <util:map id="myCustomBindings"> <entry key="company" value="My Company" /> <entry key="logo" value="/home/lhein/myLogo.png" /> </util:map> </beans> |
...
Variable | Description | Type |
---|---|---|
componentContext | The JBI Component Context | javax.jbi.component.ComponentContext |
deliveryChannel | the Delivery Channel | javax.jbi.messaging.DeliveryChannel |
exchange | The JBI Message Exchange | javax.jbi.messaging.MessageExchange |
inMessage | The in message | javax.jbi.messaging.NormalizedMessage |
outExchange | The JBI Message Exchange for the answer | javax.jbi.messaging.MessageExchange |
outMessage | The out message for answer | javax.jbi.messaging.NormalizedMessage |
log | The script logger object | java.util.logging.Logger |
endpoint | the scripting endpoint which executes the script | org.apache.servicemix.scripting.ScriptingEndpoint |
endpointname | the name of this endpoint | java.lang.String |
servicename | the name of this service | java.lang.String |
interfacename | the name of this interface | java.lang.String |
script | the absolute path of the script or the script itself if path can't be determined | java.lang.String or org.springframework.core.io.Resource |
bindings | a map containing user defined values | java.util.Map<String,Object> |
...