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.
Procedure
Result
Three log files are created in c:\tmp\InvokeMethod:
- PublishAllBalances.log for the PublishAllBalances process: has customer account information, such as customerLastName, accountId, and checkingBalance.
- PublishBalance.log for the PublishBalance process: has customer account details, such as checking and savings balances.
- PublishJavaInfo.log for the PublishJavaInfo process: has system information such as, javaHome, javaVersion, and javaVendor.
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
PublishBalance process executes as follows:
- 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 a file in a tmp directory.
The
PublishAllBalances process executes as follows:
- 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
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:
- 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 a file in a tmp directory.
The filenames used in this sample are specified in the
.Copyright © Cloud Software Group, Inc. All rights reserved.