You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nathan Schulte <na...@ngc.com> on 2009/07/16 22:03:55 UTC

EJB Injection in Interceptor

This may be more related to XWork2, but I'll start by asking here.

I'm creating a custom Interceptor to handle user permissions for an application.
 Rather than redirecting to an action to actually process a login attempt
(requiring a custom result type), the Interceptor itself will process the login
attempt.  However, in order for this to work, the Interceptor needs access to a
session bean that is the interface to the persistence layer.

Is it possible to use the Java EE 5 @EJB annotation to inject an EJB, or even
the Inject EJB Plugin?  I've tried both, and neither seem to work (both result
in a null object reference).  I realize I can use a JNDI lookup to get a
reference to the bean, but I would much rather use injection if possible, as
that's why it's there.

Thanks!
-Nate


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by David Blevins <da...@visi.com>.
Just to note, there has been some work in OpenEJB to make it so Struts  
objects can use Java EE injection like Servlets or JSF components  
can.  Karan did the work, he might be able to give more detail.

-David

On Jul 30, 2009, at 6:16 AM, Wes Wannemacher wrote:

> Sorry Robin, this is on my to-do list, but it's not something I'm
> working on right this second. One thing that is holding me up is the
> lack of knowledge of JEE. Is there a standard mechanism for creating
> instances of EJB-hydrated objects? For instance, if you annotated a
> field on a servlet with @PersistenceContext, the entity manager will
> be populated on the servlet. Obviously this works because the app
> server instantiates the servlet and the app server knows to do things
> like this. Is it part of the spec(s) that there is a way to
> instantiate objects, complete with dependencies injected? I know you
> can get objects from the JNDI context, but would that mean that
> objects retrieved need to be defined in JNDI? In the example with the
> servlet and EM, the servlet is defined in the web.xml, not the JNDI
> context... So, is there a place where I can read up on standard
> instantiation with EE DI?
>
> If it's not part of the standard, then, I still wouldn't mind building
> something specific to the app server that you are using (provided it
> is something I can get my hands on for free i.e. JBoss, OpenEJB). I
> started looking into this when this came up a few weeks ago, but I
> wasn't finding what I wanted so it got put off. If there is a way for
> me to call into the app server's own instantiation w/ DI facilities,
> writing this plugin would be a snap...
>
> -Wes
>
> On Thu, Jul 30, 2009 at 2:17 AM, Robin Mannering<robin@mtndesigns.co.uk 
> > wrote:
>> Just to clear up my actual question from the thread below as  
>> feedback has
>> run dry unfortunately.
>>
>> Is there anybody working daily with Struts 2 and EJB 3.0?
>>
>> If so, what is the best way to obtain local references to EJB 3  
>> session
>> beans from within Struts 2 action classes?
>>
>> Thanks for any thoughts on this subject.
>>
>> Robin Mannering wrote:
>>>
>>> Just wondering if the below thread has gone any further.
>>>
>>> After creating another thread on the same subject at an earlier  
>>> date, we
>>> discussed using the EJB plugin here:
>>>
>>> http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html
>>>
>>> However, having started to use this plugin so that I can reference
>>> stateless session beans, it seems that all EJB Session bean  
>>> classes must be
>>> defined as @Remote rather than @Local in order for the injection  
>>> to obtain
>>> the references correctly.  Failure to specify them as remote  
>>> throws a
>>> javax.naming.NameNotFoundException.
>>>
>>> However, reading from a book entitled "Pro EJB 3.0", the following
>>> performance issues are mentioned in relation to using @Remote when  
>>> @Local is
>>> available.  Hopefully this link will work for you.
>>>
>>>
>>> http://books.google.co.uk/books?id=fVCuB_Xq3pAC&pg=PA40&lpg=PA40&dq=Making+an+interface+remote+has+consequences&source=bl&ots=Bg9DdpVAWW&sig=vxrumZhYLhjmqbt6bdMJ96hrY7s&hl=en&ei=QIdtStuLC-WhjAf34KGeCw&sa=X&oi=book_result&ct=result&resnum=
>>>
>>> So, the problem is :
>>>
>>> How can we obtain references to EJB 3 session beans from within  
>>> Struts 2
>>> action classes?
>>>
>>> I'd be very interested to hear your thoughts.
>>>
>>> Thanks
>>> Robin
>>>
>>> Nathan Schulte wrote:
>>>>
>>>> Wes Wannemacher <wesw <at> wantii.com> writes:
>>>>
>>>>>
>>>>> Seems to me that my idea to create an ObjectFactory based  
>>>>> plugin ...
>>>>> needs to
>>>>>
>>>>
>>>> pick up some steam.
>>>>
>>>>>
>>>>> I only have one question for the EJB users out there... Do you  
>>>>> guys need
>>>>>
>>>>
>>>> Spring integration as well?
>>>>
>>>> To answer your question, _I_ personally don't need Spring  
>>>> integration.
>>>>  I've
>>>> never used Spring, and for this project, it was too much overhead  
>>>> to
>>>> learn (on
>>>> top of Java EE, the JPA, Hibernate intricacies, Struts2...), and  
>>>> from
>>>> what I
>>>> understand, it seemed like using it and S2 together provided  
>>>> duplicate
>>>> functionality (another topic altogether...).
>>>>
>>>> On another note, I find it awesome that the community (or  
>>>> whatever group
>>>> you're
>>>> part of) is so willing to provide support.  I mean, in my eyes,  
>>>> this is
>>>> something that I could see myself writing to make my coding  
>>>> easier, it's
>>>> just
>>>> that given my situation, it's easier to use the "workaround."
>>>>  Admittedly, I'm
>>>> not very familiar with JEE5.  Some of this is still black magic,  
>>>> and I
>>>> don't
>>>> fully understand the issue, I just know enough to understand that  
>>>> the
>>>> architecture permits it as an issue (and not everyone is just  
>>>> blowing
>>>> smoke my
>>>> way) and can leave all of the intricate details be, as they don't
>>>> directly
>>>> affect my project.
>>>>
>>>> -Nate
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>   
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>> No virus found in this incoming message.
>>>> Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
>>>> 270.13.20/2248 - Release Date: 07/19/09 05:57:00
>>>>
>>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> No virus found in this incoming message.
>>> Checked by AVG - www.avg.com Version: 8.5.392 / Virus Database:
>>> 270.13.31/2265 - Release Date: 07/26/09 17:59:00
>>>
>>>
>>
>
>
>
> -- 
> Wes Wannemacher
>
> Head Engineer, WanTii, Inc.
> Need Training? Struts, Spring, Maven, Tomcat...
> Ask me for a quote!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 2:02pm, HR=>Haroon Rafique <ha...@utoronto.ca> wrote:

HR> [..snip..]
HR> 
HR> Nope. Its not mentioned anywhere else in the app. Its just packaged in 
HR> the .war file (which is inside the .ear). Glassfish "does the right thing" 
HR> when it sees a servlet marked with the @EJB annotations. You can use the 
HR> Glassfish Admin Console (usually http://localhost:4848/):
HR>   Application Server -> General tab -> JNDI Browsing
HR> and you should find your EJBs under the ejb tree (the path to JNDI 
HR> browsing is from memory).
HR> 

Scratch that. The above only applies if you want to see @Remote ejbs.

Cheers,
--
Haroon Rafique
<ha...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Haroon Rafique <ha...@utoronto.ca>.
Hi Robin, see comments inline:

On Today at 7:25pm, RM=>Robin Mannering <ro...@mtndesigns.co.uk> wrote:

RM> [..snip..]
RM> 
RM> Can I just ask two further small questions to Haroon?
RM> 
RM> Is the EJBInvokerServlet set to initialise at app startup via the 
RM> web.xml definition?
RM> 

Nope. Its not mentioned anywhere else in the app. Its just packaged in 
the .war file (which is inside the .ear). Glassfish "does the right thing" 
when it sees a servlet marked with the @EJB annotations. You can use the 
Glassfish Admin Console (usually http://localhost:4848/):
  Application Server -> General tab -> JNDI Browsing
and you should find your EJBs under the ejb tree (the path to JNDI 
browsing is from memory).

RM> 
RM> Does the EJBInvokerServlet approach work for stateful session bean 
RM> references as well as stateless?
RM> 

Dunno. We have only done @Stateless.

RM> 
RM> Again, thank you for the time and effort everyone has gone through in 
RM> providing ideas and solutions to this problem.  It is good to know 
RM> that this kind of expert help is available via the forum.
RM> 
RM> Many thanks, Robin
RM> 

Cheers,
--
Haroon Rafique
<ha...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Robin Mannering <ro...@mtndesigns.co.uk>.
Wow!  Thanks for all this great feedback and ideas regards this problem.

I'm sorry I cannot add any useful prompts to help you develop a plugin 
Wes as Spring and it's methods for injection are something I know 
nothing about.  I have to admit, injection is not something I fully 
understand and anything I offered as a solution would likely be incorrect.

However, my only real requirement (currently) is to obtain local 
references to both stateless and stateful session beans in Glassfish 2.1 
from within Struts 2 action classes.

Looking at Haroons' examples, this would seem to be exactly the solution 
I'm looking for and I will try and implement this.

Can I just ask two further small questions to Haroon?

Is the EJBInvokerServlet set to initialise at app startup via the 
web.xml definition?

Does the EJBInvokerServlet approach work for stateful session bean 
references as well as stateless?

Again, thank you for the time and effort everyone has gone through in 
providing ideas and solutions to this problem.  It is good to know that 
this kind of expert help is available via the forum.

Many thanks, Robin



Wes Wannemacher wrote:
> On Thu, Jul 30, 2009 at 10:34 AM, Haroon
> Rafique<ha...@utoronto.ca> wrote:
>   
>> Hi Wes,
>>
>> I don't know much of the details about the JEE spec, however, I can share
>> my implementation with you. The code is not in production yet, so caveat
>> emptor (it works for us, for now in development).
>>
>> I use glassfish as my app server. To expose local EJB interfaces within
>> our entire application, I use an EJBInvokerServlet (uses the @EJB and
>> @EJBs annotations). The listing is as follows (took out package and import
>> statements and anonymized):
>>
>>    @EJBs(
>>        value = {
>>            @EJB(beanInterface = Local1.class, name = "ejb/local1"),
>>            @EJB(beanInterface = Local2.class, name = "ejb/local2"),
>>        }
>>    )
>>    /**
>>     * Used to make local interfaces of listed EJBs available within the whole
>>     * web application.
>>     */
>>    public class EJBInvokerServlet extends HttpServlet {
>>    }
>>
>> The other way to inject beans is by specifying <ejb-local-ref> inside web.xml.
>>    <ejb-local-ref>
>>        <ejb-ref-name>Local1Bean</ejb-ref-name>
>>        <ejb-ref-type>Session</ejb-ref-type>
>>        <local>Local1</local>
>>    </ejb-local-ref>
>> I prefer the Servlet approach as its simpler.
>>
>> Wherever we need the EJBs to be automagically injected (the container does
>> its part because of EJBInvokerServlet), we then use the @Resource
>> annotation, e.g., to inject the Local1 interface, I would use:
>>
>>    @Resource(mappedName = "ejb/local1")
>>    private Local1 local1;
>>
>> Hope that helps.
>>     
>
> Haroon, it does and it doesn't. @EJB/@EJBs and @Resource aren't the
> only DI annotations that are part of the EE specs. This is the problem
> Robin has with the existing integration plugins. My understanding of
> what he wants is that he wants to be able to use other annotations
> (like @PersistenceContext) on fields in a struts action and have those
> fields injected.
>
> To turn it around and consider it compared to another similar
> plugin... In the spring plugin, we delegate the class instantiation to
> spring, then spring can decide what needs injected, etc. based on
> spring configuration. What I'd like to do is apply the same concept to
> EE. To do this in spring, there is an implementation of the
> ObjectFactory that first tries to instantiate objects using spring,
> and when that fails, it falls back on traditional xwork instantiation
> (reflection-based). Once the object is created, the spring object
> factory then checks to see if it can autowire the instance (based on
> plugin configuration).
>
> I'd like to try a similar approach with EE. The hard part is that I
> don't know what API, or where to look for an API that instantiates EE
> objects. Spring has 'applicationContext.getBean', is there something
> similar for EE? Even if it's not as easy as Spring, I'm still willing
> to wade through it for a bit since it seems like it would be useful to
> at least a few users. The advantage to an object factory based EE
> plugin is that I don't need to be aware of the annotations at all, I'd
> be delegating that sort of thing to the EE app server's own
> mechanisms.
>
> -Wes
>
>
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.392 / Virus Database: 270.13.37/2273 - Release Date: 07/30/09 18:09:00
>
>   

Re: EJB Injection in Interceptor

Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, Jul 30, 2009 at 10:34 AM, Haroon
Rafique<ha...@utoronto.ca> wrote:
> Hi Wes,
>
> I don't know much of the details about the JEE spec, however, I can share
> my implementation with you. The code is not in production yet, so caveat
> emptor (it works for us, for now in development).
>
> I use glassfish as my app server. To expose local EJB interfaces within
> our entire application, I use an EJBInvokerServlet (uses the @EJB and
> @EJBs annotations). The listing is as follows (took out package and import
> statements and anonymized):
>
>    @EJBs(
>        value = {
>            @EJB(beanInterface = Local1.class, name = "ejb/local1"),
>            @EJB(beanInterface = Local2.class, name = "ejb/local2"),
>        }
>    )
>    /**
>     * Used to make local interfaces of listed EJBs available within the whole
>     * web application.
>     */
>    public class EJBInvokerServlet extends HttpServlet {
>    }
>
> The other way to inject beans is by specifying <ejb-local-ref> inside web.xml.
>    <ejb-local-ref>
>        <ejb-ref-name>Local1Bean</ejb-ref-name>
>        <ejb-ref-type>Session</ejb-ref-type>
>        <local>Local1</local>
>    </ejb-local-ref>
> I prefer the Servlet approach as its simpler.
>
> Wherever we need the EJBs to be automagically injected (the container does
> its part because of EJBInvokerServlet), we then use the @Resource
> annotation, e.g., to inject the Local1 interface, I would use:
>
>    @Resource(mappedName = "ejb/local1")
>    private Local1 local1;
>
> Hope that helps.

Haroon, it does and it doesn't. @EJB/@EJBs and @Resource aren't the
only DI annotations that are part of the EE specs. This is the problem
Robin has with the existing integration plugins. My understanding of
what he wants is that he wants to be able to use other annotations
(like @PersistenceContext) on fields in a struts action and have those
fields injected.

To turn it around and consider it compared to another similar
plugin... In the spring plugin, we delegate the class instantiation to
spring, then spring can decide what needs injected, etc. based on
spring configuration. What I'd like to do is apply the same concept to
EE. To do this in spring, there is an implementation of the
ObjectFactory that first tries to instantiate objects using spring,
and when that fails, it falls back on traditional xwork instantiation
(reflection-based). Once the object is created, the spring object
factory then checks to see if it can autowire the instance (based on
plugin configuration).

I'd like to try a similar approach with EE. The hard part is that I
don't know what API, or where to look for an API that instantiates EE
objects. Spring has 'applicationContext.getBean', is there something
similar for EE? Even if it's not as easy as Spring, I'm still willing
to wade through it for a bit since it seems like it would be useful to
at least a few users. The advantage to an object factory based EE
plugin is that I don't need to be aware of the annotations at all, I'd
be delegating that sort of thing to the EE app server's own
mechanisms.

-Wes


-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 9:16am, WW=>Wes Wannemacher <we...@wantii.com> wrote:

WW> Sorry Robin, this is on my to-do list, but it's not something I'm
WW> working on right this second. One thing that is holding me up is the
WW> lack of knowledge of JEE. Is there a standard mechanism for creating
WW> instances of EJB-hydrated objects?
WW> 
WW> [..snip..]
WW> 

Hi Wes,

I don't know much of the details about the JEE spec, however, I can share 
my implementation with you. The code is not in production yet, so caveat
emptor (it works for us, for now in development).

I use glassfish as my app server. To expose local EJB interfaces within 
our entire application, I use an EJBInvokerServlet (uses the @EJB and 
@EJBs annotations). The listing is as follows (took out package and import 
statements and anonymized):

    @EJBs(
        value = {
            @EJB(beanInterface = Local1.class, name = "ejb/local1"),
            @EJB(beanInterface = Local2.class, name = "ejb/local2"),
        }
    )
    /**
     * Used to make local interfaces of listed EJBs available within the whole
     * web application.
     */
    public class EJBInvokerServlet extends HttpServlet {
    }

The other way to inject beans is by specifying <ejb-local-ref> inside web.xml.
    <ejb-local-ref>
        <ejb-ref-name>Local1Bean</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <local>Local1</local>
    </ejb-local-ref>
I prefer the Servlet approach as its simpler.

Wherever we need the EJBs to be automagically injected (the container does 
its part because of EJBInvokerServlet), we then use the @Resource 
annotation, e.g., to inject the Local1 interface, I would use:

    @Resource(mappedName = "ejb/local1")
    private Local1 local1;

Hope that helps.
--
Haroon Rafique
<ha...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Wes Wannemacher <we...@wantii.com>.
Sorry Robin, this is on my to-do list, but it's not something I'm
working on right this second. One thing that is holding me up is the
lack of knowledge of JEE. Is there a standard mechanism for creating
instances of EJB-hydrated objects? For instance, if you annotated a
field on a servlet with @PersistenceContext, the entity manager will
be populated on the servlet. Obviously this works because the app
server instantiates the servlet and the app server knows to do things
like this. Is it part of the spec(s) that there is a way to
instantiate objects, complete with dependencies injected? I know you
can get objects from the JNDI context, but would that mean that
objects retrieved need to be defined in JNDI? In the example with the
servlet and EM, the servlet is defined in the web.xml, not the JNDI
context... So, is there a place where I can read up on standard
instantiation with EE DI?

If it's not part of the standard, then, I still wouldn't mind building
something specific to the app server that you are using (provided it
is something I can get my hands on for free i.e. JBoss, OpenEJB). I
started looking into this when this came up a few weeks ago, but I
wasn't finding what I wanted so it got put off. If there is a way for
me to call into the app server's own instantiation w/ DI facilities,
writing this plugin would be a snap...

-Wes

On Thu, Jul 30, 2009 at 2:17 AM, Robin Mannering<ro...@mtndesigns.co.uk> wrote:
> Just to clear up my actual question from the thread below as feedback has
> run dry unfortunately.
>
> Is there anybody working daily with Struts 2 and EJB 3.0?
>
> If so, what is the best way to obtain local references to EJB 3 session
> beans from within Struts 2 action classes?
>
> Thanks for any thoughts on this subject.
>
> Robin Mannering wrote:
>>
>> Just wondering if the below thread has gone any further.
>>
>> After creating another thread on the same subject at an earlier date, we
>> discussed using the EJB plugin here:
>>
>> http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html
>>
>> However, having started to use this plugin so that I can reference
>> stateless session beans, it seems that all EJB Session bean classes must be
>> defined as @Remote rather than @Local in order for the injection to obtain
>> the references correctly.  Failure to specify them as remote throws a
>> javax.naming.NameNotFoundException.
>>
>> However, reading from a book entitled "Pro EJB 3.0", the following
>> performance issues are mentioned in relation to using @Remote when @Local is
>> available.  Hopefully this link will work for you.
>>
>>
>> http://books.google.co.uk/books?id=fVCuB_Xq3pAC&pg=PA40&lpg=PA40&dq=Making+an+interface+remote+has+consequences&source=bl&ots=Bg9DdpVAWW&sig=vxrumZhYLhjmqbt6bdMJ96hrY7s&hl=en&ei=QIdtStuLC-WhjAf34KGeCw&sa=X&oi=book_result&ct=result&resnum=
>>
>> So, the problem is :
>>
>> How can we obtain references to EJB 3 session beans from within Struts 2
>> action classes?
>>
>> I'd be very interested to hear your thoughts.
>>
>> Thanks
>> Robin
>>
>> Nathan Schulte wrote:
>>>
>>> Wes Wannemacher <wesw <at> wantii.com> writes:
>>>
>>>>
>>>> Seems to me that my idea to create an ObjectFactory based plugin ...
>>>> needs to
>>>>
>>>
>>> pick up some steam.
>>>
>>>>
>>>> I only have one question for the EJB users out there... Do you guys need
>>>>
>>>
>>> Spring integration as well?
>>>
>>> To answer your question, _I_ personally don't need Spring integration.
>>>  I've
>>> never used Spring, and for this project, it was too much overhead to
>>> learn (on
>>> top of Java EE, the JPA, Hibernate intricacies, Struts2...), and from
>>> what I
>>> understand, it seemed like using it and S2 together provided duplicate
>>> functionality (another topic altogether...).
>>>
>>> On another note, I find it awesome that the community (or whatever group
>>> you're
>>> part of) is so willing to provide support.  I mean, in my eyes, this is
>>> something that I could see myself writing to make my coding easier, it's
>>> just
>>> that given my situation, it's easier to use the "workaround."
>>>  Admittedly, I'm
>>> not very familiar with JEE5.  Some of this is still black magic, and I
>>> don't
>>> fully understand the issue, I just know enough to understand that the
>>> architecture permits it as an issue (and not everyone is just blowing
>>> smoke my
>>> way) and can leave all of the intricate details be, as they don't
>>> directly
>>> affect my project.
>>>
>>> -Nate
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>  ------------------------------------------------------------------------
>>>
>>>
>>> No virus found in this incoming message.
>>> Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database:
>>> 270.13.20/2248 - Release Date: 07/19/09 05:57:00
>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.392 / Virus Database:
>> 270.13.31/2265 - Release Date: 07/26/09 17:59:00
>>
>>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Struts Two <st...@yahoo.ca>.
You can either use Spring or implement your own EJB3 interceptor. Though I use my own EJB3 interceptor, I believe the best option is to go with Spring. Google Juice can also be option on the table as well.



--- On Thu, 7/30/09, Robin Mannering <ro...@mtndesigns.co.uk> wrote:

> From: Robin Mannering <ro...@mtndesigns.co.uk>
> Subject: Re: EJB Injection in Interceptor
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Received: Thursday, July 30, 2009, 6:17 AM
> Just to clear up my actual question
> from the thread below as feedback has run dry
> unfortunately.
> 
> Is there anybody working daily with Struts 2 and EJB 3.0?
> 
> If so, what is the best way to obtain local references to
> EJB 3 session beans from within Struts 2 action classes?
> 
> Thanks for any thoughts on this subject.
> 
> Robin Mannering wrote:
> > Just wondering if the below thread has gone any
> further.
> > 
> > After creating another thread on the same subject at
> an earlier date, we discussed using the EJB plugin here:
> > 
> > http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html
> > 
> > However, having started to use this plugin so that I
> can reference stateless session beans, it seems that all EJB
> Session bean classes must be defined as @Remote rather than
> @Local in order for the injection to obtain the references
> correctly.  Failure to specify them as remote throws a
> javax.naming.NameNotFoundException.
> > 
> > However, reading from a book entitled "Pro EJB 3.0",
> the following performance issues are mentioned in relation
> to using @Remote when @Local is available.  Hopefully
> this link will work for you.
> > 
> > http://books.google.co.uk/books?id=fVCuB_Xq3pAC&pg=PA40&lpg=PA40&dq=Making+an+interface+remote+has+consequences&source=bl&ots=Bg9DdpVAWW&sig=vxrumZhYLhjmqbt6bdMJ96hrY7s&hl=en&ei=QIdtStuLC-WhjAf34KGeCw&sa=X&oi=book_result&ct=result&resnum=
> 
> > 
> > So, the problem is :
> > 
> > How can we obtain references to EJB 3 session beans
> from within Struts 2 action classes?
> > 
> > I'd be very interested to hear your thoughts.
> > 
> > Thanks
> > Robin
> > 
> > Nathan Schulte wrote:
> >> Wes Wannemacher <wesw <at> wantii.com>
> writes:
> >>  
> >>> Seems to me that my idea to create an
> ObjectFactory based plugin ... needs to
> >>>     
> >> pick up some steam.
> >>  
> >>> I only have one question for the EJB users out
> there... Do you guys need
> >>>     
> >> Spring integration as well?
> >> 
> >> To answer your question, _I_ personally don't need
> Spring integration.  I've
> >> never used Spring, and for this project, it was
> too much overhead to learn (on
> >> top of Java EE, the JPA, Hibernate intricacies,
> Struts2...), and from what I
> >> understand, it seemed like using it and S2
> together provided duplicate
> >> functionality (another topic altogether...).
> >> 
> >> On another note, I find it awesome that the
> community (or whatever group you're
> >> part of) is so willing to provide support.  I
> mean, in my eyes, this is
> >> something that I could see myself writing to make
> my coding easier, it's just
> >> that given my situation, it's easier to use the
> "workaround."  Admittedly, I'm
> >> not very familiar with JEE5.  Some of this is
> still black magic, and I don't
> >> fully understand the issue, I just know enough to
> understand that the
> >> architecture permits it as an issue (and not
> everyone is just blowing smoke my
> >> way) and can leave all of the intricate details
> be, as they don't directly
> >> affect my project.
> >> 
> >> -Nate
> >> 
> >> 
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>   ------------------------------------------------------------------------
> >> 
> >> 
> >> No virus found in this incoming message.
> >> Checked by AVG - www.avg.com Version: 8.5.387 /
> Virus Database: 270.13.20/2248 - Release Date: 07/19/09
> 05:57:00
> >> 
> >>   
> > 
> >
> ------------------------------------------------------------------------
> > 
> > 
> > No virus found in this incoming message.
> > Checked by AVG - www.avg.com Version: 8.5.392 / Virus
> Database: 270.13.31/2265 - Release Date: 07/26/09 17:59:00
> > 
> >   


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Robin Mannering <ro...@mtndesigns.co.uk>.
Just to clear up my actual question from the thread below as feedback 
has run dry unfortunately.

Is there anybody working daily with Struts 2 and EJB 3.0?

If so, what is the best way to obtain local references to EJB 3 session 
beans from within Struts 2 action classes?

Thanks for any thoughts on this subject.

Robin Mannering wrote:
> Just wondering if the below thread has gone any further.
>
> After creating another thread on the same subject at an earlier date, 
> we discussed using the EJB plugin here:
>
> http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html
>
> However, having started to use this plugin so that I can reference 
> stateless session beans, it seems that all EJB Session bean classes 
> must be defined as @Remote rather than @Local in order for the 
> injection to obtain the references correctly.  Failure to specify them 
> as remote throws a javax.naming.NameNotFoundException.
>
> However, reading from a book entitled "Pro EJB 3.0", the following 
> performance issues are mentioned in relation to using @Remote when 
> @Local is available.  Hopefully this link will work for you.
>
> http://books.google.co.uk/books?id=fVCuB_Xq3pAC&pg=PA40&lpg=PA40&dq=Making+an+interface+remote+has+consequences&source=bl&ots=Bg9DdpVAWW&sig=vxrumZhYLhjmqbt6bdMJ96hrY7s&hl=en&ei=QIdtStuLC-WhjAf34KGeCw&sa=X&oi=book_result&ct=result&resnum= 
>
>
> So, the problem is :
>
> How can we obtain references to EJB 3 session beans from within Struts 
> 2 action classes?
>
> I'd be very interested to hear your thoughts.
>
> Thanks
> Robin
>
> Nathan Schulte wrote:
>> Wes Wannemacher <wesw <at> wantii.com> writes:
>>  
>>> Seems to me that my idea to create an ObjectFactory based plugin ... 
>>> needs to
>>>     
>> pick up some steam.
>>  
>>> I only have one question for the EJB users out there... Do you guys 
>>> need
>>>     
>> Spring integration as well?
>>
>> To answer your question, _I_ personally don't need Spring 
>> integration.  I've
>> never used Spring, and for this project, it was too much overhead to 
>> learn (on
>> top of Java EE, the JPA, Hibernate intricacies, Struts2...), and from 
>> what I
>> understand, it seemed like using it and S2 together provided duplicate
>> functionality (another topic altogether...).
>>
>> On another note, I find it awesome that the community (or whatever 
>> group you're
>> part of) is so willing to provide support.  I mean, in my eyes, this is
>> something that I could see myself writing to make my coding easier, 
>> it's just
>> that given my situation, it's easier to use the "workaround."  
>> Admittedly, I'm
>> not very familiar with JEE5.  Some of this is still black magic, and 
>> I don't
>> fully understand the issue, I just know enough to understand that the
>> architecture permits it as an issue (and not everyone is just blowing 
>> smoke my
>> way) and can leave all of the intricate details be, as they don't 
>> directly
>> affect my project.
>>
>> -Nate
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>   
>> ------------------------------------------------------------------------
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com Version: 8.5.387 / Virus Database: 
>> 270.13.20/2248 - Release Date: 07/19/09 05:57:00
>>
>>   
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.392 / Virus Database: 270.13.31/2265 - Release Date: 07/26/09 17:59:00
>
>   

Re: EJB Injection in Interceptor

Posted by Nathan Schulte <na...@ngc.com>.
Robin Mannering <robin <at> mtndesigns.co.uk> writes:
> http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html
Are you using that plugin, or the following?
http://cwiki.apache.org/S2PLUGINS/ejb3-jboss-plugin.html

With the "JBoss" plugin, I am able to use Local interfaces rather than remote. 
I can show an example of this as well if you think it might help.





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Robin Mannering <ro...@mtndesigns.co.uk>.
Just wondering if the below thread has gone any further.

After creating another thread on the same subject at an earlier date, we 
discussed using the EJB plugin here:

http://cwiki.apache.org/S2PLUGINS/ejb3-plugin.html

However, having started to use this plugin so that I can reference 
stateless session beans, it seems that all EJB Session bean classes must 
be defined as @Remote rather than @Local in order for the injection to 
obtain the references correctly.  Failure to specify them as remote 
throws a javax.naming.NameNotFoundException.

However, reading from a book entitled "Pro EJB 3.0", the following 
performance issues are mentioned in relation to using @Remote when 
@Local is available.  Hopefully this link will work for you.

http://books.google.co.uk/books?id=fVCuB_Xq3pAC&pg=PA40&lpg=PA40&dq=Making+an+interface+remote+has+consequences&source=bl&ots=Bg9DdpVAWW&sig=vxrumZhYLhjmqbt6bdMJ96hrY7s&hl=en&ei=QIdtStuLC-WhjAf34KGeCw&sa=X&oi=book_result&ct=result&resnum=

So, the problem is :

How can we obtain references to EJB 3 session beans from within Struts 2 
action classes?

I'd be very interested to hear your thoughts.

Thanks
Robin

Nathan Schulte wrote:
> Wes Wannemacher <wesw <at> wantii.com> writes:
>   
>> Seems to me that my idea to create an ObjectFactory based plugin ... needs to
>>     
> pick up some steam.
>   
>> I only have one question for the EJB users out there... Do you guys need
>>     
> Spring integration as well?
>
> To answer your question, _I_ personally don't need Spring integration.  I've
> never used Spring, and for this project, it was too much overhead to learn (on
> top of Java EE, the JPA, Hibernate intricacies, Struts2...), and from what I
> understand, it seemed like using it and S2 together provided duplicate
> functionality (another topic altogether...).
>
> On another note, I find it awesome that the community (or whatever group you're
> part of) is so willing to provide support.  I mean, in my eyes, this is
> something that I could see myself writing to make my coding easier, it's just
> that given my situation, it's easier to use the "workaround."  Admittedly, I'm
> not very familiar with JEE5.  Some of this is still black magic, and I don't
> fully understand the issue, I just know enough to understand that the
> architecture permits it as an issue (and not everyone is just blowing smoke my
> way) and can leave all of the intricate details be, as they don't directly
> affect my project.
>
> -Nate
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.387 / Virus Database: 270.13.20/2248 - Release Date: 07/19/09 05:57:00
>
>   

Re: EJB Injection in Interceptor

Posted by Nathan Schulte <na...@ngc.com>.
Wes Wannemacher <wesw <at> wantii.com> writes:
> Seems to me that my idea to create an ObjectFactory based plugin ... needs to
pick up some steam.
> I only have one question for the EJB users out there... Do you guys need
Spring integration as well?

To answer your question, _I_ personally don't need Spring integration.  I've
never used Spring, and for this project, it was too much overhead to learn (on
top of Java EE, the JPA, Hibernate intricacies, Struts2...), and from what I
understand, it seemed like using it and S2 together provided duplicate
functionality (another topic altogether...).

On another note, I find it awesome that the community (or whatever group you're
part of) is so willing to provide support.  I mean, in my eyes, this is
something that I could see myself writing to make my coding easier, it's just
that given my situation, it's easier to use the "workaround."  Admittedly, I'm
not very familiar with JEE5.  Some of this is still black magic, and I don't
fully understand the issue, I just know enough to understand that the
architecture permits it as an issue (and not everyone is just blowing smoke my
way) and can leave all of the intricate details be, as they don't directly
affect my project.

-Nate


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Wes Wannemacher <we...@wantii.com>.
On Thursday 16 July 2009 04:20:05 pm Nathan Schulte wrote:
> Nils-Helge Garli Hegvik <nilsga <at> gmail.com> writes:
> > The short answer - You have to do the lookup yourself.
> >
> :/
> :
> > The long answer - There's a similar discussion going on that pretty
> > much covers the topic:
> > http://www.nabble.com/Struts2-Action-Class-and-EJB-Injection-td24497801.h
> >tml
>
> Yes, I'm familiar with this issue.  I guess, in order to resolve it in an
> Interceptor as opposed to an Action (the method of using an Interceptor and
> reflection to do the injection), one would have to do the same for the
> Interceptors...
>
> Oh well, you can't win all of the time.
>
> Thanks for the speedy reply!

Seems to me that my idea to create an ObjectFactory based plugin (rather than 
the existing interceptor-based plugins) needs to pick up some steam. I only 
have one question for the EJB users out there... Do you guys need Spring 
integration as well? Currently, the spring plugin is the only plugin (I know 
of) that is based on a replacement ObjectFactory. If you don't need Spring, I 
could probably put one together pretty quick. If you need Spring, it would 
take a little longer, or it could be a separate plugin...

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Nathan Schulte <na...@ngc.com>.
Nils-Helge Garli Hegvik <nilsga <at> gmail.com> writes:
> The short answer - You have to do the lookup yourself.
:/

> The long answer - There's a similar discussion going on that pretty
> much covers the topic:
> http://www.nabble.com/Struts2-Action-Class-and-EJB-Injection-td24497801.html
Yes, I'm familiar with this issue.  I guess, in order to resolve it in an
Interceptor as opposed to an Action (the method of using an Interceptor and
reflection to do the injection), one would have to do the same for the
Interceptors...

Oh well, you can't win all of the time.

Thanks for the speedy reply!


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: EJB Injection in Interceptor

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
The short answer - You have to do the lookup yourself.

The long answer - There's a similar discussion going on that pretty
much covers the topic:
http://www.nabble.com/Struts2-Action-Class-and-EJB-Injection-td24497801.html

Nils-H

On Thu, Jul 16, 2009 at 10:03 PM, Nathan Schulte<na...@ngc.com> wrote:
> This may be more related to XWork2, but I'll start by asking here.
>
> I'm creating a custom Interceptor to handle user permissions for an application.
>  Rather than redirecting to an action to actually process a login attempt
> (requiring a custom result type), the Interceptor itself will process the login
> attempt.  However, in order for this to work, the Interceptor needs access to a
> session bean that is the interface to the persistence layer.
>
> Is it possible to use the Java EE 5 @EJB annotation to inject an EJB, or even
> the Inject EJB Plugin?  I've tried both, and neither seem to work (both result
> in a null object reference).  I realize I can use a JNDI lookup to get a
> reference to the bean, but I would much rather use injection if possible, as
> that's why it's there.
>
> Thanks!
> -Nate
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org