Search Results

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.


  1. In the samples directory of the File Explorer view, expand palette > java > InvokeMethod and double-click to expand it in the Project Explorer. See Accessing Samples for more information.
  2. In Project Explorer expand the tibco_bw_sample_palette_java_invokemethod project.
  3. Fully expand the Processes directory and double-click PublishAllBalances.bwp to open it in the Process Editor pane.
  4. Click Run > Debug Configurations.
  5. At the left hand tree of Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  6. 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.
  7. Click Debug.
    This will run the sample in Debug mode.
  8. Click the Terminate icon to stop the process.
    A log is displayed in the Console view.
  9. 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.

This project has the following three processes:
  • PublishBalance
  • PublishAllBalances
  • PublishJavaInfo
The PublishBalance process executes as follows:
  1. 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.
  2. 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.
  3. 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.
  4. 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).
  5. 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.
  6. 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 PublishAllBalances process executes as follows:
  1. 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.
  2. The CollectionToArray activity invokes the toArray method of java.util.ArrayList to convert the collection to an array of objects.
  3. 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 PublishJavaInfo process allows a Java To XML activity to make the well-known Java system properties available as well as the host name and address. This process executes as follows:
  1. 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.
  2. The PublishJavaInfo activity uses the data produced by the SystemProperties activity and publishes the Java information by writing it to the log.


  • If the Output tab of Java To XML activity is not populated, then press the Reload button next to the Class Name in Java To XML activity.
  • If any problem markers are visible in the project, close and re-open the project or import the project in a clean new workspace.