Application Techniques

Administering the Server from External Java Clients

How to code an external Java client (outside of the SilverStream development environment) that accesses the SilverStream Server to perform server administration operations.

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 java.util.*; 
  import com.sssw.rt.util.*; 
  import com.sssw.rts.adminclient.*; 
  import com.sssw.rts.adminapi.*; 
  // The ExtAdmin class shows how you can access a SilverStream 
  // server from an external Java client. It includes an example 
  // of performing administrative operations on the server from 
  // the client.  
  public class ExtAdmin { 
       // Instance variable for the SilverStream server session  
       // object used by the ExtAdmin class. 
       AgrServerSession session; 
    // Constructor for the ExtAdmin class. It does the following: 
    // * Connects to a SilverStream server 
    // * Gets a reference to that server for doing administration 
    //   work 
    // * Generates a report about the server's users and groups   
    // It takes 1 argument: 
    // * SilverStream server host 
    //     myserver 
    public ExtAdmin(String s3serverhost) { 
      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. In this case,  
        // you wouldn't use RMI-IIOP (the connectRMI method), 
        // because it doesn't support the Server Administration 
        // API. 
        session = AgRuntime.connect(s3serverhost); 
        // Get a reference to the server (represented by an instance 
        // of AgiAdmServer) that enables you to perform administration 
        // tasks. 
        AgiAdmServer admserver = AgAdmin.getServer(session); 
        // Generate a report about the server's Silver Security  
        // realm that lists: 
        // * Each user 
        // * All of the groups each user is in 
          // Local variables for user and group information. 
          AgiAdmDirectory userdir; 
          Enumeration users; 
          AgiAdmUser  user; 
          Enumeration groups; 
          AgiAdmGroup group; 
          // Get a reference to the directory of users in the Silver  
          // Security realm. 
          userdir = (AgiAdmDirectory)admserver.getElement( 
          // Get a sorted list of the users in that directory. 
          users = userdir.getChildren(AgiAdmContainer.GET_CHILDREN_SORTED); 
          // Print the report title. 
          System.out.println(">>>Silver Security"); 
          System.out.println("   >>>Users"); 
          // Loop through the user list. 
          while (users.hasMoreElements()) { 
            // Get and print information about an individual user. 
            user = (AgiAdmUser)users.nextElement(); 
            System.out.println("      Name: " + user.getName()); 
            System.out.println("         Groups:"); 
            // Get a sorted list of the groups for the current user. 
            groups = user.getGroups(true); 
            // Loop through the group list. 
            while (groups.hasMoreElements()) { 
              // Get and print information about an individual group. 
              group = (AgiAdmGroup)groups.nextElement(); 
              System.out.println("            " + group.getName()); 
          System.out.println("<<<End of admin report"); 
      catch (Exception e) { 
        System.out.println("Application error in ExtAdmin"); 
      finally { 
        // When all done, close the SilverStream server session. 
    // Main method (used for application startup). 
    public static void main(String[] args) { 
      if (args.length < 1) { 
        // 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" + 
            "*  SilverStream server host\n\n" + 
          "Example:\n" + "java extjtech.ExtAdmin " + 
      else { 
        // Get the command-line args so the application can 
        // pass them to the ExtAdmin constructor. 
        String s3serverhost = args[0]; 
        // Create an instance of ExtAdmin. This executes the  
        // constructor for the class, which then accesses the 
        // SilverStream server and performs administrative 
        // operations. 
        ExtAdmin extadmin = new ExtAdmin(s3serverhost); 

Running the client   Top of page

When this class runs, it does some administrative work on the specified SilverStream server (to get information about users and groups) and reports on the outcome.

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