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);
}
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;
}
}
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;
}
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());
}
}
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;
}
}
Aggregations