this.servletContext = servletContext;
this.newSession = newSession;
}
public static HttpSessionImpl forSession(final Session session, final ServletContext servletContext, final boolean newSession) {
ServletRequestContext current = ServletRequestContext.current();
if (current == null) {
return new HttpSessionImpl(session, servletContext, newSession);
} else {
HttpSessionImpl httpSession = current.getSession();
if (httpSession == null) {
httpSession = new HttpSessionImpl(session, servletContext, newSession);
current.setSession(httpSession);
} else {
if(httpSession.session != session) {
//in some rare cases it may be that there are two different service contexts involved in the one request
//in this case we just return a new session rather than using the thread local version
httpSession = new HttpSessionImpl(session, servletContext, newSession);