• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Helper class or a Interceptor for calling EJB from a Action class

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This question is in extension to http://www.coderanch.com/t/320398/EJB-Other-Java-EE-Technologies/java/Integration-struts-x-with-Ejb

Jeanne Boyarsky ,

AS you said "have a helper layer that does the JNDI lookup" .This would be better .

Now i want to ask

1. Should i write this helper class as a Interceptor and integrate it with Struts 2 Framework ? OR

Do i write a individual class that will be responsible to do this operation ??

What approach will be better .

Waiting for your response .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this question deals with best practices for Struts 2 interceptors, I'm moving it to our Struts forum.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34229
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't done enough "real" work yet with either EJB 3 or Struts 2 to be sure of best practices. That said, I think it would be better to stay with the helper method approach to keep the scope as narrow as possible for the bean.

I look forward to reading replies to this thread to see if I am wrong.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It'd depend on how you want to use the helper class--the two solutions provided aren't mutually exclusive

If you were going to write an interceptor (to move the JNDI lookup out of the action--the interceptor would inject the results of the lookup into the action) you'd use the helper class from the interceptor. Or you can skip the interceptor and put the JNDI lookup in the action itself.

It may depend on how you'll be testing your action: by having the interceptor inject the result into the action you increase action testability in that you can inject whatever you want into the action from a test class regardless of how the "lookup" is actually done. For example, you might inject a stub interface implementation during testing, eliminating the need to set up JNDI lookup just for the test environment.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David thanks for your response. I found a open source Guice Struts 2 plug-in for this injection purpose .I decided to use that for temporarily .

Thanks for keeping answering my queries with Struts 2 Framework.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic