[omniORB] OmniOrb 4.0.1 client to Sun 1.4.1 Server returns nil object (explanation)

Klein, Roy E RKLEI2 at amfam.com
Wed Aug 6 10:15:42 BST 2003


I have set up the echo example on the sun kit along with a client and
all works from pure java. I am using the POA - Tie example but using
your echo program instead of the hello sun demo.
 
I have modified the eg3_clt and have gotten the name servers to talk and
connect but I get a nil client return. I have tried using the
-ORBverifyObjectExistsAndType 0 arg on the command line. I have VC++ 6.0
installed, but have compiled from your echo directory. I am using
windows XP, and have both client and server executing on one box.
 
It appears the object is nil after the narrow request.
 
// eg3_clt.cc - This is the source code of example 3 used in Chapter 2
//              "The Basics" of the omniORB user guide.
//
//              This is the client. It uses the COSS naming service
//              to obtain the object reference.
//
// Usage: eg3_clt
//
//
//        On startup, the client lookup the object reference from the
//        COS naming service.
//
//        The name which the object is bound to is as follows:
//              root  [context]
//               |
//              text  [context] kind [my_context]
//               |
//              Echo  [object]  kind [Object]
//
 
#include <iostream.h>
#include <echo.hh>
 
static CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb);
 
static void hello(Echo_ptr e)
{
  if( CORBA::is_nil(e) ) {
    cerr << "hello: The object reference is nil!\n" << endl;
    return;
  }
 
  CORBA::String_var src = (const char*) "Hello!";
 
  CORBA::String_var dest = e->echoString(src);
 
  cerr << "I said, \"" << (char*)src << "\"." << endl
       << "The Echo object replied, \"" << (char*)dest <<"\"." << endl;
}
 
//////////////////////////////////////////////////////////////////////
 
int
main (int argc, char **argv)
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
 
    CORBA::Object_var obj = getObjectReference(orb);
 
    Echo_var echoref = Echo::_narrow(obj);
 
    for (CORBA::ULong count=0; count < 10; count++)
      hello(echoref);
 
    orb->destroy();
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact
the "
         << "object." << endl;
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught CORBA::SystemException." << endl;
  }
  catch(CORBA::Exception&) {
    cerr << "Caught CORBA::Exception." << endl;
  }
  catch(omniORB::fatalException& fe) {
    cerr << "Caught omniORB::fatalException:" << endl;
    cerr << "  file: " << fe.file() << endl;
    cerr << "  line: " << fe.line() << endl;
    cerr << "  mesg: " << fe.errmsg() << endl;
  }
  catch(...) {
    cerr << "Caught unknown exception." << endl;
  }
 
  return 0;
}
 
//////////////////////////////////////////////////////////////////////
 
static CORBA::Object_ptr
getObjectReference(CORBA::ORB_ptr orb)
{
  CosNaming::NamingContext_var rootContext;
 
  try {
    // Obtain a reference to the root context of the Name service:
    CORBA::Object_var obj;
    obj = orb->resolve_initial_references("NameService");
 
    // Narrow the reference returned.
    rootContext = CosNaming::NamingContext::_narrow(obj);
    if( CORBA::is_nil(rootContext) ) {
      cerr << "Failed to narrow the root naming context." << endl;
      return CORBA::Object::_nil();
    }
  }
  catch(CORBA::ORB::InvalidName& ex) {
    // This should not happen!
    cerr << "Service required is invalid [does not exist]." << endl;
    return CORBA::Object::_nil();
  }
 
  // Create a name object, containing the name test/context:
  CosNaming::Name name;
  name.length(1);
 
//  name[0].id   = (const char*) "test";       // string copied
//  name[0].kind = (const char*) "my_context"; // string copied
//  name[1].id   = (const char*) "Echo";
//  name[1].kind = (const char*) "Object";
  name[0].id   = (const char*) "Echo";
  name[0].kind = (const char*) "";
  // Note on kind: The kind field is used to indicate the type
  // of the object. This is to avoid conventions such as that used
  // by files (name.type -- e.g. test.ps = postscript etc.)
 

  try {
    // Resolve the name to an object reference.
    cerr << "Context not found." << endl;
    return rootContext->resolve(name);
  }
  catch(CosNaming::NamingContext::NotFound& ex) {
    // This exception is thrown if any of the components of the
    // path [contexts or the object] aren't found:
    cerr << "Context not found." << endl;
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact
the "
         << "naming service." << endl;
  }
  catch(CORBA::SystemException&) {
    cerr << "Caught a CORBA::SystemException while using the naming
service."
  << endl;
  }
 
  return CORBA::Object::_nil();
}

 
--
 
Cheers,
 
You can have it fast, cheap and good, but you only get to pick 2.
 
(608) 242-4100 x32610
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20030806/99c2915c/attachment.htm


More information about the omniORB-list mailing list