• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

local JNDI lookup

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am using EJB with WSAD 5.0, and get problems while looking up local Beans in the JNDI tree (no problems for access for remote Beans).
The Bean appears in the UTC (Universal Test Client) under [EJB Beans in local]/ejb/myPackage/myBean, and is testable in the Bean page of the UTC.
But I cannot access it through JNDI lookup (using java:comp/env prefix or not), neither with the search engine of the UTC.
Does somebody have an idee about how to let it work ? Would be great, I'm getting of my nerves trying to solve this...
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused. You say you can look it up with the UTC, but you can't look it up in code? Am I understanding you correctly? If that's true, that's probably because your client component where your lookup code runs (either a Session EJB or a Servlet) does not implement a local EJB reference to the EJB. However, you also say you can't look it up in the UTC, which is what is confusing me...
Can you try to explain a bit more clearly what is happening? I'm not exactly sure from your original post.
Kyle
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
some explanations about my trouble :
actually there are two ways of accessing the Beans in the UTC :
- through the JNDI tree, which works correctly
- through a search function, which is the one that doesn't work
I must own up that I am also a bit confused by this error, and hope this helps you,
Theo
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Sorry for the confusion there. Local bean homes cannot be looked up through the search function because they don't have "Real" JNDI names, just local reference id's that are specific to the client that uses them. AFAIK the search function only searches the actual JNDI naming tree.
Kyle
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK,
and how is it possible to get this reference in the client ? should be possible over JNDI, isn't it ? or is there another way to access them ?
thanks,
Theo
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your client component deployment descriptor (either the EJB-JAR.xml file if your client is an EJB, the web.xml if your client is a Servlet or JSP) you must declare a local reference to the EJB (for instance, named something like ejb/YourLocalHomeReference" and then look it up with "java:comp/env/ejb/YourLocalHomeReference".
Kyle
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
There seem to be a problem in the initialization of the local context :
doing so I get an Exception :
'javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:"'
actually the problem seems to be that the server doesn't know of the 'ejb' local context.
the possibility I see is the lack of the JNDI name of CMP container Factory, but it is not needed to access the remote Beans, so why by the local ?
thanks for your help,
Theo
++++++++++++++++
here is the code of the reference (from ibm-ejb-jar-bnd):
<ejbBindings xmi:id="EnterpriseBeanBinding_1070271895609" jndiName="ejb/mich/cmp/FormulaireLocalHome">
<enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#Formulaire"/>
<resRefBindings xmi:id="ResourceRefBinding_1070362283266" jndiName="eis/jdbc/ds1_CMP">
<bindingResourceRef href="META-INF/ejb-jar.xml#ResourceRef_1070362283266"/>
</resRefBindings>
<ejbRefBindings xmi:id="EjbRefBinding_1070273701234" jndiName="ejb/mich/cmp/FormulaireLocalHome">
<bindingEjbRef xmi:type="common:EJBLocalRef" href="META-INF/ejb-jar.xml#EJBLocalRef_1070273701234"/>
</ejbRefBindings>
</ejbBindings>
++++++++++++++++
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I've found out that there is another, less known possibility : the use of 'local:/ejb/ejb/myBean' context. And it works !
thanks for your help,
best regards,
Theo
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JNDI Tutorial glossary defines a compound name and a composite name.
Is java:comp/env/ejb/YourLocalHomeReference is a compound name? I.E. there are not contexts for env, ejb, and comp.
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by theo cocolucci:
Hello,
I've found out that there is another, less known possibility : the use of 'local:/ejb/ejb/myBean' context. And it works !
thanks for your help,
best regards,
Theo


I really don't like using the local: prefix because it's outside the J2EE specification. The accepted way to do this is with java:comp/env.
Kyle
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
so what do you propose if the 'java:comp/env' doesn't work ?
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Theo, I have to go back to the second response I made. What kind of client program are you building? Is your "client" another EJB, a Java application, or a Servlet or JSP? That determines where you put the local EJB reference...
Kyle
 
theo cocolucci
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the client is a java class, actually an Action class of the Struts Framework (that is to say in the same application, but in the Web project).
Theo
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, then the actual "client component" is the Struts Servlet, since that is what kicks things off. So, in the web.xml of your web application you have to add the ejb-local-ref declaration to your EJB. So, for instance, you'd add this to your web.xml:
< ejb-local-ref>
< ejb-ref-name>ejb/myPackage/myBean</ejb-ref-name>
< ejb-ref-type>Session</ejb-ref-type>
< local-home>MyBeanHome</local-home>
< local>MyBean</local>
< ejb-link>MyBean</ejb-link>
< /ejb-local-ref>
There's a good, complete example of a web.xml with ejb-local-ref entries added at the jonas docs page here: http://jonas.objectweb.org/current/doc/PG_WarDeployment.html#Exampl1
Kyle
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kyle,
using the ejb-local-ref assumes that the servlet and ejb containers are running on the same VM. Would your solution still work using the <ejb-ref> tag if they were running on separate VM's?
Also, using the <ejb-ref> or <ejb-local-ref> element eliminates namespace collisions. How would this be solved if the client was not a struts action handler, but instead a standalone java application?

thanks,
Rowan
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, if the EJB is not in the same JVM, you use an ejb-ref, and the EJB you are using must declare a Remote interface.
And yes, the same trick works in application clients. You just add the ejb-ref to the applicationclient.xml file instead of the web.xml file.
Kyle
[ December 06, 2003: Message edited by: Kyle Brown ]
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the web.xml
<ejb-local-ref>
<ejb-ref-name>ejb/SessionEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>ejb.SessionEJBLocalHome</local-home>
<local>ejb.SessionEJBLocal</local>
<ejb-link>SessionEJB</ejb-link>
</ejb-local-ref>


then in the ejb-jar.xml, I have

<session>
<display-name>SessionEJB</display-name>
<ejb-name>SessionEJB</ejb-name>
<local-home>ejb.SessionEJBLocalHome</local-home>
<local>ejb.SessionEJBLocal</local>
<ejb-class>ejb.SessionEJBBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>


the web app and ejb are in separate jaf files (war and jar, not packaged up in ear)....

When I deploy the Web App, it keeps complaining:

weblogic.deployment.EnvironmentException: [J2EE:160101]Error: The ejb-link 'SessionEJB' declared in the ejb-ref or ejb-local-ref 'ejb/SessionEJB' in the application module 'sessio
Test.war' could not be resolved. The target EJB for the ejb-ref could not be found. Please ensure the link is correct.]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic