javax.servlet.http.HttpSessionActivationListener Java Examples
The following examples show how to use
javax.servlet.http.HttpSessionActivationListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardSession.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Perform the internal processing required to passivate * this session. */ public void passivate() { // Notify interested session event listeners fireSessionEvent(Session.SESSION_PASSIVATED_EVENT, null); // Notify ActivationListeners HttpSessionEvent event = null; String keys[] = keys(); for (int i = 0; i < keys.length; i++) { Object attribute = attributes.get(keys[i]); if (attribute instanceof HttpSessionActivationListener) { if (event == null) event = new HttpSessionEvent(getSession()); try { ((HttpSessionActivationListener)attribute) .sessionWillPassivate(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); manager.getContainer().getLogger().error (sm.getString("standardSession.attributeEvent"), t); } } } }
Example #2
Source File: WebContext.java From tomee with Apache License 2.0 | 6 votes |
private static boolean isWeb(final Class<?> beanClass) { if (Servlet.class.isAssignableFrom(beanClass) || Filter.class.isAssignableFrom(beanClass)) { return true; } if (EventListener.class.isAssignableFrom(beanClass)) { return HttpSessionAttributeListener.class.isAssignableFrom(beanClass) || ServletContextListener.class.isAssignableFrom(beanClass) || ServletRequestListener.class.isAssignableFrom(beanClass) || ServletContextAttributeListener.class.isAssignableFrom(beanClass) || HttpSessionListener.class.isAssignableFrom(beanClass) || HttpSessionBindingListener.class.isAssignableFrom(beanClass) || HttpSessionActivationListener.class.isAssignableFrom(beanClass) || HttpSessionIdListener.class.isAssignableFrom(beanClass) || ServletRequestAttributeListener.class.isAssignableFrom(beanClass); } return false; }
Example #3
Source File: SessionRestoringHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public void stop() { ClassLoader old = getTccl(); try { setTccl(servletContext.getClassLoader()); this.started = false; final Map<String, SessionPersistenceManager.PersistentSession> objectData = new HashMap<>(); for (String sessionId : sessionManager.getTransientSessions()) { Session session = sessionManager.getSession(sessionId); if (session != null) { final HttpSessionEvent event = new HttpSessionEvent(SecurityActions.forSession(session, servletContext, false)); final Map<String, Object> sessionData = new HashMap<>(); for (String attr : session.getAttributeNames()) { final Object attribute = session.getAttribute(attr); sessionData.put(attr, attribute); if (attribute instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener) attribute).sessionWillPassivate(event); } } objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData)); } } sessionPersistenceManager.persistSessions(deploymentName, objectData); this.data.clear(); } finally { setTccl(old); } }
Example #4
Source File: SessionRestoringHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final String incomingSessionId = servletContext.getSessionConfig().findSessionId(exchange); if (incomingSessionId == null || !data.containsKey(incomingSessionId)) { next.handleRequest(exchange); return; } //we have some old data PersistentSession result = data.remove(incomingSessionId); if (result != null) { long time = System.currentTimeMillis(); if (time < result.getExpiration().getTime()) { final HttpSessionImpl session = servletContext.getSession(exchange, true); final HttpSessionEvent event = new HttpSessionEvent(session); for (Map.Entry<String, Object> entry : result.getSessionData().entrySet()) { if (entry.getValue() instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener) entry.getValue()).sessionDidActivate(event); } if(entry.getKey().startsWith(HttpSessionImpl.IO_UNDERTOW)) { session.getSession().setAttribute(entry.getKey(), entry.getValue()); } else { session.setAttribute(entry.getKey(), entry.getValue()); } } } } next.handleRequest(exchange); }
Example #5
Source File: SessionRestoringHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public void stop() { ClassLoader old = getTccl(); try { setTccl(servletContext.getClassLoader()); this.started = false; final Map<String, SessionPersistenceManager.PersistentSession> objectData = new HashMap<>(); for (String sessionId : sessionManager.getTransientSessions()) { Session session = sessionManager.getSession(sessionId); if (session != null) { final HttpSessionEvent event = new HttpSessionEvent(SecurityActions.forSession(session, servletContext, false)); final Map<String, Object> sessionData = new HashMap<>(); for (String attr : session.getAttributeNames()) { final Object attribute = session.getAttribute(attr); sessionData.put(attr, attribute); if (attribute instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener) attribute).sessionWillPassivate(event); } } objectData.put(sessionId, new PersistentSession(new Date(session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000)), sessionData)); } } sessionPersistenceManager.persistSessions(deploymentName, objectData); this.data.clear(); } finally { setTccl(old); } }
Example #6
Source File: SessionRestoringHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final String incomingSessionId = servletContext.getSessionConfig().findSessionId(exchange); if (incomingSessionId == null || !data.containsKey(incomingSessionId)) { next.handleRequest(exchange); return; } //we have some old data PersistentSession result = data.remove(incomingSessionId); if (result != null) { long time = System.currentTimeMillis(); if (time < result.getExpiration().getTime()) { final HttpSessionImpl session = servletContext.getSession(exchange, true); final HttpSessionEvent event = new HttpSessionEvent(session); for (Map.Entry<String, Object> entry : result.getSessionData().entrySet()) { if (entry.getValue() instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener) entry.getValue()).sessionDidActivate(event); } if(entry.getKey().startsWith(HttpSessionImpl.IO_UNDERTOW)) { session.getSession().setAttribute(entry.getKey(), entry.getValue()); } else { session.setAttribute(entry.getKey(), entry.getValue()); } } } } next.handleRequest(exchange); }
Example #7
Source File: TestHttpSessionNotifier.java From HttpSessionReplacer with MIT License | 5 votes |
@Test public void testAttributeBeingStored() { HttpSessionActivationListener object = mock(HttpSessionActivationListener.class); notifier.attributeBeingStored(mock(RepositoryBackedSession.class), "Test", object); notifier.attributeBeingStored(session, "Test", "dummy"); verify(object, never()).sessionWillPassivate(any(HttpSessionEvent.class)); notifier.attributeBeingStored(session, "Test", object); verify(object).sessionWillPassivate(any(HttpSessionEvent.class)); }
Example #8
Source File: TestHttpSessionNotifier.java From HttpSessionReplacer with MIT License | 5 votes |
@Test public void testAttributeHasBeenRestored() { HttpSessionActivationListener object = mock(HttpSessionActivationListener.class); notifier.attributeHasBeenRestored(mock(RepositoryBackedSession.class), "Test", object); notifier.attributeHasBeenRestored(mock(RepositoryBackedSession.class), "Test", "dummy"); notifier.attributeHasBeenRestored(session, "Test", "dummy"); verify(object, never()).sessionWillPassivate(any(HttpSessionEvent.class)); notifier.attributeHasBeenRestored(session, "Test", object); verify(object).sessionDidActivate(any(HttpSessionEvent.class)); }
Example #9
Source File: StandardSession.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Perform internal processing required to activate this * session. */ public void activate() { // Initialize access count if (ACTIVITY_CHECK) { accessCount = new AtomicInteger(); } // Notify interested session event listeners fireSessionEvent(Session.SESSION_ACTIVATED_EVENT, null); // Notify ActivationListeners HttpSessionEvent event = null; String keys[] = keys(); for (int i = 0; i < keys.length; i++) { Object attribute = attributes.get(keys[i]); if (attribute instanceof HttpSessionActivationListener) { if (event == null) event = new HttpSessionEvent(getSession()); try { ((HttpSessionActivationListener)attribute) .sessionDidActivate(event); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); manager.getContainer().getLogger().error (sm.getString("standardSession.attributeEvent"), t); } } } }
Example #10
Source File: HttpSessionNotifier.java From HttpSessionReplacer with MIT License | 4 votes |
@Override public void attributeBeingStored(RepositoryBackedSession session, String key, Object value) { if (session instanceof HttpSession && value instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener)value).sessionWillPassivate(new HttpSessionEvent((HttpSession)session)); } }
Example #11
Source File: HttpSessionNotifier.java From HttpSessionReplacer with MIT License | 4 votes |
@Override public void attributeHasBeenRestored(RepositoryBackedSession session, String key, Object value) { if (session instanceof HttpSession && value instanceof HttpSessionActivationListener) { ((HttpSessionActivationListener)value).sessionDidActivate(new HttpSessionEvent((HttpSession)session)); } }