+

Search Tips   |   Advanced Search

Example: Looking up an EJB home with CosNaming

We can look up an EJB home or other CORBA object from a WebSphere Application Server name server through the CORBA CosNaming interface.

We can invoke resolve or resolve_str on the initial context, or we can invoke string_to_object on the ORB. 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 namespace to the specified server root context.)


Qualified and unqualified names

Each application server 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 namespace 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 containing the object.

We can define fixed qualified names for objects. With qualified names, we can look up objects residing on different servers from the same initial context by traversing the system namespace structure. Alternatively, we can use an unqualified name, but an unqualified name will only resolve using the name server associated with the object's application server.


CosNaming.resolve (and resolve_str) vs. ORB.string_to_object

If we have an initial context from any name server in a WAS cell, we can look up any CORBA object with a qualified name. We do not need additional host and port information for the target object's name server.

Alternatively, we 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 running in a single server. The enterprise bean being used looked up is running in the server, MyServer, on the node, Node1.

// 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/Node1/servers/MyServer/mycompany/accounting/AccountEJB");
accountHome =
  (AccountHome)javax.rmi.PortableRemoteObject.narrow(ejbHome, AccountHome.class);


Server cluster

The following example shows a lookup of an EJB home 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.

// 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/mycompany/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 containing the object, the system namespace does not need to be traversed, and we 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, we can use the default key of NameService.

Lookup of an EJB home. The enterprise bean being used looked up is bound on the name server running on the host myHost on port 2809. Note the object key of NameServiceServerRoot.

// 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#mycompany/accounting");
accountHome =
    (AccountHome)javax.rmi.PortableRemoteObject.narrow(ejbHome, AccountHome.class);

  • Developing applications that use CosNaming (CORBA Naming interface)
  • Lookup names support in deployment descriptors and thin clients