Dear sirs,
I am getting some interesting Session scope Exception..
I am using the technology
Struts,
EJB with
JBoss I am using Session Facade and Service Locator as desin
pattern Now the scenario is given below,
I am requesting for a collection of Entity Bean by passing the request as given below,
Action Class -> Session Bean (Stateless) -> Service Locator -> Entity Bean(CMP)
I am extending my action class with
org.apache.struts.actions.DispatchAction When two users of different sessions are logging in to the application and accessing the same collection; only one user is getting the Collection.
I tried to print the session ID ob each users at the console. Before the request is made the session id of each user is different as given below,
User 1 : 257B112049648471974498E34F9B1EDC
User 2 : A674D5852CB31EA975929E833E5C90B4
But after getting the collection from the bean; when i printedthe session ID along with the Collection size; the console is printing the same session for both request as given below,
1. showMessage positionMap.size()==> 124 <=> Session Id A674D5852CB31EA975929E833E5C90B4
2. showMessage positionMap.size()==> 124 <=> Session Id A674D5852CB31EA975929E833E5C90B4
This means that the user with session "257B112049648471974498E34F9B1EDC" is not getting the collection. This problem is occuring when both users are requesting for the same collection simultaneously, I checked the beam part and service locator part. I think they are working fine.
The ServiceLocator Code is given below...
public class ServiceLocator implements ServiceNames{
private static ServiceLocator serviceLocator = null;
private static Hashtable<
String,Object> ejbHomeCache = null;
private static Hashtable<String,DataSource> dataBaseCache = null;
static{
serviceLocator = new ServiceLocator();
}
private ServiceLocator(){
ejbHomeCache = new Hashtable<String,Object>();
dataBaseCache = new Hashtable<String,DataSource>();
}
public static ServiceLocator getInstance(){
return serviceLocator;
}
private static EJBHome getEJBHome(String serviceName, Class ejbHomeClass){
EJBHome ejbHome = null;
try{
if(ejbHomeCache.containsKey(serviceName)){
System.out.println("%%%%%%%%%%%%%%%%%%%%%% from ejbHomeCache Remote HashTable");
return((EJBHome)ejbHomeCache.get(serviceName));
}else{
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
InitialContext ctx = new InitialContext(properties);
Context ctx = new InitialContext();
Object jndiRef = ctx.lookup(serviceName);
Object objRef = PortableRemoteObject.narrow(jndiRef,ejbHomeClass);
ejbHomeCache.put(serviceName, objRef);
return ((EJBHome)objRef);
}
}catch(Exception e){
System.out.println("Error in getRemoteEJBHome()-Remote in finding Remote EJBHome ");
e.printStackTrace();
}
return null;
}
private static EJBLocalHome getEJBHome(String serviceName){
EJBLocalHome ejbHome = null;
try{
if(ejbHomeCache.containsKey(serviceName)){
System.out.println("%%%%%%%%%%%%%%%%%%%%%% from ejbHomeCache HashTable");
return((EJBLocalHome)ejbHomeCache.get(serviceName));
}else{
Context ctx = new InitialContext();
Object objRef = (EJBLocalHome)ctx.lookup(serviceName);
ejbHomeCache.put(serviceName,objRef);
return ((EJBLocalHome)objRef);
}
}catch(Exception e){
System.out.println("Error in getEJBHome()-Local in finding Remote EJBHome ");
e.printStackTrace();
}
return null;
}
public static ImportsVzaHeaderLocalHome getVzaHeaderLocalHome(){
ImportsVzaHeaderLocalHome vzaHeaderHome = null;
try{
vzaHeaderHome = (ImportsVzaHeaderLocalHome)getEJBHome(VZAHeaderLocal);
}catch(Exception e){
System.out.println("From ServiceLocator's getVzaHeaderHome method Exception in finding the VzaHeaderHome ");
e.printStackTrace();
}
return vzaHeaderHome;
}
}
/************************************END Of ServiceLocator *************************************************************/
Your help and suggestions solicited..