How to code an external Java client (outside of the SilverStream development environment) that accesses the SilverStream Server to invoke a triggered business object and return the result.
See the chapter on writing external Java clients in the Programmer's Guide |
For example, here's a triggered business object named boOrderSummary that computes the total value of order items and returns that value:
To learn about creating this kind of triggered business object, see the chapter on using invoked business objects in the Programmer's Guide.
To learn about the SilverStream API and how to configure your external development environment to use it, see the chapter on coding Java for SilverStream applications in the Programmer's Guide.
To learn about using the SilverStream API in your client classes and configuration requirements when deploying those classes, see the chapter on writing external Java clients in the Programmer's Guide.
Here's a class that provides a basic implementation of this technique.
package extjtech; import java.io.*; import com.sssw.rt.util.*; // The ExtBusObj class shows how you can access a SilverStream // server from an external Java client. It includes an example // of invoking a SilverStream triggered business object to // execute business logic on the server and return the result // to the client. public class ExtBusObj { // Instance variable for the SilverStream server session // object used by the ExtBusObj class. AgrServerSession session; // Constructor for the ExtBusObj class. It does the following: // * Connects to a SilverStream server // * Invokes a triggered business object on that server // * Displays the result returned by that object (if any) // // It takes 2 arguments: // 1 SilverStream server host // myserver // 2 SilverStream db & business object // mydb:com.myorg.busobj.boMyBusinessObject public ExtBusObj(String s3serverhost, String s3bolocation) { try { // Initialize the SilverStream runtime environment. Do // this if you need to specify a login handler for the // SilverStream server to call back when it requires user // authentication. (The login handler is a class that you // code and instantiate.) AgRuntime.init(new LoginHandler()); // Connect to the appropriate SilverStream server. This // establishes a server session (represented by an instance // of AgrServerSession). // // The following example connects via HTTP, but it could // use RMI-IIOP instead (if you code the connectRMI method // rather than connect). session = AgRuntime.connect(s3serverhost); // Invoke the specified business object (in the specified // database) on the SilverStream server. Object result; result = session.invokeBusinessObject(s3bolocation); // Display the string representation of the result returned // from the business object. System.out.println("Result of business object " + s3bolocation + " is:"); System.out.println(String.valueOf(result)); } catch (Exception e) { System.out.println("Application error in ExtBusObj"); e.printStackTrace(); System.exit(0); } finally { // When all done, close the SilverStream server session. session.close(); } } // Main method (used for application startup). public static void main(String[] args) { if (args.length < 2) { // Make sure all of the required command-line args // have been provided to the application. If not, // display an error message and terminate. System.out.println( "Missing Command-Line Arguments\n\n" + "Required arguments:\n" + "1 SilverStream server host\n" + "2 SilverStream db & business object\n\n" + "Example:\n" + "java extjtech.ExtBusObj " + "myserver " + "mydb:com.myorg.busobj.boMyBusinessObject"); System.exit(0); } else { // Get the command-line args so the application can // pass them to the ExtBusObj constructor. String s3serverhost = args[0]; String s3bolocation = args[1]; // Create an instance of ExtBusObj. This executes the // constructor for the class, which then accesses the // SilverStream server and invokes the requested // business object. ExtBusObj extbusobj = new ExtBusObj(s3serverhost, s3bolocation); } } }
When this class runs, it invokes an appropriate triggered business object, then displays the result.