I have a GWT+GAE web app with several service and modules. I am using the module functionlity of mvp4g. All of my services extends:
public abstract class BaseServiceImpl extends RemoteServiceServlet {
protected final static Map USERS = new HashMap();
I use USERS to store my current active user sessions. Once I user authenticates himself I store his session id as a key of the map.
protected String getSessionId() {
return getThreadLocalRequest().getSession().getId();
}
public String authenticate(String username, String password) {
...
..
.
String id = getSessionId();
synchronized( this ) {
users.put(id, user);
}
...
..
.
For every request, I check if the user session is still valid.
protected boolean validUserSession() {
if(getThreadLocalRequest() == null) {
logger.log(Level.SEVERE, "Thread is null");
return false;
} else if(getThreadLocalRequest().getSession() == null) {
logger.log(Level.SEVERE, "Session is null");
return false;
}
String id = getSessionId();
UserJDO user = (UserJDO) users.get(id);
if(user==null) {
logger.log(Level.SEVERE, "User is null");
return false;
}
return true;
}
I have sessions enabled. Next I post the last lines of appengine-web.xml
...
..
.
<sessions-enabled>true</sessions-enabled>
</appengine-web-app>
Everything works fine in the Development server. However, when I deploy it to the google app engine cloud the users variable is reset for every request.
Can anyone explain me what it is happening? How should I proceed? Should I store the user sessions in the datastore?