I am working on an enterprise application (EJB 2.1). In this app, whenever a user login, it is creating remote interface of a Stateless Session Bean and storing it in Session as an attribute.
This is the pseudo code:
HttpSession httpSession = null; // user's session
MyEjb myEjb = null; // Remote interface of EJB
// get session of the user
httpSession = ...;
// create remote interface of EJB
myEjb = ...;
// store remote interface of EJB in Session as an attribute
httpSession.setAttribute("MyEjb", myEjb);
Then for each EJB call it first gets the remote interface from the Session and then use it.
HttpSession httpSession = null; // user's session
MyEjb myEjb = null; // Remote interface of EJB
// get session of the user
httpSession = ...;
// get remote interface of EJB from session
myEjb = (MyEjb) httpSession.getAttribute("MyEjb");
// use the EJB
What are the pros of cons of using this approach? Does it make sense? Thanks