Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-04-08 Thread Piero Sartini
I coded this today, just used the field instead of a setter method. Your 
pseudo code was very helpful, thanks :-)

Maybe the following snippet is useful for someone with the same problem.
Should I post this on the wiki as well? I am not sure if it is a good 
solution - but it works for me.

Can someone please tell me if it is ok to call this every time an action needs 
the service, or would it be better to cache the service somewhere in 
application scope? I am quite new to this whole ejb thing.

Piero


 EJBInterceptor.java 
public class EJBInterceptor extends AbstractInterceptor implements Interceptor 
{
public String intercept(ActionInvocation actionInvocation) throws 
Exception {
Object action = actionInvocation.getAction();
for (Field f : action.getClass().getDeclaredFields()) {
if (f.isAnnotationPresent(EJB.class)) {
f.setAccessible(true);
String serviceName = f.getType().getName();
Object service = null;
try {
InitialContext ic = new InitialContext();
service = ic.lookup(serviceName);
} catch (Exception ex) {
System.out.println(Error: +ex.getMessage());
}
f.set(action, f.getType().cast(service));
break;
}
}
return actionInvocation.invoke();
}
}
 code 

 EJB.java 
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface EJB {
}
- code 


On Tuesday 23 January 2007 01:05:57 Ian Roughley wrote:
 I can't provide the code - it is owned my a client.  But here is the
 pseudo code:

 class EJB3Interceptor implements Interceptor {

public String intercept(ActionInvocation actionInvocation) throws
 java.lang.Exception {
 Object action = actionInvocation.getAction();
 for all methods {
   if( this is a setter and it is annotated as expected ) {
  look up the EJB
  set the EJB on the action
   }
}
 }

 }

  From here you would need to ensure that the interceptor is applied to
 the actions that need ejb's.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread papo

Hello

I am trying to find a way of calling efficienlty from Struts Actions - 
SLSBs EJB3. I have made a question before.


- Doing JNDI calls all the time through every action works though its a 
very primitive way of doing it.
-Tried to implement the Service locator pattern though the semantics on 
EJB3 are different (how to cache Intefaces, which interfaces)


I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency 
Injection for EJB3.



Will Struts 2.0 support such a feature if NOT can anyone point me the 
mechanics so to (try) doing it on my own.


I am bit stuck for days at this very point of efficiently glue-ing 
Struts and my EJB3 Business layer


Any hint would be much appreciated!




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Ian Roughley
Currently there is no EJB3 support in Struts, however I have done this 
on a couple of projects.  I used a custom annotation to mark action 
setters as ejb3 then a custom interceptor that looks for the annotation, 
looks up the ejb3 and injects it into the action.  Doing it this way is 
less than a days work.


Another option would be to replace the ObjectFactory (the class that 
does the dependency injection) with a a custom implementation that does 
EJB3 dependency injection.


/Ian

--

From Down  Around, Inc.

Innovative IT Solutions
Software Architecture * Design * Development
~
web:  www.fdar.com  
email [EMAIL PROTECTED]  
phone:617.821.5430

~



papo wrote:

Hello

I am trying to find a way of calling efficienlty from Struts Actions 
- SLSBs EJB3. I have made a question before.


- Doing JNDI calls all the time through every action works though its 
a very primitive way of doing it.
-Tried to implement the Service locator pattern though the semantics 
on EJB3 are different (how to cache Intefaces, which interfaces)


I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency 
Injection for EJB3.



Will Struts 2.0 support such a feature if NOT can anyone point me the 
mechanics so to (try) doing it on my own.


I am bit stuck for days at this very point of efficiently glue-ing 
Struts and my EJB3 Business layer


Any hint would be much appreciated!




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Stas Ostapenko

Hi !

Ian, can you provide some kind of example source code to play with ?
I'm interesting in Struts 2 and EJB 3 interoperability, but I can't
figure out how to get started. Thanks !


On 1/22/07, Ian Roughley [EMAIL PROTECTED] wrote:

Currently there is no EJB3 support in Struts, however I have done this
on a couple of projects.  I used a custom annotation to mark action
setters as ejb3 then a custom interceptor that looks for the annotation,
looks up the ejb3 and injects it into the action.  Doing it this way is
less than a days work.

Another option would be to replace the ObjectFactory (the class that
does the dependency injection) with a a custom implementation that does
EJB3 dependency injection.

/Ian

--
From Down  Around, Inc.
Innovative IT Solutions
Software Architecture * Design * Development
~
web:  www.fdar.com
email [EMAIL PROTECTED]
phone:617.821.5430
~



papo wrote:
 Hello

 I am trying to find a way of calling efficienlty from Struts Actions
 - SLSBs EJB3. I have made a question before.

 - Doing JNDI calls all the time through every action works though its
 a very primitive way of doing it.
 -Tried to implement the Service locator pattern though the semantics
 on EJB3 are different (how to cache Intefaces, which interfaces)

 I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency
 Injection for EJB3.


 Will Struts 2.0 support such a feature if NOT can anyone point me the
 mechanics so to (try) doing it on my own.

 I am bit stuck for days at this very point of efficiently glue-ing
 Struts and my EJB3 Business layer

 Any hint would be much appreciated!




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Paris Apostolopoulos

Hi again.

Ian thank you for your reply.

If I understood well, please pardon me...if it is wrong the following 
you said


1) implement your custom ejb3 annotations into struts ok
I wonder the @EJB annotations are not going to work (I guess). I had a 
look @ some glassfish FAQ..


2)Then implement Struts interceptors that are going to do the JNDI 
lookup?right?


I have to admit I am bit confused


My first attempt was to implement the classical ServiceLocator Pattern 
and stick it with delegates, though the pattern does not fit well with EJB3.


Any hint from the Struts team ..is there any intention to implement that 
kind of support to Struts (Struts 2+ EJB3) integration? Or do you know 
any other extention project that is targeting this way..maybe we could 
contribute.


At the moment this kind of problem does not make me fee confortable, I 
am a great Struts supporter(picked Struts as the web framework for our 
new j2ee web app) and its a pitty EJB3.0 is targeted towards either

plain servlets or JSF for Dependency Injection etc etc.

Any more hints if possible would be much appreciated!

Thanks




Stas Ostapenko wrote:

Hi !

Ian, can you provide some kind of example source code to play with ?
I'm interesting in Struts 2 and EJB 3 interoperability, but I can't
figure out how to get started. Thanks !


On 1/22/07, Ian Roughley [EMAIL PROTECTED] wrote:

Currently there is no EJB3 support in Struts, however I have done this
on a couple of projects.  I used a custom annotation to mark action
setters as ejb3 then a custom interceptor that looks for the annotation,
looks up the ejb3 and injects it into the action.  Doing it this way is
less than a days work.

Another option would be to replace the ObjectFactory (the class that
does the dependency injection) with a a custom implementation that does
EJB3 dependency injection.

/Ian

--
From Down  Around, Inc.
Innovative IT Solutions
Software Architecture * Design * Development
~
web:  www.fdar.com
email [EMAIL PROTECTED]
phone:617.821.5430
~



papo wrote:
 Hello

 I am trying to find a way of calling efficienlty from Struts Actions
 - SLSBs EJB3. I have made a question before.

 - Doing JNDI calls all the time through every action works though its
 a very primitive way of doing it.
 -Tried to implement the Service locator pattern though the semantics
 on EJB3 are different (how to cache Intefaces, which interfaces)

 I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency
 Injection for EJB3.


 Will Struts 2.0 support such a feature if NOT can anyone point me the
 mechanics so to (try) doing it on my own.

 I am bit stuck for days at this very point of efficiently glue-ing
 Struts and my EJB3 Business layer

 Any hint would be much appreciated!




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Joe Germuska

While I have not used it, the Spring Framework provides strategies for
defining Spring Beans which are EJB factories (or something like that.)
Struts 2 works quite nicely using Spring as the Action Factory, which can
take care of resolving all Action dependencies whether or not they are EJBs.

See
http://cwiki.apache.org/S2PLUGINS/spring-plugin.html
for more on using Spring as your object factory

and this Spring documentation on EJBs:
http://www.springframework.org/docs/reference/ejb.html

Hope that helps.

Joe


On 1/22/07, Paris Apostolopoulos [EMAIL PROTECTED] wrote:


Hi again.

Ian thank you for your reply.

If I understood well, please pardon me...if it is wrong the following
you said

1) implement your custom ejb3 annotations into struts ok
I wonder the @EJB annotations are not going to work (I guess). I had a
look @ some glassfish FAQ..

2)Then implement Struts interceptors that are going to do the JNDI
lookup?right?

I have to admit I am bit confused


My first attempt was to implement the classical ServiceLocator Pattern
and stick it with delegates, though the pattern does not fit well with
EJB3.

Any hint from the Struts team ..is there any intention to implement that
kind of support to Struts (Struts 2+ EJB3) integration? Or do you know
any other extention project that is targeting this way..maybe we could
contribute.

At the moment this kind of problem does not make me fee confortable, I
am a great Struts supporter(picked Struts as the web framework for our
new j2ee web app) and its a pitty EJB3.0 is targeted towards either
plain servlets or JSF for Dependency Injection etc etc.

Any more hints if possible would be much appreciated!

Thanks




Stas Ostapenko wrote:
 Hi !

 Ian, can you provide some kind of example source code to play with ?
 I'm interesting in Struts 2 and EJB 3 interoperability, but I can't
 figure out how to get started. Thanks !


 On 1/22/07, Ian Roughley [EMAIL PROTECTED] wrote:
 Currently there is no EJB3 support in Struts, however I have done this
 on a couple of projects.  I used a custom annotation to mark action
 setters as ejb3 then a custom interceptor that looks for the
annotation,
 looks up the ejb3 and injects it into the action.  Doing it this way is
 less than a days work.

 Another option would be to replace the ObjectFactory (the class that
 does the dependency injection) with a a custom implementation that does
 EJB3 dependency injection.

 /Ian

 --
 From Down  Around, Inc.
 Innovative IT Solutions
 Software Architecture * Design * Development
 ~
 web:  www.fdar.com
 email [EMAIL PROTECTED]
 phone:617.821.5430
 ~



 papo wrote:
  Hello
 
  I am trying to find a way of calling efficienlty from Struts Actions
  - SLSBs EJB3. I have made a question before.
 
  - Doing JNDI calls all the time through every action works though its
  a very primitive way of doing it.
  -Tried to implement the Service locator pattern though the semantics
  on EJB3 are different (how to cache Intefaces, which interfaces)
 
  I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency
  Injection for EJB3.
 
 
  Will Struts 2.0 support such a feature if NOT can anyone point me the
  mechanics so to (try) doing it on my own.
 
  I am bit stuck for days at this very point of efficiently glue-ing
  Struts and my EJB3 Business layer
 
  Any hint would be much appreciated!
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
Joe Germuska
[EMAIL PROTECTED] * http://blog.germuska.com

The truth is that we learned from João forever to be out of tune.
-- Caetano Veloso


RE: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Wesslan
I've never used it either but I know from other peoples experience that it
works great for EJB 2.1.
I don't know how good it supports Ejb 3 though but you can always ask at 
http://forum.springframework.org/forumdisplay.php?f=29.

Cheers,
Peter

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Joe
Germuska
Sent: den 22 januari 2007 15:47
To: Struts Users Mailing List
Subject: Re: [s2] Struts Dependency Injection and EJB3 - support ? or how
can i Do it?

While I have not used it, the Spring Framework provides strategies for
defining Spring Beans which are EJB factories (or something like that.)
Struts 2 works quite nicely using Spring as the Action Factory, which can
take care of resolving all Action dependencies whether or not they are EJBs.

See
http://cwiki.apache.org/S2PLUGINS/spring-plugin.html
for more on using Spring as your object factory

and this Spring documentation on EJBs:
http://www.springframework.org/docs/reference/ejb.html

Hope that helps.

Joe


On 1/22/07, Paris Apostolopoulos [EMAIL PROTECTED] wrote:

 Hi again.

 Ian thank you for your reply.

 If I understood well, please pardon me...if it is wrong the following 
 you said

 1) implement your custom ejb3 annotations into struts ok I wonder the 
 @EJB annotations are not going to work (I guess). I had a look @ some 
 glassfish FAQ..

 2)Then implement Struts interceptors that are going to do the JNDI 
 lookup?right?

 I have to admit I am bit confused


 My first attempt was to implement the classical ServiceLocator Pattern 
 and stick it with delegates, though the pattern does not fit well with 
 EJB3.

 Any hint from the Struts team ..is there any intention to implement 
 that kind of support to Struts (Struts 2+ EJB3) integration? Or do you 
 know any other extention project that is targeting this way..maybe we 
 could contribute.

 At the moment this kind of problem does not make me fee confortable, I 
 am a great Struts supporter(picked Struts as the web framework for our 
 new j2ee web app) and its a pitty EJB3.0 is targeted towards either 
 plain servlets or JSF for Dependency Injection etc etc.

 Any more hints if possible would be much appreciated!

 Thanks




 Stas Ostapenko wrote:
  Hi !
 
  Ian, can you provide some kind of example source code to play with ?
  I'm interesting in Struts 2 and EJB 3 interoperability, but I can't 
  figure out how to get started. Thanks !
 
 
  On 1/22/07, Ian Roughley [EMAIL PROTECTED] wrote:
  Currently there is no EJB3 support in Struts, however I have done 
  this on a couple of projects.  I used a custom annotation to mark 
  action setters as ejb3 then a custom interceptor that looks for the
 annotation,
  looks up the ejb3 and injects it into the action.  Doing it this 
  way is less than a days work.
 
  Another option would be to replace the ObjectFactory (the class 
  that does the dependency injection) with a a custom implementation 
  that does
  EJB3 dependency injection.
 
  /Ian
 
  --
  From Down  Around, Inc.
  Innovative IT Solutions
  Software Architecture * Design * Development 
  ~
  web:  www.fdar.com
  email [EMAIL PROTECTED]
  phone:617.821.5430
  ~
 
 
 
  papo wrote:
   Hello
  
   I am trying to find a way of calling efficienlty from Struts 
   Actions
   - SLSBs EJB3. I have made a question before.
  
   - Doing JNDI calls all the time through every action works though 
   its a very primitive way of doing it.
   -Tried to implement the Service locator pattern though the 
   semantics on EJB3 are different (how to cache Intefaces, which 
   interfaces)
  
   I know tha EJB3 on the web layer Serlvets/ JSF supports 
   Dependency Injection for EJB3.
  
  
   Will Struts 2.0 support such a feature if NOT can anyone point me 
   the mechanics so to (try) doing it on my own.
  
   I am bit stuck for days at this very point of efficiently 
   glue-ing Struts and my EJB3 Business layer
  
   Any hint would be much appreciated!
  
  
  
  
   -
    To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
 
  ---
  -- To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
  
  - To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




--
Joe Germuska
[EMAIL PROTECTED] * http://blog.germuska.com

The truth is that we learned from João forever to be out of tune.
-- Caetano Veloso

Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Craig McClanahan

On 1/22/07, Paris Apostolopoulos [EMAIL PROTECTED] wrote:


[snip]
I wonder the @EJB annotations are not going to work (I guess). I had a
look @ some glassfish FAQ..




The standard annotations for Java EE 5 resource injection are indeed *not*
going to work on a Struts action, because they only work on
container-created objects (servlets, filters, listeners, and JSF managed
beans).  You'll want to look at a custom interceptor solution (as described
in this thread), continuing to use JNDI lookups, or perhaps using an
alternative resource injection framework like Spring.

Craig


Re: [s2] Struts Dependency Injection and EJB3 - support ? or how can i Do it?

2007-01-22 Thread Ian Roughley
I can't provide the code - it is owned my a client.  But here is the 
pseudo code:


class EJB3Interceptor implements Interceptor {

  public String intercept(ActionInvocation actionInvocation) throws 
java.lang.Exception {

   Object action = actionInvocation.getAction();
   for all methods {
 if( this is a setter and it is annotated as expected ) {
look up the EJB
set the EJB on the action
 }
  }
   }

}

From here you would need to ensure that the interceptor is applied to 
the actions that need ejb's.


--

From Down  Around, Inc.

Innovative IT Solutions
Software Architecture * Design * Development
~
web:  www.fdar.com  
email [EMAIL PROTECTED]  
phone:617.821.5430

~



Paris Apostolopoulos wrote:

Hi again.

Ian thank you for your reply.

If I understood well, please pardon me...if it is wrong the following 
you said


1) implement your custom ejb3 annotations into struts ok
I wonder the @EJB annotations are not going to work (I guess). I had a 
look @ some glassfish FAQ..


2)Then implement Struts interceptors that are going to do the JNDI 
lookup?right?


I have to admit I am bit confused


My first attempt was to implement the classical ServiceLocator Pattern 
and stick it with delegates, though the pattern does not fit well with 
EJB3.


Any hint from the Struts team ..is there any intention to implement 
that kind of support to Struts (Struts 2+ EJB3) integration? Or do you 
know any other extention project that is targeting this way..maybe we 
could contribute.


At the moment this kind of problem does not make me fee confortable, I 
am a great Struts supporter(picked Struts as the web framework for our 
new j2ee web app) and its a pitty EJB3.0 is targeted towards either

plain servlets or JSF for Dependency Injection etc etc.

Any more hints if possible would be much appreciated!

Thanks




Stas Ostapenko wrote:

Hi !

Ian, can you provide some kind of example source code to play with ?
I'm interesting in Struts 2 and EJB 3 interoperability, but I can't
figure out how to get started. Thanks !


On 1/22/07, Ian Roughley [EMAIL PROTECTED] wrote:

Currently there is no EJB3 support in Struts, however I have done this
on a couple of projects.  I used a custom annotation to mark action
setters as ejb3 then a custom interceptor that looks for the 
annotation,

looks up the ejb3 and injects it into the action.  Doing it this way is
less than a days work.

Another option would be to replace the ObjectFactory (the class that
does the dependency injection) with a a custom implementation that does
EJB3 dependency injection.

/Ian

--
From Down  Around, Inc.
Innovative IT Solutions
Software Architecture * Design * Development
~
web:  www.fdar.com
email [EMAIL PROTECTED]
phone:617.821.5430
~



papo wrote:
 Hello

 I am trying to find a way of calling efficienlty from Struts Actions
 - SLSBs EJB3. I have made a question before.

 - Doing JNDI calls all the time through every action works though its
 a very primitive way of doing it.
 -Tried to implement the Service locator pattern though the semantics
 on EJB3 are different (how to cache Intefaces, which interfaces)

 I know tha EJB3 on the web layer Serlvets/ JSF supports Dependency
 Injection for EJB3.


 Will Struts 2.0 support such a feature if NOT can anyone point me the
 mechanics so to (try) doing it on my own.

 I am bit stuck for days at this very point of efficiently glue-ing
 Struts and my EJB3 Business layer

 Any hint would be much appreciated!




 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]