Thread: 10.1.3.1 Looking up a session EJB with DI from the Web tier


Permlink Replies: 11 - Pages: 1 - Last Post: Jul 18, 2007 12:09 PM Last Post By: karthequian
mulkers

Posts: 21
Registered: 01/13/00
10.1.3.1 Looking up a session EJB with DI from the Web tier
Posted: Nov 24, 2006 2:17 AM
Click to report abuse...   Click to reply to this thread Reply
Hi,
I am trying to use Dependency Injection in a class located in the Web tier.
I use the @EJB annotation but when I try to access the session bean in the code, it is a null pointer.

I have not modified any deployment descriptor. The bean is well present in the JNDI tree, with a name like <EJBmodulename>_<EJBimplementation classname> and if I do a JNDI lookup with that name, it works fine but I would like to use the Resource Injection.

I have tried to find such an example in the how-to's and in the documentation without success.

I am using Eclipse and OC4J 10.1.3.1. The EJB module descriptor is v3.0 and the Web module descriptor is v2.5 so I dont use the Jdeveloper wizardry here.

Robin
Steve Button

Posts: 1,920
Registered: 01/10/01
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Nov 24, 2006 1:42 PM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
There's an example here of EJB DI in a Web app:

http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-di-from-web/doc/how-to-di-from-web.html

See if that helps.

cheers
-steve-
mulkers

Posts: 21
Registered: 01/13/00
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Nov 29, 2006 12:32 AM   in response to: Steve Button in response to: Steve Button
Click to report abuse...   Click to reply to this thread Reply
No it does not.
I am trying to reproduce my problem with your example, I am removing the persistency stuff which does not work in my environment.

I am wondering why, in this example, the EJB-JAR file is present as a module of the J2EE application in the EAR file but is also copied as a simple JAR file in the WEB-INF/lib of the WAR module?

I don't see a reason for this.
mulkers

Posts: 21
Registered: 01/13/00
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Nov 29, 2006 3:01 AM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
So Dependency Injection (@EJB annotation) does work in the Web tier only if this annotation is located in a Servlet.

If the @EJB is located in a POJO located in WEB-INF/classes, the @EJB annotation is currently not resolved and is null.

I've extended the example provided here http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-di-from-web/doc/how-to-di-from-web.html
with a POJO acting as an intermediary between the servlet and the EJB to illustrate the problem. I can send you this EAR file if needed.

This problem is annoying, it prevents, for example, the use of @EJB annotations in a framework like Struts.

Any clue if this is a bug and when it will be solved?
Robin
Steve Button

Posts: 1,920
Registered: 01/10/01
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Nov 29, 2006 2:02 PM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
I'll check this out for you, please send me the ear file if possible.

steve [.] button [@] oracle [.] com

cheers
-steve-
mulkers

Posts: 21
Registered: 01/13/00
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Nov 30, 2006 2:15 AM   in response to: Steve Button in response to: Steve Button
Click to report abuse...   Click to reply to this thread Reply
They apparently have the same problem with @EJB DI in JSF. According to this post, it works in Glassfish.

http://forums.oracle.com/forums/thread.jspa?threadID=434481
mulkers

Posts: 21
Registered: 01/13/00
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jan 14, 2007 11:29 PM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
A final word to close this issue.
DI works only in "container managed classes" like servlets, EJBs, etc etc
If we try to do DI in a simple Java class, the container will not resolve the DI.
According to Oracle support, this behaviour is explicitely described in the J2EE 5 specification.

If you have a look at the J2EE 5 spec, the classes where DI is supported are listed on page 64.

Component classes supporting injection
Servlet: servlets, servlet filters, event listeners
JSP: tag handlers, tag library event listeners
JSF: scoped managed beans
JAX-WS: service endpoints, handlers
EJB: beans, interceptors
Java EE platform: main class (static), login callback handler


So here, we are in a situation where the Oracle implementation works in line with the spec but this feature is useless in a lot of cases. Who is still writing servlets today?

I would prefer to see Oracle suggesting an extension to that spec in order to support DI from any kind of class.

Best regards.
Robin Mulkers
Raam

Posts: 78
Registered: 12/14/06
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jan 16, 2007 7:50 AM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
I am still getting NULL when I use DI in JSF managed bean.

Did anybody make it work in managed bean???

-Rama
debabrata.panda...

Posts: 586
Registered: 01/10/01
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jan 16, 2007 10:27 AM   in response to: Raam in response to: Raam
Click to report abuse...   Click to reply to this thread Reply
Support of injection in JSF managed bean is part of JSF 1.1 and OC4J 10.1.3.1 does not support JSF 1.1.

regards
Debu
debabrata.panda...

Posts: 586
Registered: 01/10/01
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jan 16, 2007 10:30 AM   in response to: mulkers in response to: mulkers
Click to report abuse...   Click to reply to this thread Reply
We are process of adding our own extensions support injection in regular Java class and will be available in a future release of OC4J and we will work with next Java EE spec to make sure that this limitation is addressed

regards
Debu
http://debupanda.com
http://manning.com/panda - EJB 3 In Action
mulkers

Posts: 21
Registered: 01/13/00
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jan 16, 2007 12:22 PM   in response to: debabrata.panda... in response to: debabrata.panda...
Click to report abuse...   Click to reply to this thread Reply
Great news Debu, thanks.
I am looking forward for that feature in a next release.
Best regards.
Robin
karthequian

Posts: 22
Registered: 07/17/07
Re: 10.1.3.1 Looking up a session EJB with Resource Injection from the Web
Posted: Jul 18, 2007 12:09 PM   in response to: debabrata.panda... in response to: debabrata.panda...
Click to report abuse...   Click to reply to this thread Reply
Hey Debu,

I'm curious to see if this issue has been fixed in OC4J 10.3.2? I ran your ActionBazaar example (Chapter 12) from EJB in Action and it worked great; I used the same implementation as you had provided (Facade, EAO etc) but used the the myFaces implementation of JSF (MyFaces 1.1.4 with Facelets).

I tried an injection from a managed bean, but I always have a null stateless session bean.

Any ideas?

Thanks,

-K
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums