This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

<resource-env-ref> cannot inject a SessionContext on p.198 of study guide

 
Ranch Hand
Posts: 1752
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p. 197-198 of Ivan's notes, it says using <resource-env-ref> to inject a SessionContext, like this:

In ejb-jar.xml:

The output is "No session context available".

I do this instead:

In my ejb-jar.xml ,


It works. It prints out the security information. It seems to me that I cannot remove @Resource for the SessionContext in CommonStatelessSessionBean.
 
Creator of Enthuware JWS+ V6
Posts: 3293
297
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem lies within the

This is what the ejb-specs say:

16.8.1.3 Declaration of Resource Environment References in Deployment Descriptor
The resource-env-ref-name element specifies the resource environment reference name: its value is the environment entry name used in the enterprise bean code. The name of the environment entry is relative to the java:comp/env context.



I think your <resource-env-ref-name> should be:

I guess you should also change the <resource-env-ref-type> if you want to invoke specific methods on the SessionContext, into
 
Himai Minh
Ranch Hand
Posts: 1752
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for Frits's suggestion.
That is true.
I change the value in <resource-evn-ref> into the following and it works now. The notes needs to be updated.
 
Himai Minh
Ranch Hand
Posts: 1752
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the deployment descriptor with security in Chapter 8 of Ivan's notes.
Let me correct my previous post.
Both approaches work. Ivan's deployment descriptor is fine and no need to be updated.


<session>
<ejb-name>StatelessSession1Bean</ejb-name>
<local-bean/>
<ejb-class>com.ivan.scbcd6.ejbs.StatelessSession1Bean</ejb-class>
<session-type>Stateless</session-type>
<ejb-local-ref>
<ejb-ref-name>StatelessSession2Bean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
...
</ejb-local-ref>
<resource-env-ref>
<resource-env-ref-name>java:comp/EJBContext</resource-env-ref-name>
<resource-env-ref-type>javax.ejb.EJBContext</resource-env-ref-type>
....
</resource-env-ref>



is the same as


<session>
<ejb-name>StatelessSession1Bean</ejb-name>
<local-bean/>
<ejb-class>com.ivan.scbcd6.ejbs.StatelessSession1Bean</ejb-class>
<session-type>Stateless</session-type>
<ejb-local-ref>
<ejb-ref-name>StatelessSession2Bean</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
...
</ejb-local-ref>
<resource-env-ref>
<resource-env-ref-name>com.ivan.scbcd6.ejbs.CommonStatelessSessionBean/mSessionContext</resource-env-ref-name>
<resource-env-ref-type>javax.ejb.EJBContext</resource-env-ref-type>
....
</resource-env-ref>






 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3293
297
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the update!
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!