[Prev][Next][Index][Thread]

Re: jdk1.2 client wants to connect to orbix naming service



Hi,

The problem appears to be that NameService reference that you have is
incorrect. Use your Orbixweb IORExplorer to look at the host and port the
client is trying to attach to to find the NameService. Both in the IOR read
from the file and from resolve_initial_references.

Second, in your client pass the following ;

  Properties props = new Properties();
  props.put("org.omg.CORBA.ORBInitialHost", "some hostname");
  props.put("org.omg.CORBA.ORBInitialPort", "some  portnumber");

This will allow the Java 1.2 client to find the Orbixweb Naming Service.

Attached is a complete copy of a test program Java 1.2 client which uses the
Orbixweb NameService to obtain the reference to a server stored in the
context TEST.LEVEL.

William Cummings
Unisys Corp/TeamPRC

*******************************************************

// Name    : SpeakerClient.java
// Author   : William Cummings, Jr
// Company  : Unisys / TeamPRC
// Date    : 01.01.2000
// Description: Client to test SpeakerServer in java  (jdk1.2.2)

package test.dev;

import org.omg.CORBA.SystemException;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.* ;
import org.omg.CORBA.ORBPackage.InvalidName;

import java.io.*;
import java.util.*;

import test.*;


public class SpeakerClient {

  public static void main (String args[]) {
    ORB theOrb                       = null;
    NamingContext rootContext        = null;
    String nameServiceIOR            = "";
    SpeakerFactory speakerFactoryRef = null;

  Properties props = new Properties();
  props.put("org.omg.CORBA.ORBInitialHost", "cummings01");
  props.put("org.omg.CORBA.ORBInitialPort", "1570");

    theOrb = ORB.init (args,props);
    System.out.println("The orb is initialized.");

    /*
     * Get the root context
     */

    // read the nameservice ior from a file.
    String thisLine;
    try {
      FileInputStream fin =  new FileInputStream("c:/test/ior");
      BufferedReader myInput = new BufferedReader(new
InputStreamReader(fin));
      while ((thisLine = myInput.readLine()) != null) {
        System.out.println(thisLine);
        nameServiceIOR = thisLine;
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }

    try {
 /*

     System.out.println("Converting the string reference to object.");
     org.omg.CORBA.Object obj = theOrb.string_to_object(nameServiceIOR);
     System.out.println("Narrowing the object reference to rootContext.");
     rootContext = NamingContextHelper.narrow(obj);
      System.out.println("RootContextIOR " +
theOrb.object_to_string(rootContext));
*/
      rootContext =
NamingContextHelper.narrow(theOrb.resolve_initial_references("NameService"));

    }
    catch (InvalidName ie ) {
     System.out.println("Execption Invalid Name : " + ie.toString());
    }

    catch (SystemException se) {
      System.out.println ("Exception during resolve initial reference to the
Naming Service : " + se.toString());
      System.exit (1);
    }

    System.out.println("Now resolving the TEST.LEVEL.SpeakerServer
context.");

    NameComponent[] name = new NameComponent[3] ;
    org.omg.CORBA.Object objRef = null;

    try {
      /*
       * Resolve name context 'TEST.LEVEL'
       */
      name[0] = new NameComponent ("TEST", "TEST");
      name[1] = new NameComponent ("LEVEL", "LEVEL");
      name[2] = new NameComponent ("SpeakerServer","SpeakerServer");

      objRef = rootContext.resolve (name);

      System.out.println("Completed resolve of TEST.LEVEL.SpeakerServer
context.");

      speakerFactoryRef = SpeakerFactoryHelper.narrow (objRef);
    }

    catch (org.omg.CosNaming.NamingContextPackage.NotFound nf) {
      System.out.println("Now in Exception NotFound");
    }
    catch (org.omg.CosNaming.NamingContextPackage.InvalidName in) {
      System.out.println("Now in Exception InvalidName");
    }
    catch (org.omg.CosNaming.NamingContextPackage.CannotProceed cp) {
      System.out.println("Now in Exception Cannot Proceed");
    }

    String factory_ior = theOrb.object_to_string(speakerFactoryRef);
    System.out.println("SpeakerFactory = " + factory_ior);

    // use the speakerFactoryRef to get a speaker object
    Speaker speakerRef = speakerFactoryRef.getSpeaker();
    System.out.println("Got Speaker!");

    // use the speakerRef to to invoke the speak() operation
    String result = speakerRef.speak("William");
    System.out.println("Result = " + result);
  }
}


Min Tian wrote:

> Hi,
> I am trying to connect my jdk 1.2 client to an orbix naming service,
> using ior file.
>
> The code is as following:
>
> import java.io.*;
>
> import java.util.Properties;
> import org.omg.CORBA.*;
> import org.omg.CosNaming.*;
>
> import UMSException;
> import ConverterMgmt.ConverterHelper;
>
> public class TestJavaIOR {
>
> public static ConverterMgmt.Converter cvRef = null;
>
>     public static void main ( String[] args ) {
>  try {
>      Properties props = new Properties();
>      props.put("org.omg.CORBA.ORBClass","com.sun.CORBA.iiop.ORB");
>      //props.put("org.omg.CORBA.ORB","org.omg.CORBA.ORB");
>      ORB orb = ORB.init(args,props);
>      NamingContext nc;
>      if(args.length>0)
>   {// first arg is the name of the NameService IOR File
>       FileReader fr = new FileReader(args[0]);
>       BufferedReader br = new BufferedReader(fr);
>
>       String nsior = br.readLine();
>       System.out.println("nsior: " + nsior);
>
>       nc     = NamingContextHelper.narrow(orb.string_to_object(nsior)) ;
>
>   }
>      else
>   {// if no argument, try default NameService
>       System.out.println("else!!! -->  ior.txt not used!!");
>
>       nc =
> NamingContextHelper.narrow(orb.resolve_initial_references("NameService"))
> ;
>   }
>
>      System.out.println("NameComponent********:");
>
>      NameComponent [] name = new NameComponent[3];
>      name[0] = new NameComponent("UMS", "");
>      name[1] = new NameComponent("Configuration", "");
>      name[2] = new NameComponent("Converter", "");
>
>      System.out.println("******NameComponent: "+ name);
>
>     //error occurs here:
>      org.omg.CORBA.Object obj = nc.resolve(name) ;
>      System.out.println("obj:" + obj);
>
>      cvRef = ConverterMgmt.ConverterHelper.narrow(obj);
>
>      System.out.println("Converter Reference:" +cvRef);
>  }
>  catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
>      e.printStackTrace(System.err);
>
>      System.err.println("org.omg.CosNaming.NamingContextPackage.NotFound
> (uli): "+ e.why.value());   }
>  catch (Exception e) {
>      e.printStackTrace(System.err);
>  }
>     }
> }
>
> I get following the error from the line "org.omg.CORBA.Object obj =
> nc.resolve(name) ;"
>
> org.omg.CORBA.COMM_FAILURE:   minor code: 1  completed: No
>         at com.sun.CORBA.iiop.ConnectionTable.get(Compiled Code)
>         at com.sun.CORBA.iiop.GIOPImpl.createRequest(Compiled Code)
>         at com.sun.CORBA.iiop.GIOPImpl.createRequest(Compiled Code)
>         at com.sun.CORBA.idl.GenericCORBAClientSC.createRequest(Compiled
> Code)
>         at com.sun.CORBA.idl.RequestImpl.doInvocation(Compiled Code)
>         at com.sun.CORBA.idl.RequestImpl.invoke(Compiled Code)
>         at org.omg.CosNaming._NamingContextStub.resolve(Compiled Code)
>         at TestJavaIOR.main(Compiled Code)
>
> Can someone tell me what is wrong in my code?
> An example code would be also useful.
> Thank a lot in advance
>
> Happy New Year!
>
> Min
>
> pls. mailto:mti@fokus.gmd.de




References: