List of usage examples for org.apache.wicket Session isTemporary
public final boolean isTemporary()
From source file:at.molindo.wicketutils.utils.MockUtils.java
License:Apache License
/** * reuse an existing session if possible *//* w w w. ja v a 2 s .c o m*/ public static <V> V withRequest(WebApplication webApplication, IMockRequestCallback<V> callback) { Session oldSession = ThreadContext.exists() ? ThreadContext.getSession() : null; ThreadContext oldContext = ThreadContext.detach(); try { ThreadContext.setApplication(webApplication); ThreadContext.setSession(oldSession); // mock http session ServletContext context = webApplication.getServletContext(); MockHttpSession httpSession = new MockHttpSession(context); // mock servlet request MockServletRequest servletRequest = new MockServletRequest(webApplication, httpSession, context); callback.configure(new MockRequest(servletRequest)); servletRequest.setDefaultHeaders(); // mock response MockHttpServletResponse servletResponse = new MockHttpServletResponse(servletRequest); // mock web request final WebRequest request = VisibilityHelper.newWebRequest(webApplication, servletRequest, "/"); // mock web response final WebResponse response = VisibilityHelper.newWebResponse(webApplication, request, servletResponse); // create ThreadContext.setRequestCycle(webApplication.createRequestCycle(request, response)); return callback.call(); } finally { Session newSession = ThreadContext.getSession(); ThreadContext.restore(oldContext); if (oldSession == null && newSession != null && !newSession.isTemporary()) { // reuse session if a new one was created ThreadContext.setSession(newSession); } } }
From source file:de.inren.frontend.application.ApplicationStatus.java
License:Apache License
public int getTemporarySessions() { int temporarySessions = 0; for (Session session : sessions) { if (session.isTemporary()) { temporarySessions++;/*from www . j a v a 2 s . c om*/ } } return temporarySessions; }