Look up an EJB home with CosNaming
You can look up an EJB home or other CORBA object from a WebSphere Application Server name server through the CORBA CosNaming interface. You can invoke resolve or resolve_str on the initial context, or you can invoke string_to_object on the ORB. You can use a qualified name so that the name resolves regardless of which name server the lookup is executed on, or use an unqualified name that only resolves from the server root context on the name server that actually contains the object binding. (The qualified name traverses the federated system name space to the specified server root context.)
Qualified and unqualified names
Each appserver contains a name server. System artifacts such as EJB homes are bound in that name server. The various name servers are federated by means of a system name space structure. The recommended way to look up objects on different servers is to use a qualified name. A qualified name can be a topology-based name, based on the name of the cluster or single server and node that contains the object. You can define fixed qualified names for objects. With qualified names, you can look up objects residing on different servers from the same initial context by traversing the system name space structure. Alternatively, you can use an unqualified name, but an unqualified name will only resolve using the name server associated with the object's appserver.
CosNaming.resolve (and resolve_str) vs. ORB.string_to_object
If you have an initial context from any name server in a WebSphere Application Server cell, you can look up any CORBA object with a qualified name. You do not need additional host and port information for the target object's name server.
Alternatively, you can look up an object by invoking string_to_object on the ORB, passing in a corbaname URL. Typically, an IIOP type URL is specified, so the bootstrap address information required for an initial context must be contained in the URL. Use a qualified or unqualified stringified name, but an unqualifed name resolves only if the initial context is from the name server in which the object is bound.
The following examples show CosNaming resolve operations using qualified topology-based lookup names and an unqualified lookup name.
CosNaming resolve operation using a qualified name
The topology-based qualified name for an object depends on whether the object is bound in a single server or a server cluster. Examples of each follow.
Single Server
The following example shows the lookup of an EJB home that is running in a single server. The enterprise bean that is being looked up is running in the server, servername, on the node, nodename
// Get the initial context as shown in the previous example // Using the form of lookup name below, it doesn't matter which // server in the cell is used to obtain the initial context. ... // Look up the home interface using the name under which the EJB home is bound org.omg.CORBA.Object ejbHome = initialContext.resolve_str( "cell/nodes/nodename/servers/servername/companyname/accounting/AccountEJB"); accountHome = (AccountHome)javax.rmi.PortableRemoteObject.narrow(ejbHome, AccountHome.class);
Server Cluster
The following example shows a lookup of an EJB home that is running in a cluster. The enterprise bean being that is looked up is running in the cluster, Cluster1. The name can be resolved if any of the cluster members is running.
Usage scenario
// Get the initial context as shown in the previous example // Using the form of lookup name below, it doesn't matter which // server in the cell is used to obtain the initial context. ... // Look up the home interface using the name under which the EJB home is bound org.omg.CORBA.Object ejbHome = initialContext.resolve_str( "cell/clusters/Cluster1/companyname/accounting/AccountEJB"); accountHome = (AccountHome)javax.rmi.PortableRemoteObject.narrow(ejbHome, AccountHome.class);
ORB string_to_object operation using an unqualified stringified name
If the resolve operation is being performed on the name server that contains the object, the system name space does not need to be traversed, and you can use an unqualified lookup name. Note that this name does not resolve on other name servers. If an unqualified name is provided, the object key must be NameServiceServerRoot so that the correct initial context is selected. If a qualified name is provided, you can use the default key of NameService.
The following example shows a lookup of an EJB home. The enterprise bean that is being looked up is bound on the name server running on the host myHost on port 2809. Note the object key of NameServiceServerRoot.
Usage scenario
// Assume orb is an existing ORB instance ... // Look up the home interface using the name under which the EJB home is bound org.omg.CORBA.Object ejbHome = orb.string_to_object( "corbaname:iiop:myHost:2809/NameServiceServerRoot#companyname/accounting"); accountHome = (AccountHome)javax.rmi.PortableRemoteObject.narrow(ejbHome, AccountHome.class);