Example: Get the default initial context

 

+

Search Tips   |   Advanced Search

 

 

There are various ways for a program to get the default initial context.

The following example gets the default initial context.

... import javax.naming.Context; import javax.naming.InitialContext;
...
Context initialContext = new InitialContext();
...

Note that no provider URL is passed to the javax.naming.InitialContext constructor.

The default initial context returned depends the runtime environment of the JNDI client. Following are the initial contexts returned in the various environments:

Thin client

The initial context is the server root context of the server running on the local host at port 2809.

Pure client

The initial context is the context specified by the java.naming.provider.url property passed to launchClient command with the -CCD command line parameter. The context usually is the server root context of the server at the address specified in the URL, although it is possible to construct a corbaname or corbaloc URL which resolves to some other context.

If no provider URL is specified, it is the server root context of the server running on the host and port specified by the -CCproviderURL, or -CCBootstrapHost and -CCBootstrapPort command line parameters. The default host is the local host, and the default port is 2809.

Server process

The initial context is the server root context for that process.

Even though no provider URL is explicitly specified in the above example, the InitialContext constructor might find a provider URL defined in other places that it searches for property settings.

Users of properties which affect ORB initialization should read the rest of this section for a deeper understanding of exactly how initial contexts are obtained.

 

Determining which server is used to obtain the initial context

WAS name servers are CosNaming name servers, and WAS provides a CosNaming JNDI plug-in implementation for JNDI clients to perform naming operations on WAS name spaces. The CosNaming plug-in implementation is selected through a JNDI property that is passed to the InitialContext constructor. This property is java.naming.factory.initial, and it specifies the initial context factory implementation to use to obtain an initial context. The factory returns a javax.naming.Context instance, which is part of its implementation.

The WAS initial context factory, com.ibm.websphere.naming.WsnInitialContextFactory, is typically used by WAS applications to perform JNDI operations. The WAS runtime environment is set up to use this WAS initial context factory if one is not specified explicitly by the JNDI client. When the initial context factory is invoked, an initial context is obtained. The following paragraphs explain how the WAS initial context factory obtains the initial context in client and server environments.




 

Related tasks

Developing applications that use JNDI

 

Related Reference

Initial context support
Example: Getting an initial context by setting the provider URL property