Application Techniques

Invoking Business Objects from External Java Clients

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.

About this technique



Java Client Techniques> External Java clients


You'll learn about:

Source code

You can get the source code for this technique from:

Related reading

See the chapter on writing external Java clients in the Programmer's Guide

Setting up   Top of page

For this technique, you need:

Coding the client   Top of page

Here's a class that provides a basic implementation of this technique.

  package extjtech; 
  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:"); 
      catch (Exception e) { 
        System.out.println("Application error in ExtBusObj"); 
      finally { 
        // When all done, close the SilverStream server session. 
    // 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. 
          "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 " +           
      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, 

Running the client   Top of page

When this class runs, it invokes an appropriate triggered business object, then displays the result.

Copyright © 2000, SilverStream Software, Inc. All rights reserved.