@Override public boolean hasSession() { return request.getSession(false) != null; }
@Override public Session getSession() { return request.getSession(); }
public Session getSession() { return getSession(true); }
public void resetSession() { if (session == null) { return; } session.invalidate(); session = null; getSession(); }
@Override public void touchSession() { request.getSession().touch(); }
@Override public void invalidateSession() { request.getSession().invalidate(); }
@Override @SuppressWarnings("unchecked") public <T> T removeSession(String name) { return hasSession() ? (T) request.getSession().remove(name) : null; }
@Override @SuppressWarnings("unchecked") public <T> T getSession(String name) { return hasSession() ? (T) request.getSession().get(name) : null; }
public void recreateSession() { if (session == null) { return; } // preserve the session data Map<String, Object> values = new HashMap<>(); Enumeration<String> names = getSession().getNames(); while (names.hasMoreElements()) { String name = names.nextElement(); values.put(name, getSession().get(name)); } // preserve the flash data Flash flash = session.getFlash(); // create a new session resetSession(); // restore the session data for (Map.Entry<String, Object> entry : values.entrySet()) { getSession().put(entry.getKey(), entry.getValue()); } // restore the flash instance if (flash != null) { getSession().put("flash", flash); } }
@Override public void flashWarning(String message, Object... args) { request.getSession().getFlash().warning(message, args); }
public static Session get() { RouteContext routeContext = RouteDispatcher.getRouteContext(); return (routeContext != null) ? routeContext.getRequest().getSession(false) : null; }
@Override public void flashError(String message, Object... args) { request.getSession().getFlash().error(message, args); }
@Override public void flashInfo(String message, Object... args) { request.getSession().getFlash().info(message, args); }
@Override public void flashSuccess(String message, Object... args) { request.getSession().getFlash().success(message, args); }