Create the client program

In the html\classes subdirectory of your EAServer installation, create a new directory called TutorialApps if it does not exist. In this directory, create the Java file below as JAConsole.java.

This is a simple command-line application that:

You can find a copy of JAConsole.java in the html/docs/tutorial/java-corba subdirectory of your EAServer installation. Here is the source for JAConsole.java:

//
// This is a sample command-line Java application that 
// invokes the JavaArithmetic component created in the EAServer
// Java component tutorial.
//
// Usage:
//    arith iiop://<host>:<port>
//
//    Where:
//
//       <host> is the host name or IP address of the server machine. 
//
//       <iiop-port> is the server's IIOP port (9000 in the
//         default configuration).
//
//
package TutorialApps;

import org.omg.CORBA.*;
import SessionManager.*;
import Tutorial.*;  // Package for EAServer stub classes

public class JAConsole {

    static public void main(String options[]) {
 
        String _usage = "Usage: JAConsole iiop://<host>:<port>\n";
        String _ior = null;
       
       try {

           if (options.length >= 1)
           {
               _ior = options[0];
           }
           else
           {
                System.out.println(_usage);
                return;
           }

           //
           // Initialize the CORBA client-side ORB and 
           // obtain a stub for the EAServer component instance.
           //
           System.out.println("... Creating session.");

           //
           // Initialize the ORB.
           //
           java.util.Properties props = new java.util.Properties();
           props.put("org.omg.CORBA.ORBClass", "com.sybase.CORBA.ORB");

           ORB orb = ORB.init(options, props);

           //
           // Create an instance of the EAServer SessionManager::Manager 
           // CORBA IDL object.
           //

           Manager manager = ManagerHelper.narrow(orb.string_to_object(_ior));

           //
           // Create an authenticated session with user "Guest" and password
           // "GuestPassword".
           // 
           Session session = manager.createSession("Guest", "GuestPassword");

           System.out.println("... Creating component instance.");

           //
           // Create a stub object instance for the 
           // Tutorial/JavaArithmetic EAServer component.
           //
           Tutorial.JavaArithmetic comp = 
           Tutorial.JavaArithmeticHelper.narrow(
           session.create("Tutorial/JavaArithmetic"));

           if (comp == null)
           {
             System.out.print("ERROR: Null component instance. ");
             System.out.print(
       "Check Jaguar Manager and verify that the component ");
             System.out.print(
       "Tutorial/JavaArithmetic exists and that it implements the ");
             System.out.println(
       "Tutorial::JavaArithmetic IDL interface.");
             return;
           }

           System.out.println("... Created component instance.");
    
            // 
            // Invoke the multiply method.
            //
           System.out.println("... Multiplying:\n");
           double m1 = 3.1;
           double m2 = 2.5;
           double result = comp.multiply(m1, m2);
           System.out.println("    " + m1 + "*" + m2 + "=" + result);

        // Explicitly catch exceptions that can occur due to user error,
        // and print a generic error message for any other CORBA system 
        // exception.

       } catch ( org.omg.CORBA.COMM_FAILURE cfe)
       {
           // The server is not running, or the specified URL is
           // wrong. 
             System.out.println(
              "Error: could not connect to server at " + _ior + "\n"
             + "Make sure the specified address is correct and the "
             + "server is running.\n\n" + _usage );
       } catch ( org.omg.CORBA.OBJECT_NOT_EXIST cone )
        {
            // Requested object (component) does not exist.
            System.out.println(
               "Error: CORBA OBJECT_NOT_EXIST exception. Check the "
             + "server log file for more information. Also verify "
             + "that the Tutorial/JavaArithmetic "
             + "component has been created properly in "
            + "Jaguar Manager. \n"); 

        } catch (org.omg.CORBA.NO_PERMISSION npe) {
           // Login failed, or the component requires an authorization role 
           // that this user is not a member of.
            System.out.println(
               "Error: CORBA NO_PERMISSION exception. Check whether "
             + "login authentication is enabled for your server and "
             + "whether the component has restricted access.\n");
             npe.printStackTrace();

       } catch (org.omg.CORBA.SystemException se)
       {
            // Generic CORBA exception
           System.out.println(
              "Received CORBA system exception: " 
              + se.toString() );
           se.printStackTrace();
       }

        return;
    } // main()

}

Compile the application source using a JDK 1.3 or later compiler, for example:

%JAGUAR%\bin\jc JAConsole.java