/** * Gets the underlying HttpSession object or null. * <p> * WARNING: it is a bad idea to depend on the http session object directly. Please use the * classes and methods that are exposed by Wicket instead. Send an email to the mailing list in * case it is not clear how to do things or you think you miss functionality which causes you to * depend on this directly. * </p> * * @param request * * @return The underlying HttpSession object. */ protected final HttpSession getHttpSession(WebRequest request) { return getHttpSession(request, false); }
HttpSession httpSession = getHttpSession(webRequest); if (httpSession != null)
/** * @see org.apache.wicket.session.ISessionStore#invalidate(Request) */ public final void invalidate(Request request) { WebRequest webRequest = toWebRequest(request); HttpSession httpSession = getHttpSession(webRequest); if (httpSession != null) { String applicationKey = application.getApplicationKey(); try { SessionBindingListener l = (SessionBindingListener)httpSession .getAttribute("Wicket:SessionUnbindingListener-" + applicationKey); if (l != null) { l.unbound = true; } // call unbind unbind(httpSession.getId()); // tell the app server the session is no longer valid httpSession.invalidate(); } catch (IllegalStateException e) { // can safely be ignored } } }
/** * @see org.apache.wicket.session.ISessionStore#bind(org.apache.wicket.Request, * org.apache.wicket.Session) */ public final void bind(Request request, Session newSession) { // call template method onBind(request, newSession); WebRequest webRequest = toWebRequest(request); HttpSession httpSession = getHttpSession(webRequest, true); // register an unbinding listener for cleaning up String applicationKey = application.getApplicationKey(); httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey, new SessionBindingListener(applicationKey, httpSession.getId())); // register the session object itself setAttribute(webRequest, Session.SESSION_ATTRIBUTE_NAME, newSession); }
/** * @see org.apache.wicket.session.ISessionStore#bind(org.apache.wicket.Request, * org.apache.wicket.Session) */ public final void bind(Request request, Session newSession) { // call template method onBind(request, newSession); WebRequest webRequest = toWebRequest(request); HttpSession httpSession = getHttpSession(webRequest); // register an unbinding listener for cleaning up String applicationKey = application.getApplicationKey(); httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey, new SessionBindingListener(applicationKey, httpSession.getId())); // register the session object itself setAttribute(webRequest, Session.SESSION_ATTRIBUTE_NAME, newSession); }