HttpSession originalSession = getOriginalSession(false); if (originalSession != null) { String hazelcastSessionId = originalSessions.get(originalSession.getId()); String hazelcastSessionIdFromRequest = findHazelcastSessionIdFromRequest(); return readFromCookie();
path = config.getCookiePath(); } else { path = req.getContextPath();
private String findHazelcastSessionIdFromRequest() { String hzSessionId = null; final Cookie[] cookies = getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { final String name = cookie.getName(); final String value = cookie.getValue(); if (name.equalsIgnoreCase(config.getCookieName())) { hzSessionId = value; break; } } } // if hazelcast session id is not found on the cookie and using request parameter is enabled, look into // request parameters if (hzSessionId == null && config.isUseRequestParameter()) { hzSessionId = getParameter(config.getCookieName()); } return hzSessionId; } }
path = config.getCookiePath(); } else { path = req.getContextPath();
return hazelcastSession; HttpSession originalSession = getOriginalSession(false); if (originalSession != null) { String hazelcastSessionId = originalSessions.get(originalSession.getId()); return readFromCookie();
public String changeSessionId() { Method changeSessionIdMethod = getChangeSessionIdMethod(); if (changeSessionIdMethod == null) { return ""; } HttpServletRequest nonWrappedHttpServletRequest = getNonWrappedHttpServletRequest(); if (nonWrappedHttpServletRequest.getSession() == null) { throw new IllegalStateException("changeSessionId requested for request with no session"); } originalSessions.remove(nonWrappedHttpServletRequest.getSession().getId()); HazelcastHttpSession hazelcastHttpSession = getSession(false); sessions.remove(hazelcastHttpSession.getId()); hazelcastHttpSession.destroy(true); String newHazelcastSessionId = generateSessionId(); String newJSessionId = invokeChangeSessionId(nonWrappedHttpServletRequest, changeSessionIdMethod); HttpSession originalSession = nonWrappedHttpServletRequest.getSession(); HazelcastHttpSession hazelcastSession = createHazelcastHttpSession(newHazelcastSessionId, originalSession); hazelcastSession.setClusterWideNew(true); updateSessionMaps(newJSessionId, hazelcastSession); addSessionCookie(this, newHazelcastSessionId); return newJSessionId; }
protected HazelcastHttpSession createNewSession(HazelcastRequestWrapper requestWrapper, boolean create, String existingSessionId) { // use existing hazelcast session id for the new session only if the session info exists in the cluster boolean sessionExistsInTheCluster = sessionExistsInTheCluster(existingSessionId); if (!create && !sessionExistsInTheCluster) { return null; } String id = sessionExistsInTheCluster ? existingSessionId : generateSessionId(); if (requestWrapper.getOriginalSession(false) != null) { LOGGER.finest("Original session exists!!!"); } HttpSession originalSession = requestWrapper.getOriginalSession(true); HazelcastHttpSession hazelcastSession = createHazelcastHttpSession(id, originalSession); if (existingSessionId == null) { hazelcastSession.setClusterWideNew(true); // If the session is being created for the first time, add its initial reference in the cluster-wide map. } updateSessionMaps(originalSession.getId(), hazelcastSession); addSessionCookie(requestWrapper, id); return hazelcastSession; }
protected HazelcastHttpSession createNewSession(HazelcastRequestWrapper requestWrapper, boolean create, String existingSessionId) { // use existing hazelcast session id for the new session only if the session info exists in the cluster boolean sessionExistsInTheCluster = sessionExistsInTheCluster(existingSessionId); if (!create && !sessionExistsInTheCluster) { return null; } String id = sessionExistsInTheCluster ? existingSessionId : generateSessionId(); if (requestWrapper.getOriginalSession(false) != null) { LOGGER.finest("Original session exists!!!"); } HttpSession originalSession = requestWrapper.getOriginalSession(true); HazelcastHttpSession hazelcastSession = createHazelcastHttpSession(id, originalSession); if (existingSessionId == null) { hazelcastSession.setClusterWideNew(true); // If the session is being created for the first time, add its initial reference in the cluster-wide map. } updateSessionMaps(id, originalSession, hazelcastSession); addSessionCookie(requestWrapper, id); return hazelcastSession; }
private String findHazelcastSessionIdFromRequest() { String hzSessionId = null; final Cookie[] cookies = getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { final String name = cookie.getName(); final String value = cookie.getValue(); if (name.equalsIgnoreCase(config.getCookieName())) { hzSessionId = value; break; } } } // if hazelcast session id is not found on the cookie and using request parameter is enabled, look into // request parameters if (hzSessionId == null && config.isUseRequestParameter()) { hzSessionId = getParameter(config.getCookieName()); } return hzSessionId; } }
@Override public RequestDispatcher getRequestDispatcher(final String path) { final ServletRequest original = getRequest(); return new RequestDispatcher() { public void forward(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { original.getRequestDispatcher(path).forward(servletRequest, servletResponse); } public void include(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { original.getRequestDispatcher(path).include(servletRequest, servletResponse); } }; }
@Override public RequestDispatcher getRequestDispatcher(final String path) { final ServletRequest original = getRequest(); return new RequestDispatcher() { public void forward(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { original.getRequestDispatcher(path).forward(servletRequest, servletResponse); } public void include(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { original.getRequestDispatcher(path).include(servletRequest, servletResponse); } }; }
@Override public final void doFilter(ServletRequest req, ServletResponse res, final FilterChain chain) throws IOException, ServletException { HazelcastRequestWrapper requestWrapper = new HazelcastRequestWrapper((HttpServletRequest) req, (HttpServletResponse) res); chain.doFilter(requestWrapper, res); HazelcastHttpSession session = requestWrapper.getSession(false); if (session != null && session.isValid() && config.isDeferredWrite()) { if (LOGGER.isFinestEnabled()) { LOGGER.finest("UPDATING SESSION " + session.getId()); } session.sessionDeferredWrite(); } }
@Override public final void doFilter(ServletRequest req, ServletResponse res, final FilterChain chain) throws IOException, ServletException { HazelcastRequestWrapper requestWrapper = new HazelcastRequestWrapper((HttpServletRequest) req, (HttpServletResponse) res); chain.doFilter(requestWrapper, res); HazelcastHttpSession session = requestWrapper.getSession(false); if (session != null && session.isValid() && config.isDeferredWrite()) { if (LOGGER.isFinestEnabled()) { LOGGER.finest("UPDATING SESSION " + session.getId()); } session.sessionDeferredWrite(); } }
@Override public HttpSession getSession() { return getSession(true); }
@Override public HttpSession getSession() { return getSession(true); }
private HazelcastHttpSession readFromCookie() { String existingHazelcastSessionId = findHazelcastSessionIdFromRequest(); if (existingHazelcastSessionId != null) { hazelcastSession = getSessionWithId(existingHazelcastSessionId); if (hazelcastSession != null && !hazelcastSession.isStickySession()) { hazelcastSession.updateReloadFlag(); return hazelcastSession; } } return null; }
private HazelcastHttpSession readFromCookie() { String existingHazelcastSessionId = findHazelcastSessionIdFromRequest(); if (existingHazelcastSessionId != null) { hazelcastSession = getSessionWithId(existingHazelcastSessionId); if (hazelcastSession != null && !hazelcastSession.isStickySession()) { hazelcastSession.updateReloadFlag(); return hazelcastSession; } } return null; }
private HttpServletRequest getNonWrappedHttpServletRequest() { HttpServletRequest req = (HttpServletRequest) getRequest(); while (req instanceof HttpServletRequestWrapper) { req = (HttpServletRequest) ((HttpServletRequestWrapper) req).getRequest(); } return req; }
@Override public HazelcastHttpSession getSession(final boolean create) { hazelcastSession = readSessionFromLocal(); String hazelcastSessionId = findHazelcastSessionIdFromRequest(); if (hazelcastSession == null && !res.isCommitted() && (create || hazelcastSessionId != null)) { hazelcastSession = createNewSession(HazelcastRequestWrapper.this, create, hazelcastSessionId); } return hazelcastSession; }
HttpSession getOriginalSession(boolean create) { // Find the top non-wrapped Http Servlet request HttpServletRequest req = (HttpServletRequest) getRequest(); while (req instanceof HttpServletRequestWrapper) { req = (HttpServletRequest) ((HttpServletRequestWrapper) req).getRequest(); } if (req != null) { return req.getSession(create); } else { return super.getSession(create); } }