• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Himai Minh
Ranch Hand
Posts: 1360
7
  • 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.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • 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: 1360
7
  • 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: 1360
7
  • 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
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the update!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic