Setting the provider URL property to select a different root context as the initial context

Each server contains its own server root context, and, when bootstrapping to a server, the server root is the default initial JNDI context. Most of the time, this default is the desired initial context, since system artifacts such as EJB homes are bound there. However, other root contexts exist, which can contain bindings of interest. It is possible to specify a provider URL to select other root contexts.

 

Selecting the initial root context with a CORBA object URL

There are several object keys registered with the bootstrap server that you can use to select the root context for the initial context. To select a particular root context with a CORBA object URL object key, set the object key to the corresponding value. The default object key is NameService. Using JNDI yields the server root context. A table that lists the different root contexts and their corresponding object key follows:

Root Context CORBA Object URL Object Key
Server Root NameServiceServerRoot
Cell Persistent Root NameServiceCellPersistentRoot
Cell Root NameServiceCellRoot
Node Root NameServiceNodeRoot

The following example shows the use of a corbaloc URL with the object key set to select the cell persistent root context as the initial context.

 

Usage scenario

    
   ...
   import java.util.Hashtable;
   import javax.naming.Context;
   import javax.naming.InitialContext;
   ...
   Hashtable env = new Hashtable();
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
   env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809/NameServiceCellPersistentRoot");
   Context initialContext = new InitialContext(env);
   ...

 

Selecting the initial root context with the name space root property

One can also select the initial root context by passing a name space root property setting to the InitialContext constructor. Generally, the object key setting described above is sufficient. Sometimes a property setting is preferable. For example, you can set the root context property on the Java invocation to make which server root is being used as the initial context transparent to the application . The default server root property setting is defaultroot , which yields the server root context.

Root ContextName Space Root Property Value
Server Root bootstrapserverroot
Cell Persistent Root cellpersistentroot
Cell Root cellroot
Node Root bootstrapnoderoot

The initial context factory ignores the name space root property if the provider URL contains an object key other than NameService .

The following example shows use of the name space root property to select the cell persistent root context as the initial context. Note that available constants are used instead of hardcoding the property name and value.

 

Usage scenario

    
   ...
   import java.util.Hashtable;
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import com.ibm.websphere.naming.PROPS;
   ...
   Hashtable env = new Hashtable();
   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
   env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809");
   env.put(PROPS.NAME_SPACE_ROOT, PROPS.NAME_SPACE_ROOT_CELL_PERSISTENT);
   Context initialContext = new InitialContext(env);
   ...


Developing applications that use JNDI
Initial context support