Make your own free website on Tripod.com

RMI-IIOP
Building an CORBA Client to the RMI/IIOP Server

Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................JDK 1.3 or Higher (I use JDK version 1.4)
.........................................The COS Naming JNDI Service Provider (I use JNDI version 1.2.1)

Building CORBA Client to the RMI/IIOP Server

The various steps that are involved in creating a CORBA Client to our RMI/IIOP Server are as follows:

  1. Create the Client class

  2. Compile the IDL File and generate the Stubs and Skeletons

  3. Compile the Client Application

  4. Make sure the Server is running and then startup the Client

1. Create the Client Class File

Create the CORBA Client - CorbaClient.java - in a package called CorbaClient. You create the ORB object as shown on Line 37 that is used to communicate with the IIOP Server. Using the ORB, you find the naming service as shown on Lines 38 and 39. Using the naming service, you find the server as shown on Lines 43 through 45. Any message sent to the server component will be converted to IIOP and sent to the server and back.

CorbaClient/CorbaClient.java
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
/**
 * The following example illustrates a CORBA Client
 *
 * author: Gopalan Suresh Raj
 * Copyright (c), 2002. All Rights Reserved.
 * URL: http://gsraj.tripod.com/
 * email: gopalan@gmx.net
 */

package CorbaClient;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
import org.omg.CosNaming.NameComponent;

import SimpleStocks.StockMarket;
import SimpleStocks.StockMarketHelper;

/**
 * This Client looks up the price of a given Stock Symbol
 *
 * Pre-requisites: You will need to have the COS naming server
 * and the StockMarket Server up and running before you can
 * invoke them from this client.
 *
 * @author Gopalan Suresh Raj
 */

public class CorbaClient {

  /**
   * Entry Point to this Application
   */

  public static void main( String[] args ) {

    try {
      // Create and Initialize the ORB
      ORB orb = ORB.init( args, null );
      org.omg.CORBA.Object object = orb.resolve_initial_references( "NameService" );
      NamingContext context = NamingContextHelper.narrow(
object );
      System.out.println ( "The ORB has been created and initialized ..." );

      // Resolve the object reference in naming
      NameComponent component = new NameComponent( "NASDAQ", "" );
      NameComponent path [] = { component };
      StockMarket server = StockMarketHelper.narrow( context.resolve( path ) );

      System.out.println ( "The Object Reference has been resolved in Naming ..." );

      // Invoke the Servant
      System.out.println( "The price of MY COMPANY is " +
                                   server.getPrice( "MY_COMPANY" ) );      

    }
    catch ( Exception exception ) {
      exception.printStackTrace();
    }

  }
}

2. Compile the IDL file and generate the Stubs and Skeletons

To run this client, you need to generate the appropriate stubs and skeletons using the idlj.exe compiler.

Command Prompt
C:\MyProjects\Cornucopia\iiop>idlj -v -i . -i C:\java\jdk1.4\lib -fclient -td CorbaClient SimpleStocks\StockMarket.idl
Parsing SimpleStocks\StockMarket.idl
Parsing C:\java\jdk1.4\lib\orb.idl
Parsing C:\java\jdk1.4\lib\ir.idl
done - C:\java\jdk1.4\lib\ir.idl
done - C:\java\jdk1.4\lib\orb.idl
done - SimpleStocks\StockMarket.idl

Generating SimpleStocks
done - SimpleStocks

C:\MyProjects\Cornucopia\iiop>

3. Compile the CORBA Client

Command Prompt
C:\MyProjects\Cornucopia\iiop>javac -classpath .;.\CorbaClient .\CorbaClient\CorbaClient.java

C:\MyProjects\Cornucopia\iiop>

4. Make sure that the Servers are running and startup the client

Make sure that the Servers are up. If they are not, start them up using the following commands.

Command Prompt
C:\MyProjects\Cornucopia\iiop>start tnameserv -ORBInitialPort 1000

C:\MyProjects\Cornucopia\iiop>
start java -classpath . StockMarketServer

C:\MyProjects\Cornucopia\iiop>

The screen shot below shows the COS Naming Services Server up and running.

The screen shot below shows our RMI Server up and running across Client invocations

Startup the Client as shown below, and invoke operations on the Server.

Command Prompt
C:\MyProjects\Cornucopia\iiop>java -classpath .;.\CorbaClient CorbaClient.CorbaClient -ORBInitialPort 1000
The ORB has been created and initialized ...
The Object Reference has been resolved in Naming ...
The price of MY COMPANY is 159.2

C:\MyProjects\Cornucopia\iiop>

 

Java/RMI
Java/RMI - Under The Hood
Developing a Java/RMI Server using JRMP
Developing a Java/RMI Client using JRMP
Developing a Java/RMI Server Component using IIOP
Developing a Java/RMI Client to our RMI/IIOP Server Component
Developing a CORBA Client to our RMI/IIOP Server Component

 

Download the entire source code as a zip file.

 

click here to go to
My Advanced Java/J2EE Tutorial Page...

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He has co-authored a number of books including "Professional JMS", "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia site (http://gsraj.tripod.com/) or mail him at gopalan@gmx.net.

 


Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited  times since January 13, 2002.

Last Updated : Jan 13, '02

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2002, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.