The Script adapter enables Sterling B2B Integrator to run scripts that are written in various languages that use the Bean Scripting Framework (BSF).
The following table provides an overview of the Script adapter:
|Graphical Process Modeler (GPM) category||All Services|
|Description||Enables Sterling B2B Integrator to execute scripts written in various languages that utilize the Bean Scripting Framework (BSF), such as Jython and JPython. For more information about the Bean Scripting Framework and supported languages, see http://jakarta.apache.org/bsf/.|
|Business usage||Executes a script written in a language supported by the Bean Scripting Framework. If a customer has in-house expertise in one of the supported script languages, this adapter can be used to quickly solve the business need without having to write a new adapter.|
|Usage example||A customer already has scripts in place to perform some processing task and wants to incorporate that into a business process. As long as the script is written in a language that is supported by the Bean Scripting Framework, then it can be easily incorporated using this adapter.|
|Requires third-party files?||At a minimum, the BSF classes (bsf.jar) are required, plus any and all script language classes (for example, jython.jar, bsh.jar). For more information about jython.jar, see www.jython.org. For more information about bsf.jar, see http://jakarta.apache.org/bsf/.|
|Platform availability||All supported Sterling B2B Integrator platforms|
|Initiates business processes?||Can be performed but is up to the individual script writer.|
|Invocation||Runs as part of a business process.|
|Business process context considerations||No|
|Returned status values||The script can set the returned status, therefore the individual script writer determines what status is set. The only exception is when the script runs and no status is set; in this case the adapter returns a status of Success.|
|Restrictions||This adapter has been tested with Python only. Scripts written in other supported languages may work, but be certain that the language comes with the necessary classes and that you have access to its documentation.|
How the Script Adapter Works
The Script adapter gives users a way to incorporate scripts into Sterling B2B Integrator business processes without having to write a new adapter to handle the business need.
The Script adapter executes scripts written in languages supported by the Bean Scripting Framework. The Script adapter provides tight coupling between BSF user scripts and Sterling B2B Integrator by allowing scripts to access java objects that are normally only available to Sterling B2B Integrator adapters, thus providing a solution to complex business problems.
Your company uses a Python script to generate midday inventory reports from a legacy tracking system residing on a mainframe. Sterling B2B Integrator runs under UNIX, receiving and processing incoming orders and producing midday order reports. Rather than using two systems to produce the midday status reports, you use the Script adapter to import inventory data into the order reporting business process, allowing for easier tracking of orders against existing inventory.
Business Process Example
The following example uses the Script adapter:
<process name = "BSF"> <operation name="Script Adapter"> <participant name="ScriptAdapter"/> <output message="ScriptAdapterInputMessage"> <assign to="scriptFileName">/somepath/test.py</assign> <assign to="." from="*"></assign> </output> <input message="inmsg"> <assign to="." from="*"></assign> </input> </operation> </process>
Script Adapter Restrictions
The only scripts this adapter can execute have to be supported by the Bean Scripting Framework. If and when new script languages develop script engines that work with the Bean Scripting Framework, no code changes need to occur in the adapter code, as new script languages can be registered and used at any time.
For some adapters used with third-party software, you must install specific .jar files or drivers before you can use the adapter with Sterling B2B Integrator. These third-party .jar files are available from the applicable third-party software vendors. Often, you can download the files from the vendor's Web site. If an adapter requires any third-party files, the specific information about the files is included in the documentation for that adapter.
- Copy the .jar file to a directory on the host computer where Sterling B2B Integrator is installed. Record the path and name of the directory.
- Shut down Sterling B2B Integrator if it is running.
- Install the .jar file by running the install3rdParty script located in the
installdir/bin directory. You can access the following instructions for using the
command by typing in “install3rdParty” at the command
Usage: ./install3rdParty.sh vendorName vendorVersion <-j | -l | -p | -r | -d > filelist [-nodeploy] using: -j for jar/zip files -l for shared libraries -p for properties files -r for resource properties files -d for database jar/zip files ./install3rdParty.sh ibm_sap 3_5 -j /usr/local/lib/sap/*.jar ./install3rdParty.sh ibm_sap 3_5 -j /usr/local/lib/sap/infobus.jar ./install3rdParty.sh oracle 1_2 -d /usr/local/lib/jar/*.jar ./install3rdParty.sh oracle 1_2 -d /usr/local/lib/jar/classes12.zip ./install3rdParty.sh ibm_sap 3_5 -j /usr/local/lib/sap/infobus.jar ./install3rdParty.sh ibm_sap 3_5 -l /usr/local/lib/sap/*.so ./install3rdParty.sh ibm_sap 3_5 -l /usr/local/lib/sap/libivjsid35.so ./install3rdParty.sh ibm_sap 3_5 -p /usr/local/lib/sap/*.properties ./install3rdParty.sh ibm_sap 3_5 -p /usr/local/lib/sap/some.properties ./install3rdParty.sh mqseris 2_0 -r /usr/local/lib/mqs/service.properties
- Restart Sterling B2B Integrator. You can now use this adapter in Sterling B2B Integrator.
Implementing the Script Adapter
- Write a script in a language supported by the Bean Scripting Framework.
- Configure the predefined Script adapter, or create a new Script adapter configuration. For information, see Managing Services and Adapters.
- Configure the Script adapter. For information, see Configuring the Script Adapter.
- Test the Script adapter configuration. For information, see Testing the Script Adapter Configuration.
- Use the Script adapter in a business process.
Configuring the Script Adapter
To configure the Script adapter, you must specify settings for the following fields in the GPM:
|Script Filename (scriptFileName)||Fully qualified path and filename of the script to execute. Required.|
|Script Language Name (langName)||Name of the script language (for example, Python). Optional — only required if not already included within Bean Scripting Framework (BSF).|
|Script Engine Class (engineClass)||The name of the script engine class (for example, org.apache.bsf.engines.jpython.JPythonEngine). Optional – only required if not already included within BSF.|
|Script Language Extension (langExt)||The extension used to associate with this language (for example: py, pl, or bsh). Optional — only required if not already included within BSF.|
Objects Exposed for Use By a Script (Object Name – Class Exposed)
- siWfc – WorkFlowContext
- siIwf – InitialWorkFlowContext
- siWfd – WorkFlowDef
- siRmi – BSFServer (the “little-a” RMI class for doing I/O)
- siDoc – Document
- siLog - XLogger
Testing the Script Adapter Configuration
After you have a script written that you want to test, create an instance of the Script adapter and create a business process that runs that instance.
Python Script Example
The following example (Test.py) illustrates a script written in Python:
# This script expects an input file with the workflow context # This script expects a bp called zze (FS Extract) to exist siDoc = siWfc.getPrimaryDocument(); name = siDoc.getBodyName(); body = siDoc.getBody(); siLog.logError(name); stuff = siRmi.readFile("/home/test.txt"); id1 = siWfd.getIDForName("zze"); siIwf.setWorkFlowDefId(id1); siIwf.setDocumentName("junk.txt"); siIwf.setDocumentBody(body); siWfk = siIwf.start(); id2 = siWfk.getWorkFlowId(); siLog.logError(str(id2)); siWfc.addBootStrapWorkFlows(str(id2)); siDoc = siWfc.createDocument(); siDoc.setBody("this is a test"); siDoc.setBodyName("test.txt"); siWfc.putPrimaryDocument(siDoc); siWfc.setWFContent("TestVal", "Hello"); siWfc.setWFStatusRpt("Status_Report", "hello"); siWfc.setAdvancedStatus("worked"); siWfc.setBasicStatus(siWfc.SUCCESS);