JNDI overview in the WebLogic server
In a business, naming services provide a way for your application to locate on the network. A naming service is in touch with the object and the name and can find the corresponding object by the name specified by them. (RMI registration is a good example of naming service.)
Java Names and Directory Interface (JNDI) is an application programming interface (API) that provides a naming service for Java applications. JNDI is a complete component in the J2EE technology of the Sun micro system. It supports methods of accessing different new and existing services through a single way. This support allows any service providers to perform JNDI frameworks through the Standard Service Provider Interface (SPI). In addition, JNDI allows Java applications on WebLogic servers to access the appropriate service providers to an external directory service such as LDAP.
WEBLOGIC Server Executes JNDI Methods include:
l Allows the client to access the WebLogic naming service.
l Make an object valid in WebLogic namespace.
l Refers the object from the WebLogic namespace.
Each WebLogic server cluster is supported by a replicated cluster range, and this JNDI tree provides an intersection that enters each replicated RMI and EJB object. When the JNDI tree representing the cluster is now in the client, the tree containing the cluster range service is actually a WebLogic server intersect in the cluster. For more information, see "WebLogic JNDI in the cluster environment".
The complete naming service provided by WebLogic Server JNDI can be used in many other WebLogic services. For example, WebLogic RMI can bind and access remote objects through standard RMI methods and JNDI methods.
In addition, the WebLogic server provides its implementation for JNDI's standard Java interface, namely WebLogic.jndi, WLinitialContextFactory uses a standard JNDI interface. In your application code, you don't need to instantiate this class directly. Instead, you can use the standard Javax.naming.initialContext class, and set the appropriate Haxi property, like "Environment Properties for Initialization Context Set JNDI". As described in JNDI's Javadoc, all interactions are done through javax.naming.context interface.
WebLogic JNDI programming
l The following sections describe WebLogic JNDI programming, including:
l Use WebLogic JNDI through the Java client
l Sets JNDI's environmental properties for the initialization context
l Find name objects with context
l Get the reference to the object with a named object
l Close the context
l Use WebLogic JNDI in the cluster environment
l
Use WebLogic JNDI through the Java client
The JNDI Service Provider Interface (SPI) of the WebLogic server provides an initialContext implementation that allows the remote Java client to connect to the WebLogic server. The client can specify a standard JNDI environment property to determine a special WebLogic server deployment and the connection properties associated with the WEBLOGIC server.
In order to make the WebLogic server participate in a session, a Java client must be able to get a reference to the remote object, and can call the corresponding operations on this object. In order to achieve this, the client application code must complete the following steps:
1. Set the JNDI environment properties for the initialization context.
2. Create an initialization context on the WebLogic server.
3. Use this context to look up a named object at the namespace of the WebLogic server. 4. Use this named object to get a reference for the remote object and call the appropriate operation on this remote object.
5. Complete this session.
The next section discusses the work to connect to a WebLogic server and the JNDI client. For information on using JDNI in a WebLogic server cluster, see "WebLogic JNDI from the Cluster Environment".
Before you access an object with JNDI in a WebLogic server environment, you must load this object into the JNDI tree of the WebLogic server. Please refer to "Management JNDI" in the JNDI tree.
To initialize the context setting JNDI's environmental properties
The first task that the Java client application must perform is to create environment properties. Initializing the context factory uses different properties to customize its context. You can also use the Haxi table or use the set () method to set these properties. These names and values correspond to the attribute determine how WLinitialContextFactory creates context.
Use the following properties when the initialization context is in the form:
l Context.Provider_URL ---- Determine the URL of the WebLogic server that provides a naming service. The default is T3: // localhost: 7001.
l Context.Security_Principal ---- Determines the identity of the user (ie user defined in the WebLogic server security domain) for the purpose of the authentication. This property is a guest user unless this thread has been associated with the WebLogic server user. For more information, see "Connection with a WebLogic user with a WebLogic user".
You can use the same properties on the client and the server. If you define this property on the server-side object, use the local context. If you define this property on the client or other WebLogic server, this context represents a remote context that runs on the WebLogic server determined by the Context.Provider_URL property.
The following code shows how to use these two to get context:
CONTEXT CTX = NULL;
Hashtable ht = new hashtable ();
Ht.put (Context.Initial_Context_Factory,
"WebLogic.jndi.wlinitialContextFactory");
HT.PUT (Context.Provider_URL,
"T3: // LocalHost: 7001");
Try {
CTX = New InitialContext (HT);
// use the context in your program
}
Catch (namingexception e) {
// a failure occurred
}
Finally {
Try {ctx.close ();
Catch (Exception E) {
// a failure occurred
}
}
Other WebLogic properties are valid for configuring environmental parameters and control how to bind objects to clusters. Note that this binding can be copied for each server in a cluster or no copy of JNDI trees. These attributes are determined by the constants in the WebLogic.jndi.wlconText class. For clusters related to JNDI, see "Use WebLogic JNDI from the cluster environment".