use of javax.servlet.http.HttpSessionEvent in project tomee by apache.
the class HttpSessionImpl method getSessionContext.
@Override
public HttpSessionContext getSessionContext() {
touch();
final SessionManager component = SystemInstance.get().getComponent(SessionManager.class);
return new HttpSessionContext() {
@Override
public javax.servlet.http.HttpSession getSession(final String sessionId) {
final HttpSessionEvent event = component.findSession(sessionId);
return event == null ? null : event.getSession();
}
@Override
public Enumeration<String> getIds() {
return Collections.enumeration(component.findSessionIds());
}
};
}
use of javax.servlet.http.HttpSessionEvent in project tomee by apache.
the class HttpSessionImplTest method run.
@Test
public void run() throws URISyntaxException {
final HttpRequest req = new HttpRequestImpl(new URI("http://localhost:1234/foo"));
final javax.servlet.http.HttpSession session = req.getSession();
Reflections.set(session, "listeners", Collections.<Object>singletonList(new HttpSessionListener() {
private int count = 0;
@Override
public void sessionCreated(final HttpSessionEvent se) {
// no-op
}
@Override
public void sessionDestroyed(final HttpSessionEvent se) {
se.getSession().setAttribute("seen", ++count);
}
}));
session.invalidate();
final long c1 = Integer.class.cast(session.getAttribute("seen"));
session.invalidate();
final long c2 = Integer.class.cast(session.getAttribute("seen"));
assertEquals(c1, c2);
}
use of javax.servlet.http.HttpSessionEvent in project jetty.project by eclipse.
the class Session method willPassivate.
/* ------------------------------------------------------------- */
/**
* Call the passivation listeners. This must be called holding the
* lock
*/
public void willPassivate() {
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.sessionWillPassivate(event);
}
}
}
use of javax.servlet.http.HttpSessionEvent 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;
}
}
use of javax.servlet.http.HttpSessionEvent in project tomcat by apache.
the class StandardSessionContext method activate.
/**
* Perform internal processing required to activate this
* session.
*/
public void activate() {
// Initialize access count
if (ACTIVITY_CHECK) {
accessCount = new AtomicInteger();
}
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_ACTIVATED_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).sessionDidActivate(event);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
manager.getContext().getLogger().error(sm.getString("standardSession.attributeEvent"), t);
}
}
}
}
Aggregations