Search in sources :

Example 1 with HttpSessionActivationListener

use of javax.servlet.http.HttpSessionActivationListener in project tomcat by apache.

the class StandardSessionContext method passivate.

/**
     * 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.getContext().getLogger().error(sm.getString("standardSession.attributeEvent"), t);
            }
        }
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener)

Example 2 with HttpSessionActivationListener

use of javax.servlet.http.HttpSessionActivationListener in project jetty.project by eclipse.

the class Session method didActivate.

/* ------------------------------------------------------------- */
/**
     * Call the activation listeners. This must be called holding the
     * lock.
     */
public void didActivate() {
    HttpSessionEvent event = new HttpSessionEvent(this);
    for (Iterator<String> iter = _sessionData.getKeys().iterator(); iter.hasNext(); ) {
        Object value = _sessionData.getAttribute(iter.next());
        if (value instanceof HttpSessionActivationListener) {
            HttpSessionActivationListener listener = (HttpSessionActivationListener) value;
            listener.sessionDidActivate(event);
        }
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener)

Example 3 with HttpSessionActivationListener

use of javax.servlet.http.HttpSessionActivationListener in project undertow by undertow-io.

the class SessionRestoringHandler method stop.

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);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) PersistentSession(io.undertow.servlet.api.SessionPersistenceManager.PersistentSession) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener) Date(java.util.Date) Session(io.undertow.server.session.Session) PersistentSession(io.undertow.servlet.api.SessionPersistenceManager.PersistentSession)

Example 4 with HttpSessionActivationListener

use of javax.servlet.http.HttpSessionActivationListener in project undertow by undertow-io.

the class SessionRestoringHandler method handleRequest.

@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);
}
Also used : HttpSessionImpl(io.undertow.servlet.spec.HttpSessionImpl) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) PersistentSession(io.undertow.servlet.api.SessionPersistenceManager.PersistentSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener)

Example 5 with HttpSessionActivationListener

use of javax.servlet.http.HttpSessionActivationListener in project wildfly by wildfly.

the class InfinispanSessionManager method triggerPrePassivationEvents.

void triggerPrePassivationEvents(ImmutableSession session) {
    List<HttpSessionActivationListener> listeners = findListeners(session);
    if (!listeners.isEmpty()) {
        HttpSessionEvent event = new HttpSessionEvent(new ImmutableHttpSessionAdapter(session, this.context));
        listeners.forEach(listener -> listener.sessionWillPassivate(event));
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent) HttpSessionActivationListener(javax.servlet.http.HttpSessionActivationListener) ImmutableHttpSessionAdapter(org.wildfly.clustering.web.session.ImmutableHttpSessionAdapter)

Aggregations

HttpSessionActivationListener (javax.servlet.http.HttpSessionActivationListener)8 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)8 PersistentSession (io.undertow.servlet.api.SessionPersistenceManager.PersistentSession)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ImmutableHttpSessionAdapter (org.wildfly.clustering.web.session.ImmutableHttpSessionAdapter)2 Session (io.undertow.server.session.Session)1 HttpSessionImpl (io.undertow.servlet.spec.HttpSessionImpl)1 Date (java.util.Date)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1