Invoking Custom Code to Complete a Purchase Order

The Java Invoke activity can be used to write custom code to get information from a legacy system, retrieve binary data, and so on.

Assume, for example, information from an ERP system is sent to a business partner using a B2B XML protocol such as CXML or RosettaNet. If some fields required by the protocol are not available from the ERP system, the missing information can be retrieved using the Java Invoke activity. The activity can access, for example, a CSV file. You can then combine the information coming from the ERP system and the CSV file and send it to the business partner.

Note: If you are accessing the sample from the Welcome page of TIBCO Business Studio™ for BusinessWorks™, go directly to Step 3.

Procedure

  1. In the samples directory, select palette > java > InvokeCode and double-click tibco.bw.sample.palette.java.InvokeCode. For more information, see Accessing Samples .
  2. In the Project Explorer view, expand the tibco.bw.sample.palette.java.InvokeCode project.
  3. Set the default ApplicationProfile to match the OS you are running on. For more information, see Setting the Default Application Profile.
  4. Fully expand the Processes directory and double-click JavaProcess.bwp.
  5. Click Run > Debug Configurations.
  6. At the left hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  7. Click the Applications tab and then click the Deselect All button. Select the check box next to tibco.bw.sample.palette.java.InvokeCode.application.
  8. Click Debug.
    This runs the sample in Debug mode.
  9. Click the Terminate icon to stop the process.

Result

The process combines the purchase order information in the PO.xml file and customer information in csvFile.log file present in BW_HOME\samples\palette\java\InvokeCode folder and writes it to the C:\tmp\InvokeCode\CompletePo.xml file.

Understanding the Configuration

The sample uses the Read File activity to read and parse an XML file into an XML tree. The Java Invoke activity gets customer information from the csvFile.log file and makes it available to the process. A Map activity combines the Read File and Java Invoke output to build a complete schema, which contains the purchase order and customer information. The combined information is passed to the RenderPOXML activity that converts the information to XML string, using the specified schema. The process then publishes the XML string by writing it to the CompletePo.xml file in C:\tmp\InvokeCode.

The example requires the following schema files:
  • PurchaseOrderSchema used by ParsePO XML, which parses the PO.
  • CustomerSchema referenced by CompletePO, which contains customer information.
  • CompletePO used by Render PO XML and has information on both the purchase order and the customer. CompletePO is a combination of PurchaseOrderSchema and CustomerSchema.

To view the Java source, fully expand the src directory and double-click JavaProcessJavaCode.java.

Troubleshooting

If any problem markers are visible in the project, close and re-open the project or import the project in a clean new workspace.