The existing, running CORBA naming service can be accessed through the classes in the org.omg.CosNaming package. You need to obtain the NamingContextExt
. It has methods to iterate through all existing bindings as well as to resolve objects by name.
When you start a tnameserv
tool, it prints for you IOR - this is CORBA URL. You can get the CORBA object (name service including) from any ORB in the world if it is accessible through network and you supply the IOR:
public static void main(String args[]) throws Exception {
ORB orb = ORB.init(args, null);
// pass the IOR as command line parameter for this program
String ior = args[0];
org.omg.CORBA.Object objRef = orb.string_to_object(ior);
NamingContextExt nameService = NamingContextExtHelper.narrow(objRef);
// Now you can work with your naming service.
}
See here for tutorial on how to access CORBA objects and here on how to work with naming service.
The orb.resolve_initial_references("NameService")
by default (if not configured) returns the local service on the running virtual machine and you need to query the external one. To use this, you need to pass the correct configuration properties (second parameter that is null in my example) with the ORBInitRef.NameService property set to the address of your name service, as described here. Many (or most of) production environments have this property set so that this method returns the correct remote name service.
servertool is a command line tool that allows to list the registered CORBA objects without writing Java code. You need to specify on which host the name service of interest is running. servertool will not complain if the service is running at the given host and port. It should complain if it does not find one!
Most important, your CORBA object must register with the obtained name service by calling
nameService.bind(yourName, yourCORBAObject);
In case the name service is remote, this will send the network message containing the URL of your orb and reference to your object. If your do not register your object, of course the reference will not be available there and the servertool will show you an empty list, just as you complain.