[omniORB] Java & omniORB

Rosimildo DaSilva rdasilva@connecttel.com
Wed, 21 Jul 1999 22:34:49 -0500


First,
Do not post in HTML. Some people might not be able to read your post.

I am preparing some examples to show java/omniORB integration,
add them to my web site, but they're not  quite ready yet....

Below you have a java client example to talk to the "Echo"  implementation,
i.e.  eg3_impl.exe.
You need to compile echo.idl using  idltojava, and them compile all java
generated files.

Have fun.
Rosimildo.


////////////////////////////////////////////////////////////////////////////
/
// $Header: d:/archive/EchoClient.javav 1.1 1999/07/22 02:25:32 rps Exp $
//
// Copyright (c) 1999 ConnectTel, Inc. All Rights Reserved.
//
// MODULE DESCRIPTION:
// This is an example of a Java Application that implements the "Echo"
// example of the OmniORB2-7.1 ORB.
//
// MODIFICATION/HISTORY:
//
// $Log: EchoClient.javav $
// Revision 1.1  1999/07/22 02:25:32  rps
// Initial revision
//
//
////////////////////////////////////////////////////////////////////////////
/


import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.util.Properties;

/**
 * This class is a client interface to the "echo" example that comes with
the
 * distribution of the omniORB examples.
 */
public class EchoClient
{
    public static void main(String args[])
    {
        try{

            // The lines below are not actually necessary, as long as you
use
   // the default settings for the bostrapping of the Naming Service.
   // But just in case, it does not hurt add them...
            Properties props = new Properties();
   // This line would make sure that the Java 1.2 ORB is going to be used.
            props.put("org.omg.CORBA.ORBClass", "com.sun.CORBA.iiop.ORB");
      // Change this to match with your host address where the
"NamingService"
   // is running.
            props.put("org.omg.CORBA.ORBInitialHost", "rps1");
   // Change this to match with your port number ( Naming Service ).
            props.put("org.omg.CORBA.ORBInitialPort", "6000");
               // create and initialize the ORB
            ORB orb = ORB.init( args, props );
            // get the root naming context
            org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
            NamingContext ncRef = NamingContextHelper.narrow( objRef );
            System.out.println("Naming Service was found successfully..." );
            // resolve the Object Reference in Naming:
   // NOTE: !!!!
   // This has to match with the the same names used by the implementation
   // in C++ ( see omniORB examples. ). If you have not changed them, do
   // not worry about it.
   // THIS IS CASE SENSITIVE. SO, SPELL THEM RIGHT !!!!.
            NameComponent nc1 = new NameComponent( "test", "my_context");
            NameComponent nc = new NameComponent( "Echo", "Object" );
            NameComponent path[] = {nc1, nc};

            System.out.println("About to find Component...." );
            Echo echoRef = EchoHelper.narrow( ncRef.resolve( path ) );

            // call the "ECHO" server object and print results
            String msg;
            String hello;
   int i = 0;
   while( true )
   {
      msg = "Java Client ==>Hello: " + i++;
               hello = echoRef.echoString( msg );
               System.out.println( hello );
      Thread.sleep( 1000 );
   }

        } catch (Exception e) {
            System.out.println("ERROR: " + e) ;
            e.printStackTrace( System.out );
        }
    }
}
////////////////////////////////////////////////////////////////////////////
///////////

Regards, Rosimildo.

+---------------------------------------------------------------------
| ConnectTel, Inc. - Austin, Texas.
| Phone : 512-338-1111 - Fax : 512-918-0449
| Email : devl@connecttel.com  or mkting@connecttel.com
| Site  : http://www.connecttel.com
+---------------------------------------------------------------------