• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJBContext injection and ACC

 
Dirk Dühr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Why can't I inject an EJBContext object into an application client main class using the application client container (ACC)?
Remote interfaces of session beans work fine by the way.

Did I miss something fundamental or is it just a specific container issue?

That's what I did ...


And started it with container specific application client container launcher, e.g. Glassfish, like this (classpath and vm args omitted):



See http://java.sun.com/developer/technicalArticles/J2EE/jws-glassfish/part2.html#3

Any idea?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it make sense to have an EJBContext in a client application? It is only available to EJB, as the name suggests.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,

You can inject a EJB in a EJB, and not in a client. A client can look up a EJB, but can not have it injected.

Right?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An EJB can be injected to a Client application, but not EJBContext.

Right?
 
Dirk Dühr
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Raf, Niranjan, Tremin, you are right!

To my excuse - I was excited by the injection capabilities of the ACC. And I was especially interessted in a convinient way for JNDI lookups. So an injected EJBContext with it's ENC lookup method seemed to by a nice idea.

But I should have read the Java documentation more thoroughly.
"The EJBContext interface provides an instance with access to the container-provided runtime context of an enterprise Bean instance."
I guess I missed the last five words.

Probably i am just missing a kind of "ClientContext" which might be a superinterface of EJBContext but without getEJBHome(), getEJBLocalHome() of course.

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raf,

Kindly add some closing comments! I am confused again!
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Java EE 5 specs:

EE.9.4 Resources, Naming, and Injection
As with all Java EE components, application clients use JNDI to look up enterprise
beans, get access to resource managers, reference configurable parameters set at
deployment time, and so on. Application clients use the java: JNDI namespace to
access these items (see Chapter EE.5, “Resources, Naming, and Injection” for
details).
Injection is also supported for the application client main class. Because the
application client container does not create instances of the application client
main class, but merely loads the class and invokes the static main method,
injection into the application client class uses static fields and methods, unlike
other Java EE components. Injection occurs before the main method is called.

To summarise - injection and JNDI are available for clients. EJB and other resources may be injected, but only to static fields / properties in the class designated as Main-Class in MANIFEST.MF.
Whereas injecting an EJB is just fine, injecting an EJBContext doesn't look correct to me. I don't any specs section to back it up, unfortunately.
On the bright side, this is a cert forum, and for that, you don't have to worry about client containers - these are not a requirement.

Raf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic