Search in sources :

Example 1 with HttpSessionEvent

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

the class StandardSessionContext method tellNew.

/**
     * Inform the listeners about the new session.
     *
     */
public void tellNew() {
    // Notify interested session event listeners
    fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
    // Notify interested application event listeners
    Context context = manager.getContext();
    Object[] listeners = context.getApplicationLifecycleListeners();
    if (listeners != null && listeners.length > 0) {
        HttpSessionEvent event = new HttpSessionEvent(getSession());
        for (int i = 0; i < listeners.length; i++) {
            if (!(listeners[i] instanceof HttpSessionListener))
                continue;
            HttpSessionListener listener = (HttpSessionListener) listeners[i];
            try {
                context.fireContainerEvent("beforeSessionCreated", listener);
                listener.sessionCreated(event);
                context.fireContainerEvent("afterSessionCreated", listener);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                try {
                    context.fireContainerEvent("afterSessionCreated", listener);
                } catch (Exception e) {
                // Ignore
                }
                manager.getContext().getLogger().error(sm.getString("standardSession.sessionEvent"), t);
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) WriteAbortedException(java.io.WriteAbortedException)

Example 2 with HttpSessionEvent

use of javax.servlet.http.HttpSessionEvent 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 3 with HttpSessionEvent

use of javax.servlet.http.HttpSessionEvent 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 4 with HttpSessionEvent

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

the class SessionHandler method renewSessionId.

/* ------------------------------------------------------------ */
/** Change the existing session id.
    * 
    * @param oldId the old session id
    * @param oldExtendedId the session id including worker suffix
    * @param newId the new session id
    * @param newExtendedId the new session id including worker suffix
    */
public void renewSessionId(String oldId, String oldExtendedId, String newId, String newExtendedId) {
    try {
        //swap the id over
        Session session = _sessionCache.renewSessionId(oldId, newId);
        if (session == null) {
            //session doesn't exist on this context
            return;
        }
        //remember the extended id
        session.setExtendedId(newExtendedId);
        //inform the listeners
        if (!_sessionIdListeners.isEmpty()) {
            HttpSessionEvent event = new HttpSessionEvent(session);
            for (HttpSessionIdListener l : _sessionIdListeners) {
                l.sessionIdChanged(event, oldId);
            }
        }
    } catch (Exception e) {
        LOG.warn(e);
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpSession(javax.servlet.http.HttpSession)

Example 5 with HttpSessionEvent

use of javax.servlet.http.HttpSessionEvent in project jodd by oblac.

the class ServletsMockitoUtil method createHttpSessionEvent.

public static HttpSessionEvent createHttpSessionEvent(HttpSession session) {
    HttpSessionEvent sessionEvent = mock(HttpSessionEvent.class);
    when(sessionEvent.getSession()).thenReturn(session);
    return sessionEvent;
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent)

Aggregations

HttpSessionEvent (javax.servlet.http.HttpSessionEvent)25 HttpSessionActivationListener (javax.servlet.http.HttpSessionActivationListener)8 HttpSessionListener (javax.servlet.http.HttpSessionListener)7 Test (org.junit.Test)6 IOException (java.io.IOException)4 HttpSession (javax.servlet.http.HttpSession)4 MockHttpSession (org.springframework.mock.web.MockHttpSession)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 HttpSessionEventPublisher (org.springframework.security.web.session.HttpSessionEventPublisher)4 ServletContext (javax.servlet.ServletContext)3 SessionManager (org.apache.openejb.server.httpd.session.SessionManager)3 PersistentSession (io.undertow.servlet.api.SessionPersistenceManager.PersistentSession)2 NotSerializableException (java.io.NotSerializableException)2 WriteAbortedException (java.io.WriteAbortedException)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ServletException (javax.servlet.ServletException)2 Context (org.apache.catalina.Context)2 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)2 ImmutableHttpSessionAdapter (org.wildfly.clustering.web.session.ImmutableHttpSessionAdapter)2