Re: RE: Accessing EJB references by extending ActionServlet

2002-01-09 Thread srajan

Thanks for the reply. I was planning to put the look up of the EJB 
reference in the init method of the servlet, so unless Iam missing 
something, It should be thread safe. I looked at the java pet store 
source code specifically at WebControllerImpl. I found that , it looks 
up the EJB reference in a non synchronized method. All the other 
methods that access the EJB are synchronized, Does that mean lookups in 
general are thread safe? 

Appreciate your help,
Sunder

- Original Message -
From: James Dasher [EMAIL PROTECTED]
Date: Tuesday, January 8, 2002 7:20 pm
Subject: RE: Accessing EJB references by extending ActionServlet

 Uh, careful--synchronization issues (immediate problem) and data
 abstraction (long term problem).
 Servlets are not thread-safe, so be very careful handing that 
 referencearound.
 
 Also, do you want your struts stuff knowing about EJB?  EJB is
 complicated.
 
 Possible alternatives:
 1.  Use session-scope beans as web-tier Helpers, abstracting data-
 accessimplementation.  (Your actions don't really need to know how 
 to use an
 EJB, do they?)
 2.  Consider adding a service locator, which implements
 HttpSessionListener, which binds itself in session and knows how to
 get/create above Helper objects
 3.  Value object are a pretty good idea, too.
 4.  (Extreme)  Have a single point of entry into the EJB tier, a
 controller which has one operant method, something like

public synchronized ModificationResponse
 handleModification(Modification Request) {}
 
public interface ModificationRequest {
public String getName();
}

public interface ModifcationResponse {
public Object getPayload();
}
 
Your controller (a stateful EJB) can delegate to various other
 EJB's based on an XML file or environment entries with
 ModificationRequest.getName() as the key.
 
Your Data-Access Objects can take that response, grab the
 payload, and put it in session as needs be.
 
 Then your actions can just grab what they need likewise: 
Locator l =
 (Locator)request.getSession().getAttribute(Keys.SERVICE_LOCATOR)
Carthelper c = l.getCartWebhelper();

 request.setSessionAttribute(Keys.SHOPPING_CART,c.addStuffToCart
(someItem
 ))
where addStuffToCart returns some kind of Value Object
 you can expose as a bean.  Meanwhile, your cart has been updated 
 back in
 the EJB's somewhere.
 
 Most of this is ripped straight from the pages of the petstore 
 demo Web
 Application Framework.  If you haven't read it, it is worth it.  The
 part you are looking for is 
 
  petstore1.3/src/waf/src/controller/com/sun/j2ee/blueprints/waf
 
 Remember--Sun pushes EJB so you buy bigger appservers.  Basically, 90%
 of the projects using EJB don't have to.  If you are in the other 10%,
 then your project is large-scale enough to merit some extra time
 thinking about data abstraction.
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
 Sent: Tuesday, January 08, 2002 9:17 PM
 To: Struts Users Mailing List
 Subject: Accessing EJB references by extending ActionServlet
 
 
 Hello,
 I have a design question about accessing EJB references from the 
 servlet. I would like to obtain a reference to my proxy session 
 bean in 
 the init of the servlet and use that reference to call methods on 
 the 
 bean from the action classes. I have extended the ActionServlet 
 and 
 added additional code to the init method for the EJB lookup. I 
 would 
 like to know how I can pass the remote reference across the 
 different 
 action classes? I am not sure if putting the remote reference in 
 session would be a good idea. I have all my action classes extend 
 from 
 the new ExtendedActionServlet
 
 Sunder
 
 
 
 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 
 


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




RE: Accessing EJB references by extending ActionServlet

2002-01-08 Thread James Dasher

Uh, careful--synchronization issues (immediate problem) and data
abstraction (long term problem).
Servlets are not thread-safe, so be very careful handing that reference
around.

Also, do you want your struts stuff knowing about EJB?  EJB is
complicated.

Possible alternatives:
1.  Use session-scope beans as web-tier Helpers, abstracting data-access
implementation.  (Your actions don't really need to know how to use an
EJB, do they?)
2.  Consider adding a service locator, which implements
HttpSessionListener, which binds itself in session and knows how to
get/create above Helper objects
3.  Value object are a pretty good idea, too.
4.  (Extreme)  Have a single point of entry into the EJB tier, a
controller which has one operant method, something like

public synchronized ModificationResponse
handleModification(Modification Request) {}

public interface ModificationRequest {
public String getName();
}

public interface ModifcationResponse {
public Object getPayload();
}

Your controller (a stateful EJB) can delegate to various other
EJB's based on an XML file or environment entries with
ModificationRequest.getName() as the key.

Your Data-Access Objects can take that response, grab the
payload, and put it in session as needs be.

Then your actions can just grab what they need likewise: 
Locator l =
(Locator)request.getSession().getAttribute(Keys.SERVICE_LOCATOR)
Carthelper c = l.getCartWebhelper();

request.setSessionAttribute(Keys.SHOPPING_CART,c.addStuffToCart(someItem
))
where addStuffToCart returns some kind of Value Object
you can expose as a bean.  Meanwhile, your cart has been updated back in
the EJB's somewhere.

Most of this is ripped straight from the pages of the petstore demo Web
Application Framework.  If you haven't read it, it is worth it.  The
part you are looking for is 

  petstore1.3/src/waf/src/controller/com/sun/j2ee/blueprints/waf

Remember--Sun pushes EJB so you buy bigger appservers.  Basically, 90%
of the projects using EJB don't have to.  If you are in the other 10%,
then your project is large-scale enough to merit some extra time
thinking about data abstraction.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 08, 2002 9:17 PM
To: Struts Users Mailing List
Subject: Accessing EJB references by extending ActionServlet


Hello,
I have a design question about accessing EJB references from the 
servlet. I would like to obtain a reference to my proxy session bean in 
the init of the servlet and use that reference to call methods on the 
bean from the action classes. I have extended the ActionServlet and 
added additional code to the init method for the EJB lookup. I would 
like to know how I can pass the remote reference across the different 
action classes? I am not sure if putting the remote reference in 
session would be a good idea. I have all my action classes extend from 
the new ExtendedActionServlet

Sunder



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


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