@Override public String getOrCreateSessionId(PippoWebContext pippoWebContext) { return getSession(pippoWebContext).getId(); }
public void resetSession() { if (session == null) { return; } session.invalidate(); session = null; getSession(); }
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); } }
public <T> T remove(String name) { T t = get(name); httpSession.removeAttribute(name); return t; }
@Override public <T> T setSession(String name, T value) { getSession().put(name, value); return value; }
@Override @SuppressWarnings("unchecked") public <T> T removeSession(String name) { return hasSession() ? (T) request.getSession().remove(name) : null; }
@Override public void flashSuccess(String message, Object... args) { request.getSession().getFlash().success(message, args); }
public Session getSession(boolean create) { if (session == null) { HttpSession httpSession = httpServletRequest.getSession(create); if (httpSession != null) { session = new Session(httpSession); } } return session; }
@Override public Object get(PippoWebContext pippoWebContext, String name) { return getSession(pippoWebContext).get(name); }
@Override public void flashWarning(String message, Object... args) { request.getSession().getFlash().warning(message, args); }
protected String getTokenId(RouteContext context) { return context.getSession().getId().toString(); }
@Override @SuppressWarnings("unchecked") public <T> T getSession(String name) { return hasSession() ? (T) request.getSession().get(name) : null; }
@Override public boolean destroySession(PippoWebContext pippoWebContext) { getSession(pippoWebContext).invalidate(); return true; }
@Override public void flashError(String message, Object... args) { request.getSession().getFlash().error(message, args); }
protected String getTokenId(Context context) { return context.getSession().getId().toString(); }
/** * Renders a template to a {@link String}. * * @param templateName * @param model */ public String renderToString(String templateName, Map<String, Object> model) { if (templateEngine == null) { throw new PippoRuntimeException("You must set a template engine in your application"); } // merge the model passed with the locals data model.putAll(getLocals()); // add session (if exists) to model Session session = Session.get(); if (session != null) { model.put("session", session); } // render the template using the merged model StringWriter stringWriter = new StringWriter(); templateEngine.renderResource(templateName, model, stringWriter); return stringWriter.toString(); }