Hi,
Jay SenSharma

Jay SenSharma

Looks Like a BUG Or Immature Implementation Or Lack of Documentation
In WLS10.3  Remedy is available in the following link:

Here is a Simple demonstration of Binding some informations or Objects in WebLogic Server’s JNDI tree. Many times we want to Bind some sort of environmental informations in the Server JNDI tree sothat the Application deployed on that server can easily look them up and can use them.
When you bind a custom object (a non-RMI object) into a JNDI tree in a WebLogic Server cluster, the object is replicated across all the servers in the cluster. However, if the host server goes down, the custom object is removed from the cluster’s JNDI tree. Custom objects are not replicated unless the custom object is bound again. You need to unbind and rebind a custom object every time you want to propagate changes made to the custom object. Therefore, WebLogic JNDI should not be used as a distributed object cache.
Suppose the custom object needs to be accessed only by EJBs that are deployed on only one WebLogic Server. Obviously it is unnecessary to replicate this custom object throughout all the WebLogic Servers in the cluster. In fact, you should avoid replicating the custom object in order to avoid any performance degradation due to unnecessary server-to-server communication. To create a binding that is not replicated across WebLogic Servers in a cluster, you must specify the REPLICATE_BINDINGS property when creating the context that binds the custom object to the namespace.
Example:
Hashtable ht = new Hashtable();
ht.put(WLContext.REPLICATE_BINDINGS, “false”);

.

Step1). Create a Directory somewhere like “C:JNDI_Demo” and Create a Class there with name “Employee.java” suppose you want to bind the Employee Object in the Server JNDI Tree… Make Sure that the Object is declared as java.io.Serializable sothat it can be used remotely as well.

package pack;
public class Employee implements java.io.Serializable
{
private int empNo;

public Employee()
{
System.out.println("nnt Employee Object Instentiated...With EmpId:0");
}

public Employee(int empNo)
{
System.out.println("nnt Employee Object Instentiated...With EmpId:"+empNo);
}
}
Step2). Compile it and make a Jar of it…like “Employee.jar”.
Making Employee.jar for Binding

Making Employee.jar for Binding

Step3). Make this JAR available in the Server Classpath…or you can paste this Jar in the Domain/Lib directory:

Example: C:bea103user_projectsdomains7001_Domain_Namelib
Pasting Employee.jar in Domain Lib directory

Pasting Employee.jar in Domain Lib directory

Step4). Restart the Server so that it can pick up the Employee.jar from the Classpath or “<DOMAIN_HOME>lib”.

Step5). Inside “C:JNDI_Demo” Write another Program there as a Client “BindingStartUp.java” to Bind this Object in the Server JNDI tree…

import java.rmi.*;
import javax.naming.*;
import java.util.*;
public class BindingStartUp
{
public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private static String serverUrl ="t3://localhost:7001";   (The Server address in which u want to bind the Employee Object)

public static void main(String ar[])throws Exception
{
InitialContext ic=null;
try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, serverUrl);
env.put(Context.SECURITY_PRINCIPAL,"weblogic");
env.put(Context.SECURITY_CREDENTIALS,"weblogic");
ic = new InitialContext(env);
}
catch(Exception e){
System.out.println("nnt Unable To Get The InitialContext => "+e);
}

try{
pack.Employee emp=new pack.Employee(1000);
ic.rebind("EmpJndiName",emp);
System.out.println("nnt Employee Object Binded in the JNDI Tree Of Server Suuccessfully");
System.out.println("nnt You can use (pack.Emp)ic.lookup("EmpJndiName");");
System.out.println("t To Lookup the Employee Object from the JNDI Tree");
}
catch(Exception e)
{
System.out.println("nnt Unable To Bind => "+e);
e.printStackTrace();
}
}
}
Step6). Now as soon as you run this Client Program it will,Bind this Employee Object in the Server JNDI tree…You can verify it from the AdminConsole—>JNDITree section
Binding Employee Object In JNDI Tree

Binding Employee Object In JNDI Tree

Home >Summary of Servers >AdminServer—>View JNDI Tree (click this link)
AdminServer JNDI Tree

AdminServer JNDI Tree

Step7). Now u can write the Smilar code …to Lookup the Object from JNDI tree….

You can use (pack.Emp)ic.lookup(“EmpJndiName”);

NOTE: as soon as you start the Server next time you wont be able to see the Employee Object in the JNDI tree of the Server…you need to bind that object again after starting the server everyting.

To avoid this problem … If you want that as soon as your server comes into the Running mode your Desired Object or Information should have binded automatically in the JNDI tree of the Server then you can use the concept of “WebLogic StartUp and Shutdown classes”.
==============================================================
SOME WLS JNDI related Interesting Threads:
.
.
Thanks
Jay SenSharma
If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.