|
Re: Jetty Cross Context Session Sharing [message #1727858 is a reply to message #1727526] |
Mon, 28 March 2016 11:28  |
Eclipse User |
|
|
|
My solution was to extend the HashSessionManager so that it queries the SessionIdManager before creating a new session. The result is that WebAppContext instances share session contents instead of just session ids.
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.eclipse.jetty.server.session.AbstractSession;
import org.eclipse.jetty.server.session.HashSessionIdManager;
import org.eclipse.jetty.server.session.HashSessionManager;
/**
* Allows the WebAppContext to check the server's SessionIdManager before creating a new session
* so that WebAppContext can share session contents for each client rather than just session ids.
*/
public class CrossContextSessionManager extends HashSessionManager {
/**
* Check for an existing session in the session id manager by the requested id.
* If no session has that id, create a new HttpSession for the request.
*/
@Override
public HttpSession newHttpSession(HttpServletRequest request) {
AbstractSession session = null;
String requestedId = request.getRequestedSessionId();
if (requestedId != null) {
String clusterId = getSessionIdManager().getClusterId(requestedId);
Collection<HttpSession> sessions = ((HashSessionIdManager) getSessionIdManager()).getSession(clusterId);
for (HttpSession httpSession : sessions) {
session = (AbstractSession) httpSession;
break;
}
}
if (session == null) {
session = newSession(request);
session.setMaxInactiveInterval(_dftMaxIdleSecs);
addSession(session,true);
}
return session;
}
}
[Updated on: Mon, 28 March 2016 17:08] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05465 seconds