Search in sources :

Example 11 with HttpSessionEvent

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

Example 12 with HttpSessionEvent

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

the class InfinispanSessionManager method triggerPostActivationEvents.

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

Example 13 with HttpSessionEvent

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

the class SessionManager method doDestroy.

private void doDestroy(final SessionWrapper next) {
    HttpSessionEvent event = null;
    if (next.end != null) {
        event = new HttpSessionEvent(next.session);
        next.end.sessionDestroyed(event);
        // just set session thread local
        next.begin.sessionCreated(event);
    }
    try {
        next.session.invalidate();
    } finally {
        if (next.begin != null) {
            next.begin.sessionDestroyed(event);
        }
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent)

Example 14 with HttpSessionEvent

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

the class HttpRequestImpl method getSession.

public HttpSession getSession(boolean create) {
    if (session == null && create) {
        // default is infinite *here* only
        long timeout = -1;
        if (contextPath != null) {
            // TODO: webapp should be contextual, would need to normalize jaxws, jaxrs, servlet, jsf...before but would be better
            final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
            if (assembler != null) {
                for (final AppInfo info : assembler.getDeployedApplications()) {
                    for (final WebAppInfo webApp : info.webApps) {
                        if (webApp.contextRoot.replace("/", "").equals(contextPath.replace("/", ""))) {
                            timeout = webApp.sessionTimeout;
                        }
                    }
                }
            }
        }
        final HttpSessionImpl impl = new HttpSessionImpl(contextPath, timeout) {

            @Override
            public void invalidate() {
                super.invalidate();
                HttpRequestImpl.this.session = null;
            }
        };
        session = impl;
        if (begin != null) {
            begin.sessionCreated(new HttpSessionEvent(session));
            session = new SessionInvalidateListener(session, begin);
        }
        // can call req.getSession() so do it after affectation + do it after cdi init
        impl.callListeners();
        final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
        final SessionManager.SessionWrapper previous = sessionManager.newSession(begin, end, session, application);
        if (previous != null) {
            session = previous.session;
        }
    }
    return session;
}
Also used : WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) Assembler(org.apache.openejb.assembler.classic.Assembler) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 15 with HttpSessionEvent

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

the class HttpSessionImpl method invalidate.

@Override
public void invalidate() {
    if (!valid) {
        return;
    }
    synchronized (this) {
        if (!valid) {
            return;
        }
        if (!listeners.isEmpty()) {
            final HttpSessionEvent event = new HttpSessionEvent(this);
            for (final HttpSessionListener o : listeners) {
                try {
                    HttpSessionListener.class.cast(o).sessionDestroyed(event);
                } catch (final Throwable th) {
                // ignore, may be undeployed
                }
            }
        }
        final SessionManager sessionManager = SystemInstance.get().getComponent(SessionManager.class);
        if (sessionManager != null) {
            sessionManager.removeSession(sessionId);
        }
        valid = false;
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) SessionManager(org.apache.openejb.server.httpd.session.SessionManager) 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