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 =)