private PippoHttpSession createSession(SessionData sessionData) { return new PippoHttpSession(sessionData, getServletContext()) { @Override public void onInvalidate() { currentSession = null; getSessionDataStorage().delete(getId()); } }; }
@Override public HttpSession getSession() { return getSession(true); }
private boolean isInvalidateClientSession() { return (currentSession == null) && isRequestedSessionIdValid(); }
public void commitSession(HttpServletResponse response) { // System.out.println("SessionHttpServletRequest.commitSession"); PippoHttpSession wrappedSession = currentSession; if (wrappedSession == null) { if (isInvalidateClientSession()) { getSessionStrategy().onInvalidatedSession(this, response); } } else { SessionData sessionData = wrappedSession.getSessionData(); getSessionDataStorage().save(sessionData); if (!isRequestedSessionIdValid() || !sessionData.getId().equals(getRequestedSessionId())) { getSessionStrategy().onNewSession(this, response, sessionData); } } }
@Override public boolean isRequestedSessionIdValid() { if (requestedSessionIdValid == null) { String sessionId = getRequestedSessionId(); SessionData sessionData = (sessionId != null) ? getSessionDataStorage().get(sessionId) : null; return isRequestedSessionIdValid(sessionData); } return super.isRequestedSessionIdValid(); }
@Override public HttpSession getSession(boolean create) { if (currentSession != null) { return currentSession; } String requestedSessionId = getRequestedSessionId(); if (requestedSessionId != null) { SessionData session = getSessionDataStorage().get(requestedSessionId); if (session != null) { requestedSessionIdValid = true; currentSession = createSession(session); currentSession.setNew(false); return currentSession; } } if (!create) { return null; } SessionData session = getSessionDataStorage().create(); currentSession = createSession(session); return currentSession; }
@Override public RequestResponse createRequestResponse(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { SessionHttpServletRequest sessionHttpServletRequest = new SessionHttpServletRequest(httpServletRequest, sessionManager); Request request = new Request(sessionHttpServletRequest, application); Response response = new Response(httpServletResponse, application); response.getFinalizeListeners().add(r -> sessionHttpServletRequest.commitSession(httpServletResponse)); return new RequestResponse(request, response); }
@Override public String getRequestedSessionId() { return getSessionStrategy().getRequestedSessionId(this); }