aspose file tools*
The moose likes Websphere and the fly likes JNDI local context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "JNDI local context" Watch "JNDI local context" New topic
Author

JNDI local context

Anant Kabra
Greenhorn

Joined: Dec 10, 2003
Posts: 5
Hi,
I'm having a problem with JNDI lookups on the local JNDI Context (java:comp/env) in my application.
Ok here is the problem
A method is called in a class. I print out the java:comp/env context bindings in this method, and it shows me all the objects that I expect to be bound to java:comp/env context. Then it calls a method in another class. I again print out the java:comp/env bindings in this method. Here there are no bindings in java:comp/env.
Any ideas why this might happen?
Thanks
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi Anant,
I think, for example, if your SessionBean class A tries and successfully lookup a JDNI context, and then calls methods located in other classes, this lookup will NOT be carry forward to that class, you need to look it up again in that class.
If you want the class notifies the JNDI context, you can pass the context to that class, and see whether it is bind.
Nick.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
The bindings are carried along with the thread. If you spin off another thread it could cause this to happen.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Anant Kabra
Greenhorn

Joined: Dec 10, 2003
Posts: 5
Ok but the resources are defined in the web.xml file as <resource-ref>s so I would think that these would be available to all threads?
Also how does this work with EJBs? If the resource is defined in the ejb-jar.xml file, is this resource available to the ejb's as well as the methods on other classes that the ejb invokes?
For example lets take the following scenario.
Res1 -> JMS Queue
EJB1 -> defines Res1 in ejb-jar.xml
IntClass1 -> class contained in EJB1-ejb.jar
ExtLib1 -> contains ExtClass1
EJB2 -> another EJB that does not have Res1 defined
EJB1 calles method on IntClass1.. is Res1 available to method?
EJB1 calles method on ExtClass1.. is Res1 available to method?
EJB1 looks up EJB2 and calles method on EJB2.. is Res1 available to method?
Thanks,
-- Anant
Gary Craig
Author
Greenhorn

Joined: Aug 10, 2001
Posts: 16
Please indicate how you are trying to access local reference in each method. My assumption is you are doing a lookup(java:comp/env/...) in each case. Are you "building" an Initial context in each case or are you reusing a common Context?
It is the Context that either has a reference bound (at runtime) or not.


Gary Craig,<br />Author of <a href="http://www.amazon.com/exec/obidos/tg/detail/-/032118579X/qid=1060361076/sr=1-11/ref=sr_1_11/102-0063041-4226517?v=glance&s=books" target="_blank" rel="nofollow">Enterprise Java (tm) Programming with IBM Websphere, 2nd edition</a><br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182116/qid=1060361262/sr=1-30/ref=sr_1_30/102-0063041-4226517?v=glance&s=books" target="_blank" rel="nofollow">Introduction to Web Application Development with IBM Websphere Studio (Certification Guide, Test 285)</a>
Anant Kabra
Greenhorn

Joined: Dec 10, 2003
Posts: 5
I am using java:comp/env to do the lookup
Also I'm building the initial context each time.
Thanks,
-- Anant
Daniel Berg
author
Greenhorn

Joined: Jan 22, 2004
Posts: 5
It would be wise to cache the InitialContext within the Application (you could use a utility JAR service locator approach). This would allow you to use the same context for all clients and it will improve performance because you are not constantly creating the same InitialContext.
Dan
Co-Author of "Enterprise Java (tm) Programming with IBM Websphere, 2nd Edition".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI local context
 
Similar Threads
WebSphere Application Developer v4.0 JNDI Lookups
@Resource injection problem with JNDI
resin-web.xml
java:comp/env questions / doubts
linking webapp with ejb in ear