The Ant project for the component
The Ant project is located in the subdirectory samples/tutorial/java-corba. Source for the client is in Arith.java in the subdirectory client-src/com/sybase/easerver/tutorials/java/client.
This is a simple command-line application that:
Connects to EAServer.
Creates an authenticated session using the Guest account that we created earlier.
Creates a proxy for the component.
Calls the component multiply method.
Here is the source for Arith.java:
//package com.sybase.easerver.tutorials.java.client; /** * This is a sample command-line Java application that * invokes the JavaArithmetic component created in the EAServer * CORBA/Java component tutorial. Usage: * <pre> * 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 (2000 in the * default configuration). *</pre> */ import org.omg.CORBA.*; import SessionManager.*; import Tutorial.*; // Package for EAServer stub classes public class Arith { static public final String compName = "javatut/JavaArithmetic"; static public void main(String options[]) { String _usage = "Usage: Arith 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 // "GuestPassword2". // Session session = manager.createSession("Guest", "GuestPassword2"); System.out.println("... Creating component instance."); // // Create a stub object instance for the // Tutorial/JavaArithmetic EAServer component. // JavaArithmetic comp = JavaArithmeticHelper.narrow( session.create(compName)); if (comp == null) { System.out.print("ERROR: Null component instance. "); System.out.print( "Verify that the component " + compName + "exists and that it implements the " + "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 " + compName + "component has been created properly. \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. " + " Does the Guest account exist and have" + " you set the password to match this example" + " code?"); npe.printStackTrace(); } catch (org.omg.CORBA.SystemException se) { // Generic CORBA exception System.out.println( "Received CORBA system exception: " + se.toString() ); se.printStackTrace(); } return; } // main() }
Compiling the client application
Compile the application source using the component
Ant project, specifying the client
target.
For example, on Windows
set DJC_HOME=D:\Sybase\eas60 cd %DJC_HOME%\samples\tutorial\java-corba build client
Or, if running UNIX with C shell:
setenv DJC_HOME /opt/Sybase/eas60 cd $DJC_HOME/samples/tutorial/java-corba build client
The build script or batch file runs the EAServer djc-ant command, which invokes Ant on the default build file, build.xml in the current directory.