You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Baetz <ba...@arcor.de> on 2008/08/27 09:46:17 UTC

Extending EJBInjection interceptor

Hi,

i'm currently working on a new Interceptor for EJB Injection on Actions. 
I allready extendet it to work on fields and methods. But since i dont 
like to make my own Annotation type i wanted to use the javax.ejb.ejb 
anotation. But there is a small problem with that:

the annotation used by the ejb3-plugin for struts 2 has a field that 
determines if the bean is statefull or stateless. I don't have this 
bean, so how do i determine for the injection if the bean is statefull?

my first idea was to use reflection and look for @statefull or 
@stateless on the beanclass. But since i don't have to know the class 
this doesnt have to work.
the second idea was to do the lookup in any case and look then for the 
annotation on the class.

Is there a better way to determine if a bean is statefull with only the 
ejb-name for the jndi lookup?

Greetings,
Alex

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


Re: Extending EJBInjection interceptor

Posted by Alexander Baetz <ba...@arcor.de>.
As i answered to the other mail. I'm not sure. Based on the code i 
started with i thought i would have to take care of the instances (and 
therefore only hold one for a stateless bean).
I'm not that familiar with EJB injection and lookups. but when i think 
about it JNDI has to hold the one instance so it shouldnt matter.
but i'm not sure.

Greetings
Alexander

Jeromy Evans schrieb:
> Alexander Baetz wrote:
>> Hi,
>>
>> i'm currently working on a new Interceptor for EJB Injection on 
>> Actions. I allready extendet it to work on fields and methods. But 
>> since i dont like to make my own Annotation type i wanted to use the 
>> javax.ejb.ejb anotation. But there is a small problem with that:
>>
>> the annotation used by the ejb3-plugin for struts 2 has a field that 
>> determines if the bean is statefull or stateless. I don't have this 
>> bean, so how do i determine for the injection if the bean is statefull?
>>
>
> I'm not familiar with the plugin, but why does it need to know whether 
> the bean is statefull or stateless?  I don't think that should affect 
> the lookup or injection into the action, should it?  Only the 
> Container that instantiates the bean and provides the instance cares, 
> doesn't it?
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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: Extending EJBInjection interceptor

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Alexander Baetz wrote:
> Hi,
>
> i'm currently working on a new Interceptor for EJB Injection on 
> Actions. I allready extendet it to work on fields and methods. But 
> since i dont like to make my own Annotation type i wanted to use the 
> javax.ejb.ejb anotation. But there is a small problem with that:
>
> the annotation used by the ejb3-plugin for struts 2 has a field that 
> determines if the bean is statefull or stateless. I don't have this 
> bean, so how do i determine for the injection if the bean is statefull?
>

I'm not familiar with the plugin, but why does it need to know whether 
the bean is statefull or stateless?  I don't think that should affect 
the lookup or injection into the action, should it?  Only the Container 
that instantiates the bean and provides the instance cares, doesn't it?






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


Re: Extending EJBInjection interceptor

Posted by "David N. Arnold" <da...@gmail.com>.
I'm not sure what you mean.  Even though I advised against it, I
explained how to do it.

To be specific, you write an interceptor that scans the incoming
action instance for @EJB annotations.  For each annotation, you check
the HttpSession to see if you already have a reference for the
specified class.  If not, you do the JNDI lookup and store it in the
HttpSession for future use.  And finally, you inject the reference(s)
into the action and call the next step in the invocation chain.

Maybe someone else has some improvements, but that's the general way
it would work.

On Sat, Aug 30, 2008 at 4:31 PM, Alexander Baetz
<ba...@arcor.de> wrote:
> As i mentioned, i want to avoid doing the lookup every time. Thats why i
> wanted to write that interceptor.
> But there doesnt seem to be a good way to get Beans without doing the lookup
> directly in the action. At least i didnt find one.
>
> Greetings,
> Alexander

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


RE: Extending EJBInjection interceptor

Posted by Martin Gainty <mg...@hotmail.com>.
you can use Spring framework to create a proxy which will be cached (from the JNDI lookup)to quote the doc:The EJB local home is cached on startup, so there’s only a single JNDI lookup. Each time the EJB is invoked, the proxy invokes the classname method on the local EJB and invokes the corresponding business method on the EJB. 
http://static.springframework.org/spring/docs/2.5.x/reference/ejb.html
i believe this will accomplish your objective..
anyone ?Martin ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Sat, 30 Aug 2008 22:31:13 +0200> From: baetz.paderborn@arcor.de> To: user@struts.apache.org> Subject: Re: Extending EJBInjection interceptor> > As i mentioned, i want to avoid doing the lookup every time. Thats why i > wanted to write that interceptor.> But there doesnt seem to be a good way to get Beans without doing the > lookup directly in the action. At least i didnt find one.> > Greetings,> Alexander> > Martin Gainty schrieb:> > did you get a chance to look at using context.lookuphttp://www.tutorialized.com/view/tutorial/EJB-3-and-Struts-Framework-Tutorial-using-JBoss/11894> > by Sebastian Hennebrueder > > public class ListBooksAction extends Action { /** * Method execute * * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { > > BookDao bookDao = null; List<Book> books = null; try { > > Context context = new InitialContext(); > > bookDao = (BookDao) context.lookup(BookDaoImp.LocalJNDIName); > > } > > catch (NamingException e) { > > System.out.println("NamingException found message = "+e.getMessage());}> > we could be more assistance if you could describe which alternative lookups you want to implement and provide a few testcases to achieve that objective> > ?Martin Gainty ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Sat, 30 Aug 2008 16:18:56 +0200> From: baetz.paderborn@arcor.de> To: user@struts.apache.org> Subject: Re: Extending EJBInjection interceptor> > Thats a pretty good explanation of how the plugin works....> > I was going to use this method because it was recommended by another > user on the mailing list.> EJB3 is no necessity, but i want to avoid making jndi lookups in every > action i have. Is there another way to achive that?> > Greetings,> Alexander> > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org> For additional commands, e-mail: user-help@struts.apache.org> > > _________________________________________________________________> > Get thousands of games on your PC, your mobile phone, and the web with Windows®.> > http://clk.atdmt.com/MRT/go/108588800/direct/01/> > > > > > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org> For additional commands, e-mail: user-help@struts.apache.org> 
_________________________________________________________________
Be the filmmaker you always wanted to be—learn how to burn a DVD with Windows®.
http://clk.atdmt.com/MRT/go/108588797/direct/01/

Re: Extending EJBInjection interceptor

Posted by Alexander Baetz <ba...@arcor.de>.
As i mentioned, i want to avoid doing the lookup every time. Thats why i 
wanted to write that interceptor.
But there doesnt seem to be a good way to get Beans without doing the 
lookup directly in the action. At least i didnt find one.

Greetings,
Alexander

Martin Gainty schrieb:
> did you get a chance to look at using context.lookuphttp://www.tutorialized.com/view/tutorial/EJB-3-and-Struts-Framework-Tutorial-using-JBoss/11894
> by Sebastian Hennebrueder 
> public class ListBooksAction extends Action { /**  * Method execute  *   * @param mapping  * @param form  * @param request  * @param response  * @return ActionForward  */ public ActionForward execute(ActionMapping mapping, ActionForm form,   HttpServletRequest request, HttpServletResponse response) { 
>  BookDao bookDao = null;  List<Book> books = null;   try  {   
>    Context context = new InitialContext();   
>    bookDao = (BookDao) context.lookup(BookDaoImp.LocalJNDIName);  
>  } 
>  catch (NamingException e)  { 
>  System.out.println("NamingException found message = "+e.getMessage());}
> we could be more assistance if you could describe which alternative lookups you want to implement and provide a few testcases to achieve that objective
> ?Martin Gainty ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Sat, 30 Aug 2008 16:18:56 +0200> From: baetz.paderborn@arcor.de> To: user@struts.apache.org> Subject: Re: Extending EJBInjection interceptor> > Thats a pretty good explanation of how the plugin works....> > I was going to use this method because it was recommended by another > user on the mailing list.> EJB3 is no necessity, but i want to avoid making jndi lookups in every > action i have. Is there another way to achive that?> > Greetings,> Alexander> > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org> For additional commands, e-mail: user-help@struts.apache.org> 
> _________________________________________________________________
> Get thousands of games on your PC, your mobile phone, and the web with Windows®.
> http://clk.atdmt.com/MRT/go/108588800/direct/01/
>   



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


RE: Extending EJBInjection interceptor

Posted by Martin Gainty <mg...@hotmail.com>.
did you get a chance to look at using context.lookuphttp://www.tutorialized.com/view/tutorial/EJB-3-and-Struts-Framework-Tutorial-using-JBoss/11894
by Sebastian Hennebrueder 
public class ListBooksAction extends Action { /**  * Method execute  *   * @param mapping  * @param form  * @param request  * @param response  * @return ActionForward  */ public ActionForward execute(ActionMapping mapping, ActionForm form,   HttpServletRequest request, HttpServletResponse response) { 
 BookDao bookDao = null;  List<Book> books = null;   try  {   
   Context context = new InitialContext();   
   bookDao = (BookDao) context.lookup(BookDaoImp.LocalJNDIName);  
 } 
 catch (NamingException e)  { 
 System.out.println("NamingException found message = "+e.getMessage());}
we could be more assistance if you could describe which alternative lookups you want to implement and provide a few testcases to achieve that objective
?Martin Gainty ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Sat, 30 Aug 2008 16:18:56 +0200> From: baetz.paderborn@arcor.de> To: user@struts.apache.org> Subject: Re: Extending EJBInjection interceptor> > Thats a pretty good explanation of how the plugin works....> > I was going to use this method because it was recommended by another > user on the mailing list.> EJB3 is no necessity, but i want to avoid making jndi lookups in every > action i have. Is there another way to achive that?> > Greetings,> Alexander> > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org> For additional commands, e-mail: user-help@struts.apache.org> 
_________________________________________________________________
Get thousands of games on your PC, your mobile phone, and the web with Windows®.
http://clk.atdmt.com/MRT/go/108588800/direct/01/

Re: Extending EJBInjection interceptor

Posted by Alexander Baetz <ba...@arcor.de>.
Thats a pretty good explanation of how the plugin works....

I was going to use this method because it was recommended by another 
user on the mailing list.
EJB3 is no necessity, but i want to avoid making jndi lookups in every 
action i have. Is there another way to achive that?

Greetings,
Alexander

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


Re: Extending EJBInjection interceptor

Posted by "David N. Arnold" <da...@gmail.com>.
On Wed, Aug 27, 2008 at 3:46 AM, Alexander Baetz
<ba...@arcor.de> wrote:
> Hi,
>
> i'm currently working on a new Interceptor for EJB Injection on Actions. I
> allready extendet it to work on fields and methods. But since i dont like to
> make my own Annotation type i wanted to use the javax.ejb.ejb anotation.

I tried to do something similar once and came to the conclusion that
it is not a good idea.

> the annotation used by the ejb3-plugin for struts 2 has a field that
> determines if the bean is statefull or stateless. I don't have this bean, so
> how do i determine for the injection if the bean is statefull?

Basically, you don't.  The best you can do (and someone please correct
me if I'm wrong) is do a JNDI lookup the first time you need the
session bean and then store its reference in the HttpSession.  That's
the only way to make stateful session beans work at all and it doesn't
hurt stateless session beans.

Now this creates two problems.  1) You're dumping crap in the session,
which is bad for all the usual reasons and 2) stateful session beans
aren't guaranteed to be thread-safe.  That means if someone
double-posts a form they could end up with an error page.  It also may
cause problems with AJAX pages creating multiple concurrent requests.

These are major headaches that JBoss Seam was specifically designed to
address.  Now just to be clear, JSF makes me gag and I'm not trying to
pimp a framework I've never used.  What I am saying though, is that if
EJB 3 is a requirement for your app, Struts may not be the best
choice.

I'd be curious to hear if anyone has really pulled off good Java EE 5
integration.  I'd guess that the majority around here are using Spring
or Guice instead.

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


Re: Extending EJBInjection interceptor

Posted by Alexander Baetz <ba...@arcor.de>.
I hate to admit it, but i dont unterstand that question...

if it helps, i'm using JBoss 5 rc1 and the Interceptor i'm writing 
naturally runs in the same container as my struts application.

Greetings
Alexander

Martin Gainty schrieb:
> which EJB container are you using to implement the  @EJB functionality?
>
> Martin
> ______________________________________________ 
> Disclaimer and confidentiality note 
> Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 
>
>
>   
>> Date: Wed, 27 Aug 2008 19:16:53 +0200
>> From: baetz.paderborn@arcor.de
>> To: user@struts.apache.org
>> Subject: Re: Extending EJBInjection interceptor
>>
>> Correct me if i'm wrong but afaik beans (with bean-name) are defined via 
>> @stateless and @statefull and @entity
>> @EJB (in servelett context) does the injection for me.
>>
>> and this doesnt work with struts.
>>
>> based on the code from the plugin i thought i would have take care of 
>> the instances. but maybe this code was only inserted to save some 
>> lookups (otherwise i would do the lookup everytime).
>> If thats the case it begs the question if the lookup is that slow.
>>
>> Greetings
>> Alex
>>
>> Lukasz Lenart schrieb:
>>     
>>>> make my own Annotation type i wanted to use the javax.ejb.ejb anotation. But
>>>>     
>>>>         
>>> Maybe it will be better to use @Inject from xwork or something? The
>>> javax.ejb.ejb annotation are used to define EJBs itself not to be used
>>> for injecting them.
>>>
>>>
>>> Regards
>>>   
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>     
>
> _________________________________________________________________
> Get thousands of games on your PC, your mobile phone, and the web with Windows®.
> http://clk.atdmt.com/MRT/go/108588800/direct/01/
>   


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


RE: Extending EJBInjection interceptor

Posted by Martin Gainty <mg...@hotmail.com>.
which EJB container are you using to implement the  @EJB functionality?

Martin
______________________________________________ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. 


> Date: Wed, 27 Aug 2008 19:16:53 +0200
> From: baetz.paderborn@arcor.de
> To: user@struts.apache.org
> Subject: Re: Extending EJBInjection interceptor
> 
> Correct me if i'm wrong but afaik beans (with bean-name) are defined via 
> @stateless and @statefull and @entity
> @EJB (in servelett context) does the injection for me.
> 
> and this doesnt work with struts.
> 
> based on the code from the plugin i thought i would have take care of 
> the instances. but maybe this code was only inserted to save some 
> lookups (otherwise i would do the lookup everytime).
> If thats the case it begs the question if the lookup is that slow.
> 
> Greetings
> Alex
> 
> Lukasz Lenart schrieb:
> >> make my own Annotation type i wanted to use the javax.ejb.ejb anotation. But
> >>     
> >
> > Maybe it will be better to use @Inject from xwork or something? The
> > javax.ejb.ejb annotation are used to define EJBs itself not to be used
> > for injecting them.
> >
> >
> > Regards
> >   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Get thousands of games on your PC, your mobile phone, and the web with Windows®.
http://clk.atdmt.com/MRT/go/108588800/direct/01/

Re: Extending EJBInjection interceptor

Posted by Alexander Baetz <ba...@arcor.de>.
Correct me if i'm wrong but afaik beans (with bean-name) are defined via 
@stateless and @statefull and @entity
@EJB (in servelett context) does the injection for me.

and this doesnt work with struts.

based on the code from the plugin i thought i would have take care of 
the instances. but maybe this code was only inserted to save some 
lookups (otherwise i would do the lookup everytime).
If thats the case it begs the question if the lookup is that slow.

Greetings
Alex

Lukasz Lenart schrieb:
>> make my own Annotation type i wanted to use the javax.ejb.ejb anotation. But
>>     
>
> Maybe it will be better to use @Inject from xwork or something? The
> javax.ejb.ejb annotation are used to define EJBs itself not to be used
> for injecting them.
>
>
> Regards
>   


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


Re: Extending EJBInjection interceptor

Posted by Lukasz Lenart <lu...@googlemail.com>.
> make my own Annotation type i wanted to use the javax.ejb.ejb anotation. But

Maybe it will be better to use @Inject from xwork or something? The
javax.ejb.ejb annotation are used to define EJBs itself not to be used
for injecting them.


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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