To create and run the sample application:
Starting EAServer
If EAServer is not already running, follow the instructions under “Starting the server” to start the server.
Starting EAServer Manager
If EAServer Manager is not already running, start it as described in “Using EAServer Manager”.
This section shows you how to use EAServer Manager to create the package, component, and method for the sample application.
For complete information on creating packages, components, and methods, see Chapter 5, “Defining Component Interfaces,” in the EAServer Programmer’s Guide.
In EAServer, a package is a unit of deployment for a group of components that perform related tasks. Before a component can be instantiated by clients, it must be installed in a package, and that package must be installed in the server. The steps below create the package and component within the predefined “Jaguar” server to satisfy these requirements.
Creating the Tutorial package
if it does not exist
In EAServer Manager, expand the servers folder, then expand the Jaguar server icon.
Expand the Installed Packages folder. If the Tutorial package is displayed, skip to “Define and install a new component”.
Highlight the Installed Packages folder, and select File | Install Package.
In the Package wizard, select Create and Install a New Package.
For the package name, enter Tutorial
.
Click Create New Package.
You see the Package Properties window.
Click OK.
Defining the new component
Click the Tutorial package.
Select File | New Component.
In the Define New Component wizard, select Define New Component and click Next.
For the component name, enter JavaArithmetic
.
Click Finish. You see the Component Properties window.
Select the General tab. Fill in the fields as follows:
Field |
Value |
---|---|
Description |
Tutorial Java component |
Component Type |
Java - CORBA |
Java Class |
Sample.Intro.JavaArithmetic.JavaArithmeticImpl |
Leave the remaining fields at their default settings.
Click OK.
The component interface will have one method, multiply.
Defining the component interface
Expand the Tutorial package. Double-click the JavaArithmetic component to show the Roles and Interfaces folders beneath it.
Double-click the Interfaces folder, and highlight the Tutorial::JavaArithmetic interface. If you do not see this interface, install it as follows:
Highlight the Interfaces folder and select File | Add Interfaces ...
In the Install Interface dialog box, highlight Tutorial::JavaArithmetic in the Selected to Install table, then click Install.
Highlight the Tutorial::JavaArithmetic interface that is now displayed under the Interfaces folder.
Select File | New Method.
Assign the name multiply to the method.
Click Create New Method.
You see the Method Properties window.
In the Return field, select double as the method’s return type.
Beneath the empty parameter list, click Add to add a parameter. In the New Parameter dialog:
For the parameter name, enter m1
.
For Mode, select in
.
For Type, select double
.
Click OK to close the New Parameter dialog box.
Repeat steps 7 and 8 to add a second parameter named m2
with
a Type of double.
Click OK to close the Method Properties dialog box.
Once you have created the package, component, and methods, you generate the stub and skeleton files for the component. The client-side application uses the stubs to invoke the server-side component methods. The skeleton acts as an interface between EAServer and your component methods.
Generating the stub and skeleton files for the
component
Click the Tutorial package and select the JavaArithmetic component.
Select File | Generate Stub/Skeleton.
Select Generate Stubs, then select Generate Java Stubs. Fill in the Java Stubs fields as follows:
Select CORBA from the drop-down list.
Select Generate Java Files.
Select Compile Java Stubs.
Leave the Java Code Base field at the default:
|
For Windows |
|
For UNIX |
Deselect Generate C++ Stubs.
Click Next to display the skeleton generation options and configure the settings as follows:
Select Generate Skeletons on Client.
Leave the Java Code Base field at the default value:
|
For Windows |
|
For UNIX |
Deselect “Compile Java Skeletons” (you cannot compile now because the component implementation source file is not ready).
Click Finish.
At this point, EAServer Manager has created server-side implementation files in the following directory under your EAServer installation:
java/classes/Sample/Intro/JavaArithmetic
The implementation template file is JavaArithemeticImpl.Java.new and the skeleton is called _sk_Tutorial_JavaArithmetic.java.
Completing the component implementation
Rename JavaArithemeticImpl.Java.new to JavaArithmeticImpl.Java (that is, delete the .new extension). Open the renamed file in a text editor, then find the definition of the multiply method. Change the definition so that it matches the one below:
double multiply (double m1, double m2) { return m1 * m2; }
Save your changes.
Compile the component skeleton and implementation files using a JDK 1.3 or later compiler—for example, if you are using Windows:
cd %JAGUAR%\java\classes\Sample\Intro\JavaArithmetic %JAGUAR%\bin\jc.bat *.java
Or, if you are using UNIX:
cd $JAGUAR/java/classes/Sample/Intro/JavaArithmetic $JAGUAR/bin/jc *.java
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:
Connects to EAServer.
Creates an authenticated session. Edit the user name and password in the source code if your server is configured to validate passwords and role memberships. By default, authentication and role checking are disabled in the server.
Creates a proxy for the component.
Calls the component multiply method.
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
If you have not refreshed or restarted the server since creating the JavaArithmetic component, refresh the server before running the client program.
Create a batch file or UNIX shell script to run the client application, then run it. The batch file or shell script configures the CLASSPATH environment variable, then runs the application using the JDK 1.3 java program included with your EAServer installation.
If necessary, you can run the client on a different machine than the server host, as long as your server uses a real host address and not localhost or 127.0.0.1.
Creating the Windows batch file
Create a file named runja.bat containing the commands below:
call %JAGUAR%\bin\setenv.bat set CLASSPATH=%JAGUAR%\java\lib\easj2ee.jar; set CLASSPATH=%CLASSPATH%;%JAGUAR%\java\lib\easclient.jar set CLASSPATH=%CLASSPATH%;%JAGUAR%\html\classes set JAVA_HOME=%JAGUAR_JDK13% %JAVA_HOME%\jre\bin\java TutorialApps.JAConsole %*
Creating the UNIX shell script
Create a file named runja containing the commands below:
#!/bin/sh . $JAGUAR/bin/setenv.sh CLASSPATH=$JAGUAR/java/lib/easj2ee.jar CLASSPATH=$CLASSPATH:$JAGUAR/java/lib/easclient.jar CLASSPATH=$CLASSPATH:$JAGUAR/html/classes export CLASSPATH JAVA_HOME=$JAGUAR_JDK13 $JAVA_HOME/jre/bin/java TutorialApps.JAConsole $*
Change the file permissions to allow the script to be executed. For example:
chmod 777 runja
Running the client application
Run the batch or script file, specifying the server host name and IIOP port number on the command line as follows:
runja iiop://host:iiop-port
For example:
runja iiop://myhost:9000
If everything is working, the application prints the results from the invocation of the multiply method. If not, check the error text printed on the console where you ran the client, and check for error messages in the server log file.
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |