Working with a Content Manager OnDemand server

An object of the ODServer class represents and manages a connection to a Content Manager OnDemand server, provides transaction support, and runs server commands.

The following example uses ODServer methods to do the following tasks:
  • Prepare for logon
  • Set the application name
  • Display the server name, user ID and password
  • Display and set the connection type
  • Display and set the port
  • Disconnect from the server
This example demonstrates the following ODServer methods:
  • initialize
  • logon
  • logoff
  • terminate
  • getConnectType
  • getPassword
  • getPort
  • getServerName
  • getUserId
  • setConnectType
  • setPassword
  • setPort
  • setServerName
  • setUserId
This example uses the following runtime parameters:
  • Server name
  • User Id
  • Password
  • Port
Example of working with a Content Manager OnDemand server:
import java.util.*;
import java.io.*;
import com.ibm.edms.od.*;


public class TcServerMisc
{
    public static void main ( String argv[] )
    {
        ODServer odServer;

        String str;

        int j;
        //----------
        // If too few parameters, display syntax and get out
        //----------
        if ( argv.length < 4 )
        {
            System.out.println( "usage: java TcServerMisc <server> <port> <userid> <password>" );
            return;
        }
        try
        {
            //----------
            // Set the stage
            //----------
            System.out.println( "Testcase TcServerMisc started." );
            System.out.println( "This testcase should:" );
            System.out.println( "  Use ODServer methods setServer, setUserId, and setPassword" );
            System.out.println( "    to prepare for logon" );
            System.out.println( "  Set the application name" );
            System.out.println( "  Display the" );
            System.out.println( "    Server name" );
            System.out.println( "    User Id" );
            System.out.println( "    Password" );
            System.out.println( "  Set and display the port" );
            System.out.println( "  Logoff" );
            System.out.println( "" );
            System.out.println( "Ensure that all information is correct." );
            System.out.println( "" );
            System.out.println( "---------------------------------------------------" );
            System.out.println( "" );

            //----------
            // Logon to specified server
            //----------
            ODConfig odConfig = new ODConfig();
            if(odConfig == null)
                return;
            else
            {
                odServer = new ODServer(odConfig );
                odServer.initialize(  "TcServerMisc.java" );
                odServer.setServerName( argv[0] );
                odServer.setUserId( argv[2] );
                odServer.setPassword( argv[3] );
                odServer.setPort(Integer.parseInt(argv[1]));
                System.out.println( "Logging on to " + argv[0]  + " server with user " + argv[2] + "..." );
                odServer.logon( );
                //----------
                // Test miscellaneous methods
                //----------
                System.out.println( "Server Name: " + odServer.getServerName( ) );
                System.out.println( "User Id: " + odServer.getUserId( ) );
                System.out.println( "Password: " + odServer.getPassword( ) );
                j = odServer.getPort( );
                System.out.println( "Setting port to " + j + "..." );
                odServer.setPort( j );
                System.out.println( "Port: " + j );
                //----------
                // Cleanup
                //----------
                System.out.println( "Logging off..." );
                odServer.logoff( );
                odServer.terminate( );
                System.out.println( "" );
                System.out.println( "---------------------------------------------------" );
                System.out.println( "" );
                System.out.println( "Testcase TcServerMisc completed - analyze if required" );
                System.out.println( "" );
            }
        }

        catch ( ODException e )
        {
            System.out.println( "ODException: " + e );
            System.out.println( "   id = " + e.getErrorId( ) );
            System.out.println( "  msg = " + e.getErrorMsg( ) );
            e.printStackTrace( );
        }

        catch ( Exception e2 )
        {
            System.out.println( "exception: " + e2 );
            e2.printStackTrace( );
        }
    }
}