Search in sources :

Example 11 with HttpSessionListener

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

the class UndertowContext method addSessionListener.

@Override
public void addSessionListener(org.jboss.modcluster.container.listeners.HttpSessionListener sessionListener) {
    HttpSessionListener listener = new HttpSessionListener() {

        @Override
        public void sessionCreated(HttpSessionEvent se) {
            sessionListener.sessionCreated();
        }

        @Override
        public void sessionDestroyed(HttpSessionEvent se) {
            sessionListener.sessionDestroyed();
        }
    };
    ManagedListener ml = new ManagedListener(new ListenerInfo(HttpSessionListener.class, new ImmediateInstanceFactory<>(listener)), true);
    try {
        ml.start();
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    this.deployment.getApplicationListeners().addListener(ml);
}
Also used : ServletException(javax.servlet.ServletException) HttpSessionListener(javax.servlet.http.HttpSessionListener) ListenerInfo(io.undertow.servlet.api.ListenerInfo) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) ManagedListener(io.undertow.servlet.core.ManagedListener) ImmediateInstanceFactory(io.undertow.servlet.util.ImmediateInstanceFactory)

Example 12 with HttpSessionListener

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

Example 13 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project Payara by payara.

the class StandardContext method eventListenerStop.

private boolean eventListenerStop() {
    if (eventListeners.isEmpty()) {
        return true;
    }
    Iterator<EventListener> iter = eventListeners.iterator();
    while (iter.hasNext()) {
        EventListener listener = iter.next();
        // already had their PreDestroy called
        if (listener instanceof ServletContextListener || listener instanceof HttpSessionListener) {
            continue;
        }
        fireContainerEvent(ContainerEvent.PRE_DESTROY, listener);
    }
    eventListeners.clear();
    return true;
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletContextListener(javax.servlet.ServletContextListener) EventListener(java.util.EventListener)

Example 14 with HttpSessionListener

use of javax.servlet.http.HttpSessionListener in project Payara by payara.

the class StandardContext method addListener.

/**
 * Adds the given listener instance to this ServletContext.
 *
 * @param t the listener to be added
 * @param isProgrammatic true if the listener is being added
 * programmatically, and false if it has been declared in the deployment
 * descriptor
 */
private <T extends EventListener> void addListener(T t, boolean isProgrammatic) {
    if (isContextInitializedCalled) {
        String msg = MessageFormat.format(rb.getString(LogFacade.SERVLET_CONTEXT_ALREADY_INIT_EXCEPTION), new Object[] { "addListener", getName() });
        throw new IllegalStateException(msg);
    }
    if ((t instanceof ServletContextListener) && isProgrammatic && !isProgrammaticServletContextListenerRegistrationAllowed) {
        throw new IllegalArgumentException("Not allowed to register " + "ServletContextListener programmatically");
    }
    boolean added = false;
    if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestAttributeListener || t instanceof ServletRequestListener || t instanceof HttpSessionAttributeListener || t instanceof HttpSessionIdListener) {
        eventListeners.add(t);
        added = true;
    }
    if (t instanceof HttpSessionListener) {
        sessionListeners.add((HttpSessionListener) t);
        if (!added) {
            added = true;
        }
    }
    if (t instanceof ServletContextListener) {
        ServletContextListener proxy = (ServletContextListener) t;
        if (isProgrammatic) {
            proxy = new RestrictedServletContextListener((ServletContextListener) t);
        }
        // Always add the JSF listener as the first element,
        // see GlassFish Issue 2563 for details
        boolean isFirst = "com.sun.faces.config.ConfigureListener".equals(t.getClass().getName());
        if (isFirst) {
            contextListeners.add(0, proxy);
        } else {
            contextListeners.add(proxy);
        }
        if (!added) {
            added = true;
        }
    }
    if (!added) {
        throw new IllegalArgumentException("Invalid listener type " + t.getClass().getName());
    }
}
Also used : ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletContextListener(javax.servlet.ServletContextListener) ServletRequestListener(javax.servlet.ServletRequestListener) HttpSessionAttributeListener(javax.servlet.http.HttpSessionAttributeListener) HttpSessionIdListener(javax.servlet.http.HttpSessionIdListener)

Example 15 with HttpSessionListener

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

the class SessionHandler method newHttpSession.

/* ------------------------------------------------------------ */
/**
     * Creates a new <code>HttpSession</code>.
     *
     * @param request the HttpServletRequest containing the requested session id
     * @return the new <code>HttpSession</code>
     */
public HttpSession newHttpSession(HttpServletRequest request) {
    long created = System.currentTimeMillis();
    String id = _sessionIdManager.newSessionId(request, created);
    Session session = _sessionCache.newSession(request, id, created, (_dftMaxIdleSecs > 0 ? _dftMaxIdleSecs * 1000L : -1));
    session.setExtendedId(_sessionIdManager.getExtendedId(id, request));
    session.getSessionData().setLastNode(_sessionIdManager.getWorkerName());
    try {
        _sessionCache.put(id, session);
        _sessionsCreatedStats.increment();
        if (request.isSecure())
            session.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
        if (_sessionListeners != null) {
            HttpSessionEvent event = new HttpSessionEvent(session);
            for (HttpSessionListener listener : _sessionListeners) listener.sessionCreated(event);
        }
        return session;
    } catch (Exception e) {
        LOG.warn(e);
        return null;
    }
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpSession(javax.servlet.http.HttpSession)

Aggregations

HttpSessionListener (javax.servlet.http.HttpSessionListener)22 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)15 HttpSession (javax.servlet.http.HttpSession)9 IOException (java.io.IOException)7 ServletException (javax.servlet.ServletException)5 NotSerializableException (java.io.NotSerializableException)4 WriteAbortedException (java.io.WriteAbortedException)4 ServletContext (javax.servlet.ServletContext)4 ServletContextAttributeListener (javax.servlet.ServletContextAttributeListener)4 ServletContextListener (javax.servlet.ServletContextListener)4 HttpSessionAttributeListener (javax.servlet.http.HttpSessionAttributeListener)4 Context (org.apache.catalina.Context)4 SessionAuthentication (org.eclipse.jetty.security.authentication.SessionAuthentication)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 ServletRequestAttributeListener (javax.servlet.ServletRequestAttributeListener)3 ServletRequestListener (javax.servlet.ServletRequestListener)3 HttpSessionIdListener (javax.servlet.http.HttpSessionIdListener)3 Test (org.junit.Test)3 ListenerInfo (io.undertow.servlet.api.ListenerInfo)2 ManagedListener (io.undertow.servlet.core.ManagedListener)2