Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to do a jndi lookup. Getting Exception

 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have project srtucture like this

MAIN_EAR
--WEBPROJECT WAR
--- SOURCE JAR

(In s"SOURCE" I had a program where I was calling all webservice proxies defined in "WEBPROJECT" web.xml. But the day I wrote a thread there and tried to call these from the thread, it all stopped with a very clear message. Obviously I tried to use commonj.timers.TimerManager, resolve this problem. Unfortunaltey I am getting stuck in exceptions)

a) Code Snippet which threw the exception

InitialContext icReloadAll = new InitialContext();
TimerManager reloadAllTmMgr = (TimerManager)icReloadAll.lookup("java:comp/env/timer/ReloadAllCachesTimer");

b) The exception

W NMSV0605W: A Reference object looked up from the context "java:" with the name "comp/env/timer/ReloadAllCachesTimer" was sent to the JNDI Naming Manager and an exception resulted. Reference data follows:
Reference Factory Class Name: com.ibm.ws.util.ResRefJndiLookupObjectFactory
Reference Factory Class Location URLs: <null>
Reference Class Name: java.lang.Object
Type: ResRefJndiLookupInfo
Content: com.ibm.ws.util.ResRefJndiLookupInfo@6997a762 ResRefJndiLookupInfo: Look up Name="timer/ReloadAllCachesTimer";JndiLookupInfo: jndiName="timer/ReloadAllCachesTimer"; providerURL=""; initialContextFactory=""

Exception data follows:
javax.naming.NameNotFoundException: Context: INDOFF405024Node02Cell/nodes/INDOFF405024Node02/servers/server1, name: timer/ReloadAllCachesTimer: First component in name timer/ReloadAllCachesTimer not found. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDLmg.org/CosNaming/NamingContext/NotFound:1.0

c) Relevant web.xml snippet

<resource-ref id="ResourceRef_11111111112">
<res-ref-name>timer/ReloadAllCachesTimer</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

d) Relevant ibm-web-bnd.xmi snippet

<resRefBindings xmi:id="ResourceRefBinding_11111111112"
jndiName="timer/ReloadAllCachesTimer">
<bindingResourceRef
href="WEB-INF/web.xml#ResourceRef_11111111112" />
</resRefBindings>

e) Relevant ibm-web-ext.xmi snippet

<resourceRefExtensions xmi:id="ResourceRefBinding_11111111112">
<resourceRef href="WEB-INF/web.xml#ResourceRef_11111111112"/>
</resourceRefExtensions>

(I didnt write on ibm-web-ext.xmi at the first go. But as I was trying all avenues, I added this part later too, but without luck though)



I must be doing something very stupid, or mistypes something? Please help !!
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java:comp/env/timer/ReloadAllCachesTimer"

What is this name??? Is this is jndi name of ejb? or somthing else?
Go to server console and check if anything is deployed with this jndi name.

 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not in server ! It's TimerManager class I need to call through jndi reference. I checked with all IBM/BEA guidelines, none says anything about the server settings.

One such guideline document is as below

http://xml.coverpages.org/IBM-BEA-TimerV10.doc
 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the commonj source package in both WebProject war and source project jar
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Timer for Application Servers specification provides a timer service API for use within managed environments on the JavaTM platform, such as Servlets, EJBs, and JCA Resource Adapters. The Timer API enables applications to schedule future timer notifications and receive timer notification callbacks to an application-specified listener.


That is the first paragraph of the guide. So, you must use this code inside any of the above specified.

And you have to add this thing in deployment descriptor



 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to elaborate a bit.

I am running this code (jndi lookup) from a singleton class which in turn is instantiated and run from "StartupServlet"

StartupServlet -> StartupManager (singleton) -> lookup (TimerManager)

And I did add the required entries in web.xml. (given above in my first post). And all in ibm-web-bnd.xmi and ibm-web-ext.xmi

So what wrong did I do?

 
Deepak Pant
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you solved this issue? If not I can try to help you out. Please specify the WAS version.
 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope..still groping for an answer.

I have made a simplest test.

TestServlet (load on startup 1)

public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();

System.out.println("Helllo............");
try {
InitialContext ctx = new InitialContext();
TimerManager mgr = (TimerManager)ctx.lookup("java:comp/env/timer/mytimer");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

web.xml

<resource-ref id="ResourceRef_1285669031941">
<res-ref-name>timer/mytimer</res-ref-name>
<res-type>commonj.timers.TimerManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

ibm-web-bnd.xmi

<resRefBindings xmi:id="ResourceRefBinding_1285669031941" jndiName="timer/mytimer">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1285669031941"/>
</resRefBindings>


as you can see, everything I did this time is with help RAD, from adding a servlet to adding reference, I created it through IDE. no handwritten part this except those few lines in init method of the servlet.

RAD also checked that commonj.timers.TimerManager is not a broken link.(give a wrong path, and it will complain)

But still I am getting this Exception


[9/28/10 17:29:38:063 IST] 00000013 Helpers W NMSV0605W: A Reference object looked up from the context "java:" with the name "comp/env/timer/mytimer" was sent to the JNDI Naming Manager and an exception resulted. Reference data follows:
Reference Factory Class Name: com.ibm.ws.util.ResRefJndiLookupObjectFactory
Reference Factory Class Location URLs: <null>
Reference Class Name: java.lang.Object
Type: ResRefJndiLookupInfo
Content: com.ibm.ws.util.ResRefJndiLookupInfo@608799d1 ResRefJndiLookupInfo: Look up Name="timer/mytimer";JndiLookupInfo: jndiName="timer/mytimer"; providerURL=""; initialContextFactory=""

Exception data follows:
javax.naming.NameNotFoundException: Context: CSCINDAF405024Node02Cell/nodes/CSCINDAF405024Node02/servers/server1, name: timer/mytimer: First component in name timer/mytimer not found. Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDLmg.org/CosNaming/NamingContext/NotFound:1.0
at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.handleNameNotFound(WsnOptimizedNamingImpl.java:2252)
at com.ibm.ws.naming.ipcos.WsnOptimizedNamingImpl.getNextWsnOptimizedNamingContext(WsnOptimizedNamingImpl.java:1448)
at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.getTargetContext(WsnOptimizedNamingImplBase.java:4396)
at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase$LeafOperationData.<init>(WsnOptimizedNamingImplBase.java:5012)
at com.ibm.ws.naming.cosbase.WsnOptimizedNamingImplBase.resolve_complete_info(WsnOptimizedNamingImplBase.java:2205)
at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(Unknown Source)
at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:4043)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1746)
at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1707)
at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1412)
at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory$1.run(IndirectJndiLookupObjectFactory.java:372)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java(Compiled Code))
at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstanceExt(IndirectJndiLookupObjectFactory.java:221)
at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstance(IndirectJndiLookupObjectFactory.java:149)
at com.ibm.ws.util.ResRefJndiLookupObjectFactory.getObjectInstance(ResRefJndiLookupObjectFactory.java:138)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:314)
at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:894)
at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:191)
at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:403)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1280)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:201)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:142)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at com.nil.TestServlet.init(TestServlet.java:48)

 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RAD 7.0 with WebSphere 6.0 server environment
 
Nilabhra Banerjee
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got the solution from IBM WebSphere Forum.

Thanks to RoyCCC for providing the solution.

Apart from all these I have to also create an asynchronous been for TImer Manager with required thread count.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic