protected SessionStore lookSessionStore() { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); SessionStore store = (SessionStore) wac.getBean("sessionStore", SessionStore.class); if (logger.isInfoEnabled()) { logger.info( "Using '" + store.getClass().getSimpleName() + "' SessionStore for HttpSessionStoreFilter"); } return store; }
private Map loadSessionData(String sessionId, HttpSession rawSession) { Map sessionData = null; try { sessionData = sessionStore.getSession(sessionId, rawSession.getMaxInactiveInterval()); } catch (Exception e) { sessionData = new HashMap(); log.warn("load session data error,cause:" + e, e); } return sessionData; }
@Override protected void doFilterInternal( HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { Cookie sessionIdCookie = getOrGenerateSessionId(request, response); String sessionId = sessionIdCookie.getValue(); HttpSession rawSession = request.getSession(); Map sessionData = loadSessionData(sessionId, rawSession); try { HttpSession sessionWrapper = new HttpSessionSessionStoreWrapper(rawSession, sessionStore, sessionId, sessionData); chain.doFilter(new HttpServletRequestSessionWrapper(request, sessionWrapper), response); } finally { try { sessionStore.saveSession(sessionId, sessionData, rawSession.getMaxInactiveInterval()); } catch (Exception e) { log.warn("save session data error,cause:" + e, e); } } }