Control http sessions on the server side

24 views
Skip to first unread message

Red_Dragon Red_Dragon

unread,
Dec 5, 2011, 2:49:59 PM12/5/11
to gwt-comet
Hi. I have a problem. Important for me to control the http sessions.
When break the session, I need to perform actions on the server side.
I wanted to use Window.addCloseHandler, but there is a bug (http://
code.google.com/p/google-web-toolkit/issues/detail?id=6088) which does
not guarantee RPC request when the window closes.
I think I need to follow the rupture of the sessions on the server
side.
How do I do? and I need to get the user name who broke the session.

login and logout are similar to the demo example.

@Override
public void login(String username) throws ChatException {
// Get or create the HTTP session for the browser
httpSession = getThreadLocalRequest().getSession();
// Get or create the Comet session for the browser
CometSession cometSession =
CometServlet.getCometSession(httpSession);
// Remember the user name for the
httpSession.setAttribute("username", username);

// setup the mapping of user names to CometSessions
if (users.putIfAbsent(username, cometSession) != null) {
// some one else has already logged in with this
user name
httpSession.invalidate();
throw new ChatException("User: " + username + "
already logged in");
}
}

@Override
public void logout(String username, int id) throws ChatException {
// check if there is a HTTP session setup.
httpSession = getThreadLocalRequest().getSession(false);
if (httpSession == null) {
throw new ChatException("User: " + username + " is
not logged in: no http session");
}

// check if there is a Comet session setup. In a larger
application the HTTP session may have been
// setup via other means.
CometSession cometSession =
CometServlet.getCometSession(httpSession, false);
if (cometSession == null) {
throw new ChatException("User: " + username + " is
not logged in: no comet session");
}

// check the user name parameter matches the HTTP sessions
user name
if (!
username.equals(httpSession.getAttribute("username"))) {
throw new ChatException("User: " + username + " is
not logged in on this session");
}

// remove the mapping of user name to CometSession
users.remove(username, cometSession);

xmppConList.get(id).disconnect();
}

Sorry for bad english =)

Reply all
Reply to author
Forward
0 new messages