Java Task Service

The Java Task service runs java code in Sterling B2B Integrator. It eliminates the need to create a custom service.

The following table provides an overview of the Java Task service:

System Name JavaTask
Graphical Process Modeler (GPM) categories) All Services
Description Executes java code in Sterling B2B Integrator.
Business usage Used to execute java code without having to create a custom service.
Usage example To execute any piece of javacode within Sterling B2B Integrator.
Preconfigured? No
Requires third-party files? No
Platform availability All supported Application platforms.
Related services No
Initiates business processes? A business process can be initiated if the code is written to initiate it.
Invocation None
Business process context considerations None.
Returned status values Return of a string.
Restrictions None
Persistence level Defaults to Full.
Testing considerations None

How the Java Task Service Works

To execute the source code place import statements at the top followed by any set of standard java code you want to call. There are two classes automatically available to you, one called wfc (which is an instance of the workflow context of the current process), and one called log (which is an instance of the XLogger). There must be a return of a string included in the code fragment. This string will go to the log.

Example:

import com.sterlingcommerce.woodstock.workflow.Document;Document
doc = wfc.getPrimaryDocument();if (doc == null){ log.log("Document
is null");}else{ log.log("Document Name:" + doc.getDocumentName());}return
"return value here";Implementing the Java Task Service
To implement the Java Task service, complete the following tasks:
  1. Create a configuration of the Java Task service.
  2. Create a business process with this service in the GPM.
  3. Specify the Java source field with either Java code or the relative path to a file containing Java code. Use the settings in Configuring the Java Task Service for more information.
  4. Execute the business process.

Configuring the Java Task Service

The task takes two parameters, javaSrc and srcLocationMode. The javaSrc can either be the full path to a file containing the java code you wish to execute, or it can be the actual java code you wish to execute. The srcLocationMode will either be “File” if you are supplying a file name and “Inline” if you are specifying the code in the service instance.

To configure the Java Task service, you must specify settings for the following fields in Sterling B2B Integrator:

Field Description
srcLocationMode If you want to reference a file with a file name, valid value is: File. If you want to reference specific Java source code, valid value is: Inline.
relativePath If File is selected in the srcLocationMode field you must designate if there is a relativePath. If Yes, then the path is relative to the root of the Sterling B2B Integrator installation directory. If No, the path is absolute.
javaFile If File is selected in the srcLocationMode field, you must specify the file name with either a relative or absolute path.
javaSrc If Inline is selected in the srcLocationMode field, you must specify the specific Java source code you want to execute.
Note: The total inline source code specified cannot be larger than 2048 characters (bytes).

Business Process Example

The following example illustrates how the Java Task service can be used in a business process:

<process
name="JavaTaskDocTestFile">
<sequence> 
<operation name="JavaTask">
<participant name="JavaTaskDocTestFile"/>
<output message="Xout" > 
<assign to="srcLocationMode" from="'file'" /> 
<assign to="javaFile"
from="'/usr/local/source/DocumentCreator.java'" />
<assign to="." from="*"></assign>
</output>
<input message="Xin" >
<assign to="." from="*"></assign>
</input> 
</operation>
<operation name="JavaTaskFS">
<participant name="JavaTaskFS"/>
<output message="Xout" > 
<assign to="Action">FS_EXTRACT</assign>
<assign to="." from="*"></assign> 
</output>
<input message="Xin" >
<assign to="." from="*"></assign>
</input> 
</operation>
</sequence>
</process>