Solved

"jAVA:env/comp" JNDI lookups in Websphere 6.0.1

Posted on 2006-11-27
3
14,126 Views
Last Modified: 2013-12-10
Hi,
I am using websphere version 6 .0.1 am quite new to websphere. For JNDI lookups i give the full path example "ejb/test/someEJB" this works fine and i am able to run my small application. As soon as i append "java:env/comp" in front of the name websphere gives Namenot FoundException . It complains about java: not being set.
What is it that i need to do to make java: lookups.

2. How can i do lookups on environment variables defined in the web app. For example i want to store class name against a key as environment variable . I want to do a JNDI lookup and get the class instance.What server configuration is required to achieve it.

Thanks in advance to anyone who can enlighten me on this issue.
0
Comment
Question by:AMIT_SOOD
  • 2
3 Comments
 
LVL 10

Expert Comment

by:ECollin
ID: 18053159
hi,

Do you make these lookups from inside your web application ?

If you want to create environment entries in your web application and acces to them from your java code :
déclaration for your variable in the web.xml file :
<env-entry>
<description>welcome message</description>
<env-entry-name>greetings</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Welcome to the Inventory Control System</env-entry-value>
</env-entry>

java code :
javax.naming.Context ctx =
new javax.naming.InitialContext();
javax.naming.Context env =
ctx.lookup("java:comp/env");

// obtain the greetings message
//configured by the deployer
String str = (String) env.lookup("greetings");

2. If you want to obtain a reference to your ejb via an "indirection" use this :
in the web.xml :
<ejb-ref id="EjbRef_02">
   <ejb-ref-name>ejb/DualEntityRemoteHome</ejb-ref-name>
   <ejb-ref-type>Entity</ejb-ref-type>
   <home>dual.ejb.DualEntityRemoteHome</home>
   <remote>dual.ejb.DualEntityRemote</remote>
   <ejb-link>DualEJBModule01.jar#DualEntity</ejb-link>
</ejb-ref>
<ejb-local-ref id="EJBLocalRef_02">
   <ejb-ref-name>ejb/DualEntityLocalHome</ejb-ref-name>
   <ejb-ref-type>Entity</ejb-ref-type>
   <local-home>dual.ejb.DualEntityLocalHome</local-home>
   <local>dual.ejb.DualEntityLocal</local>
   <ejb-link>DualEJBModule01.jar#DualEntity</ejb-link>
</ejb-local-ref>

the lookup :
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("java:comp/env/ejb/DualEntityLocalHome");
or
DualEntityRemoteHome homeObject = (DualEntityRemoteHome)initCtx.lookup("java:comp/env/ejb/DualEntityRemoteHome");


Emmanuel
0
 

Author Comment

by:AMIT_SOOD
ID: 18058711
Hi Emmanuel,
Thanks for your reply.
I am doing what you just mentioned above but my question is i am not able to do lookups using "java:comp/env" .websphere complains about java not being set. example that you have given
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("java:comp/env/ejb/DualEntityLocalHome"); fails but if i do the samething in the following manner.
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("ejb/DualEntityLocalHome"); it succeeds.that means i can't do the following
javax.naming.Context env =
ctx.lookup("java:comp/env");
So the question is if websphere by default cannot lookup  "java:comp/env" what setting does the server require or in other words how do i configure it.

I hope you will be able to shed light on this issue.

Cheers
Amit Sood
0
 
LVL 10

Accepted Solution

by:
ECollin earned 500 total points
ID: 18059128
hi,

The java:comp/env context is reachable only from inside the web app. A servlet, a jsp or a single java class placed inside the web application can access this context.
A class outside the application (in another jvm for instance) will not be able to.

Emmanuel
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question