|
Page Edited :
SM :
servicemix-scripting
servicemix-scripting has been edited by Lars Heinemann (Jun 12, 2008). Content:ServiceMix ScriptingThe ServiceMix Scripting component provides support for processing scripts using JSR-223.
What is JSR-223JSR-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 Have a look at the project site to get an overview what languages are available and what dependencies they have.
InstallationInstalling the servicemix-scripting component can be done in several ways:
Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console. CreationYou can use Maven to create a service unit. mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-scripting-service-unit \
-DgroupId=com.mycompany.myproduct \
-DartifactId=mycomponent.artifact
The following table shows the additional configuration possibilities of the endpoint.
For all xbean file endpoint configuration take a look at Xml schemas The script resourceThe script resource can be defined in different ways: script="classpath:MyScript.js" OR script="file:///home/lhein/scripts/groovy/MyGroovyScript.groovy" The user bindingsYou can specify user bindings to be available from inside the script as variables. For doing this you can specify the Example: <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>
These values (company and logo) are available from within the MyJavaScriptFile.js via a global variable called "bindings". var companyName = bindings.get("company");
var companyLogoPath = bindings.get("logo");
MarshalersYou can write your own marshalers to have a possibility to influence the bahviour of the engine. onStartup (...)This method is called by the endpoint when the endpoint is starting. onShutdown (...)This method is called by the endpoint when the endpoint is shutting down. getScriptCode (...)This method is called to get the input stream for the script defined in script attribute of the xbean configuration. registerUserBeans (...)This method is called after all scope variables of the endpoint where set, just before starting the script. After finishing your marshaler you can simply configure your endpoints to use it: Marshaler example <scripting:endpoint service="test:myScriptService" endpoint="scriptingEndpoint" script="classpath:MyScript.rb" > <property name="marshaler"> <bean class="com.mycompany.MyScriptingMarshaler" /> </property> </scripting:endpoint> Global variablesWhile inside the script you have a access to the following variables / objects:
Migration from ScriptComponent / GroovyComponentThe servicemix-scripting is a full replacement of the leightweight components for "script" and "groovy". What are the differences?The GroovyComponent knew a binding / variable called builder which in fact was a DOMBuilder. This variable isn't available now. To have it again you could write your own marshaler and provide such a variable in the registerUserBeans(...) method. Both components, GroovyComponent and ScriptComponent, knew the following configuration attributes:
These attributes are no longer available. Instead of scriptText you could write your own marshaler overriding the getScriptCode (...) method to provide your scriptText. |
Unsubscribe or edit your notifications preferences
