wood burning stoves*
The moose likes Servlets and the fly likes Interesting session exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Interesting session exception" Watch "Interesting session exception" New topic
Author

Interesting session exception

Sudheesh
Greenhorn

Joined: Sep 22, 2005
Posts: 11
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..
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You've been warned numerous times, and so now I'm blocking your account from making further posts until you comply with our naming policy by going
here
and editing your display name to conform to the required "Firstname Lastname" format. You can send email or a private message to me to have your account reinstated once you've complied.

By the way -- I just deleted two duplicate copies of this message. Please Carefully Choose One Forum for your posts. Thanks.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Interesting session exception
 
Similar Threads
Proble with Relationship in Entity Bean
singleton
Problems with ejb reference.....
calling ejb from tomcat
ClassCastException when casting to home interface