dev@glassfish.java.net

[Bug] NameNotFoundException is occured when use the relative path to lookup

From: Meng XiaoLong <mxlong_at_cn.fujitsu.com>
Date: Thu, 23 Dec 2010 13:55:45 +0800

GlassFish Dev Team,

Hello everybody.

Sorry for interrupting you.

I am from Fujitsu China. I found a bug when I test JNDI Service's lookup
method.

#Scene 1 [NameNotFoundException occured]
==========================================================
Specify 'endpoints' property in client application, then use the
relative path to lookup EJB application. when execute the 2nd lookup
method, NameNotFoundException is throwed.

client source:
----------src start-----------
System.setProperty("com.sun.appserv.iiop.endpoints", "localhost:3700");
System.out.println("==========>start: ");
Context ctx = new InitialContext();
System.out.println("begin: ");
WorkerRemote wr = null;
Context ctx2 = (Context) ctx.lookup("ejb");
wr = (WorkerRemote) ctx2.lookup("worker01"); //NameNotFoundException
// wr = (WorkerRemote) ctx.lookup("ejb/worker01");
System.out.println(wr.work());
----------src end-----------
===Exception info===
Exception in thread "main" javax.naming.NameNotFoundException: ejb not found
at
com.sun.enterprise.naming.TransientContext.resolveContext(TransientContext.java:268)
at
com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:191)
at
com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:192)
at
com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
at
com.sun.enterprise.naming.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:129)
==========================================================


#Scene 2 [NameNotFoundException is not occurred]
==========================================================
Do not specify 'endpoints' property in client application, use the
relative path to lookup EJB application. In this scene, can lookup the
object correctly without NameNotFoundException.

client source:
----------src start-----------
System.out.println("==========>start: ");
Context ctx = new InitialContext();
System.out.println("begin: ");
WorkerRemote wr = null;
Context ctx2 = (Context) ctx.lookup("ejb");
wr = (WorkerRemote) ctx2.lookup("worker01");
// wr = (WorkerRemote) ctx.lookup("ejb/worker01");
System.out.println(wr.work()); 
----------src end-----------
==========================================================

About client source and EJB application, Please refer to the attached file.

==howto fix==
In SerialContext class's lookup method, before
javax.naming.spi.NamingManager.getObjectInstance(), executing
resetSticky().
---
if(obj instanceof Context) {
      resetSticky();
      return new SerialContext(name, myEnv);
}
resetSticky(); //fix the problem.
Object retObj =
      javax.naming.spi.NamingManager.getObjectInstance(obj,
                                       new CompositeName(name),
                                       null, myEnv);
return retObj;
---
However, I donot know whether this can really fix the problem.
Can Anybody answer me the following 2 questions?
Question 1: the purpose of stickyContext.
Question 2: If I changed the processing order whether this can really 
fix the problem?
---
resetSticky(); //fix the problem.
Object retObj =
      javax.naming.spi.NamingManager.getObjectInstance(obj,
                                       new CompositeName(name),
                                       null, myEnv);
return retObj;
---
Best Regard.
Meng XiaoLong