• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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

 
Saloon Keeper
Posts: 2449
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 2449
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 2449
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3412
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the update!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic