Using Java Activities to Publish Information
Using several Java activities, you can invoke a method on a Java object and translate the resulting data into an XML document. The data can then be made available to other activities.
- In the samples directory of the File Explorer view, expand and double-click tibco_bw_sample_palette_java_invokemethod.zip to expand it in the Project Explorer. See Accessing Samples for more information.
- In Project Explorer expand the tibco_bw_sample_palette_java_invokemethod project.
- Fully expand the Processes directory and double-click PublishAllBalances.bwp to open it in the Process Editor pane.
- Click .
- At the left hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
- Click the Applications tab and then click the Deselect All button if you have multiple applications. Select the check box next to tibco_bw_sample_palette_java_invokemethod_application.
This will run the sample in Debug mode.
icon to stop the process.
A log is displayed in the Console view.
- Optionally, push your application to TIBCO Cloud Integration. For details on how to do this see the "Pushing an Application to Cloud" topic.
Understanding the Configuration
The following three Java activities are used in this sample.
- The Java Invoke activity invokes a method on a Java object.
- The Java To XML activity translates data from a Java object into an XML document that can be later used in other activities.
- The XML To Java activity supplies data to an XML schema to construct an instance of the desired Java object.
The source code for the Java objects, LocalBank, Account, Balance, and SystemProperties is in the src directory in the project.
- The CreateLocalBank activity is a Java Invoke activity that constructs an instance of the LocalBank object. This object contains the getBalance(...) method that the process later invokes to retrieve the balance.
- The CreateAccount activity is an XML To Java activity that creates an instance of the Account object and sets the object's data using an XML schema.
- The getBalance activity is a Java Invoke activity that invokes the getBalance(...) method on the LocalBank object created by the CreateLocalBank activity. The Account object created by the CreateAccount activity is also passed as a parameter to the getBalance(...) method. The method returns an instance of the Balance object that contains the balances for the specified account.
- If the getBalance activity returns an exception, the error is published by the PublishException (if the exception is InvalidAccount) or PublishError activity (in the event of any other exceptions).
- If the getBalance activity executes without any exception, the Balance activity is a Java To XML activity that takes the Balance object produced by the getBalance activity and converts the object's data to an XML document.
- The PublishBalance activity takes the data produced by the Balance activity and publishes the account and balance information by writing it to the log.
- The getAllBalance activity is a Java Invoke activity that constructs an instance of the LocalBank object and invokes the getAllBalance() method on that object. The output of the method is an instance of the java.util.ArrayList class that contains a collection of all balances.
- The CollectionToArray activity invokes the toArray method of java.util.ArrayList to convert the collection to an array of objects.
- The group then iterates over each object in the array. The Balance activity takes the current object in the array and converts its data to an XML document. The PublishBalance activity publishes the data from the output of the Balance activity.
- The SystemProperties activity is a Java To XML activity that constructs an instance of the SystemProperties object and provides the data in the class as an XML schema.
- The PublishJavaInfo activity uses the data produced by the SystemProperties activity and publishes the Java information by writing it to the log.