aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3 Local Lookup not working with Weblogic 10.3 and JDK 1.6_05 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3 Local Lookup not working with Weblogic 10.3 and JDK 1.6_05" Watch "EJB 3 Local Lookup not working with Weblogic 10.3 and JDK 1.6_05" New topic
Author

EJB 3 Local Lookup not working with Weblogic 10.3 and JDK 1.6_05

Saurabh Gokhale
Greenhorn

Joined: Dec 07, 2008
Posts: 25
Hi,

I am trying to write a simple stateless EJB 3 with weblogic 10.3 and JDK 1.6_05.

<1> BusinessLogicBean


<2> Local Interface


<3> JNDI


<4> Servlet Code


PROBLEM:
From the servlet I am Not able to lookup this EJB using JNDI (given above). The code fails for NameNotFoundException. (I have try catch in the code, not shown above)
If I change the Interface annotation to Remote, the remote lookup works good. But local lookup is not working.
(For the Remote lookup I am annotating interface as @Remote, removing @Local annotation in the Bean class and adding @Remote annotation with Remote Class name in the bean class.)

Is there anything else I have to do to make local lookup work?

Does any one has working EJB 3 code on Weblogic 10 that I can try to see whats going on?

Thanks
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
Hi Saurabh,

The problem is that weblogic does not make business local interfaces available on the global JNDI tree. This is not specified in EJB 3.0 specification so some vendors make business local interfaces available on the global JNDI tree (e.g. JBoss), while others filter them (e.g. Weblogic).
To access the business local interface you need to define ejb local references for your component environment (i.e. from your servlet environment). You can do this by defining references in your web.xml. For example:

<ejb-local-ref>
<ejb-ref-name>ejb/BusinessLogicBean</ejb-ref-name>
<local>packagename.BusinessLogicBean</local>
</ejb-local-ref>

To lookup your local reference from your servlet you need to use the following JNDI reference:

java:comp/env/ejb/BusinessLogicBean

This problem won't exist with EJB3.1 because global JNDI names are going to be standardized for local and remote references.

Regards,

Manuel
sachin rathore
Greenhorn

Joined: Jan 29, 2010
Posts: 8
Hi,

The solution you gave to make an entry in web.xml works fine if the EJB is accessed from the WAR context. I am trying to access an EJB from another EJB and then it gives me NameNotFoundException.
What and where should be the entry in EJB.jar to make Local EJB's accessible to other EJB's. I tried to make the same entry in weblogic-ejb-jar.xml and it wont let me deploy the EAR. Gives errors for the elements in the deployment descriptor.
Can you please provide me the exact values and entries to be made to which file so that Local EJB is available to another EJB.

Thanks
Sachin
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
I am trying to access an EJB from another EJB
If both ejb's are in the same ear, simplest way is to inject the ejb using @EJB. No explicit JNDI names are needed then - the container handles that for you.


SCJP 5 (98%) - SCBCD 5 (98%)
Manuel Alberto Quero
Ranch Hand

Joined: Jul 17, 2009
Posts: 31
Hi,

I agree with Ralph.

Have a look at this example:

http://www.java2s.com/Code/Java/EJB3/UseContextToLookupAnotherEjb.htm


Regards,

Manuel
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Manuel, thanks for agreeing.

A note about the example in the link: Since AnotherBeanLocal is stateless, EmployeeBean can be simplified in the following way:
sachin rathore
Greenhorn

Joined: Jan 29, 2010
Posts: 8
Hi,

Thanks a lot for your response. The annotation works fine when an EJB-A calls EJB-B directly.

Now i made an reference entry in web.xml
<ejb-local-ref>
<ejb-ref-name>ejb/TestLocal</ejb-ref-name>
<local>com.test.TestLocal</local>
</ejb-local-ref>

But i have another problem.
I am trying to access the local reference it cannot find the local reference in EJB Jar context.
Here is the condition. Class A - calls - EJB-A , with the context lookup for local interface and it works fine.
Now Class-A - calls - EJB-A and EJB-A - calls - class-B and Class-B - calls - EJB-B, this is a context lokup for local interface of EJB-B and it gives exception NameNotFound, it cannot find the reference for EJB-B in Class-B.

I even tried to make this entry in ejb-jar.xml
<session>
<ejb-name>TestLocalEJB</ejb-name>
<ejb-class>com.test.TestLocalBean</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ejb/ILocal</ejb-ref-name>
<local>com.test.ILocal</local>
</ejb-local-ref>
</session>

Still it gives the same error. Please let me know what change i can do to make this working to lookup with local interface.
I am using Java 5, Weblogic 10.3 , EJB 3.0

Thanks
Sachin
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Sachin,

I'm not sure what "EJB-A calls - class-B" means. Best you post a code excerpt from this call and from the JNDI lookup in class-B.

Does the lookup work (with the deployment descriptor) if it is processed in EJB-A instead of class-B ?
sachin rathore
Greenhorn

Joined: Jan 29, 2010
Posts: 8
Hi Ralph,

Thanks for your inputs.
I was actually trying to list the chain of calls, the order of calls how it fails.
and the deployment descriptor entries are already listed there .

So the situation is there are these java classes:
Class-A -- Simple Java Class (Calling Code (EJB-ALocal)context.lookup("java:comp/env/EJB-ALocal"))
EJB-ALocal -- This is local business interface implemented by EJB-A
EJB-A -- A stateless session bean EJB 3.0 (Actual Bean), this bean calls Class-B
Class-B -- Simple Java Class ( Calling Code (EJB-BLocal)context.lookup("java:comp/env/EJB-BLocal")), it fails on this lookup gives Exception NameNotFound.
EJB-B -- A stateless session bean EJB 3.0 (Actual Bean)

The deployment descriptor entries.
web.xml
<ejb-local-ref>
<ejb-ref-name>ejb/EJB-BLocal</ejb-ref-name>
<local>com.test.EJB-BLocal</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/EJB-ALocal</ejb-ref-name>
<local>com.test.EJB-ALocal</local>
</ejb-local-ref>

Then i tried adding ejb-jar.xml with these entries ( previously it was not there since it is not required by EJB 3.0)
ejb-jar.xml
<enterprise-beans>
<session>
<ejb-name>EJB-A</ejb-name>
<ejb-class>com.test.EJB-A</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ejb/EJB-ALocal</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.test.EJB-ALocal</local>
<ejb-link>testLocalEJB.jar#EJB-A</ejb-link>
</ejb-local-ref>
</session>
<session>
<ejb-name>EJB-B</ejb-name>
<ejb-class>com.test.EJB-B</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ejb/EJB-BLocal</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.test.EJB-BLocal</local>
<ejb-link>testLocalEJB.jar#EJB-B</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>

Call is still failing and cannot find the EJB via context lookup. Please let me know what else information i can provide?
What is more we can add to make this working. I am using Java 5, EJB 3.0, Weblogic 10.3

Thanks
Sachin
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi Sachin,

remember that you want to lookup EJB-B from EJB-A's environment. Therefore the deployment descriptor should be

<session>
<ejb-name>EJB-A</ejb-name>
<ejb-class>com.test.EJB-A</ejb-class>
<ejb-local-ref>
<ejb-ref-name>ejb/EJB-BLocal</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.test.EJB-BLocal</local>
<ejb-link>testLocalEJB.jar#EJB-B</ejb-link>
</ejb-local-ref>
</session>


I'm not sure if a context lookup from a plain java class that is instantiated inside an ejb is actually covered by the ejb spec. At least it worked with Glasfish app server. But for test I didn't used your deployment descriptor but the corresponding annotation:

@Stateless
@EJB(name="ejb/EJB-BLocal", beanInterface=EJB-BLocal.class)
public class EJB-A implements EJB-ALocal{...}


sachin rathore
Greenhorn

Joined: Jan 29, 2010
Posts: 8
Hi Ralph,

Thanks a lot , this works good..
Thanks again, helping me out.

I just have one more thing. Is there no direct way to do it ?
Since in my application there are 50 or so EJB and i dont know exactly which will call internally to which one.
So if there is any convenient and easy way to get around this i can try?

Right now what i am doing is finding from logs which all ejb throw the exception and adding those to the ejb-local-reference.

Please let me know if you know some other way of doing it for all the EJB so that any EJB can be called from the EJB context.

Thanks again , this solution serves the purpose.

Sachin
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
sachin wrote:
Please let me know if you know some other way of doing it for all the EJB so that any EJB can be called from the EJB context.

Some app servers like JBoss allow to bind local interfaces to the global JNDI namespace and to lookup global JNDI names within an ejb. In this case it's enough to ensure that each bean has a global name - no entry in the beans environment using <ejb-local-ref> is necessary, since the ejb can be accessed through its global JNDI name. But I don't know if weblogic offers this possibility. Also this solution isn't portable.

In EJB 3.1 the situation is much better: There the namespaces java:module and java:app have been introduced that deal with scenarios like the one you are faced with.
Shane Lee
Ranch Hand

Joined: Mar 19, 2005
Posts: 63
Good post guys.
This is my example to lookup ejb3 stateless session bean locally via web container on weblogic 10.3.2.
DocumentDAOLocal



DocumentDAOBean class


web.xml


POJO class:


Funny how different java ee certified servers process for ejb lookups are different...


 
 
subject: EJB 3 Local Lookup not working with Weblogic 10.3 and JDK 1.6_05