Example usage for javax.servlet.http HttpSessionEvent getSession

List of usage examples for javax.servlet.http HttpSessionEvent getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionEvent getSession.

Prototype

public HttpSession getSession() 

Source Link

Document

Return the session that changed.

Usage

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testDestroyHttpSessionWithListener(StandardManager manager) throws Exception {
    WADIHttpSession session = (WADIHttpSession) manager.create(null);
    HttpSession wrapper = session.getWrapper();

    String key = "foo";
    Object val = new Listener();
    wrapper.setAttribute(key, val);
    wrapper.setAttribute("bar", "baz");
    events.clear();/*from  www . ja  va 2s .com*/

    session.destroy();

    assertTrue(events.size() == 4);
    {
        Pair pair = (Pair) events.get(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueUnbound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    {
        Pair pair = (Pair) events.get(2);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    {
        Pair pair = (Pair) events.get(3);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("sessionDestroyed"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(wrapper == e.getSession());
    }
    events.clear();
}

From source file:org.codehaus.wadi.web.TestHttpSession.java

public void testReplaceAttribute(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    String key = "foo";
    Object oldVal = new Listener();
    Object newVal = new Listener();
    session.setAttribute(key, oldVal);/*from   w  w  w.j  a v a  2 s  .  c om*/
    assertTrue(events.size() == 3); // valueBound, attributeAdded
    events.clear();

    session.setAttribute(key, newVal);
    assertTrue(events.size() == 3); // valueUnbound, valueBound,
                                    // attributeReplaced
    {
        Pair pair = (Pair) events.get(0);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueUnbound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("valueBound"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == newVal);
    }
    {
        Pair pair = (Pair) events.get(2);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeReplaced"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == oldVal);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getValue(key) == newVal);
}

From source file:org.opencms.main.CmsSessionManager.java

/**
 * Called by the {@link OpenCmsListener} when a http session is destroyed.<p>
 * //from w w  w . java 2  s . co  m
 * @param event the http session event
 * 
 * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
 * @see OpenCmsListener#sessionDestroyed(HttpSessionEvent)
 */
protected void sessionDestroyed(HttpSessionEvent event) {

    synchronized (m_lockSessionCount) {
        m_sessionCountCurrent = (m_sessionCountCurrent <= 0) ? 0 : (m_sessionCountCurrent - 1);
        if (LOG.isInfoEnabled()) {
            LOG.info(Messages.get().getBundle().key(Messages.LOG_SESSION_DESTROYED_2,
                    new Integer(m_sessionCountTotal), new Integer(m_sessionCountCurrent)));
        }
    }

    CmsSessionInfo sessionInfo = getSessionInfo(event.getSession());
    CmsUUID userId = null;
    if (sessionInfo != null) {
        userId = sessionInfo.getUserId();
        m_sessionStorageProvider.remove(sessionInfo.getSessionId());
    }

    if ((userId != null) && (getSessionInfos(userId).size() == 0)) {
        // remove the temporary locks of this user from memory
        OpenCmsCore.getInstance().getLockManager().removeTempLocks(userId);
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_SESSION_DESTROYED_1, event.getSession().getId()));
    }
}

From source file:org.opencms.main.CmsSessionManager.java

/**
 * Called by the {@link OpenCmsListener} when a http session is created.<p>
 * //from  www .j a v  a  2 s.  co  m
 * @param event the http session event
 * 
 * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
 * @see OpenCmsListener#sessionCreated(HttpSessionEvent)
 */
protected void sessionCreated(HttpSessionEvent event) {

    synchronized (m_lockSessionCount) {
        m_sessionCountCurrent = (m_sessionCountCurrent <= 0) ? 1 : (m_sessionCountCurrent + 1);
        m_sessionCountTotal++;
        if (LOG.isInfoEnabled()) {
            LOG.info(Messages.get().getBundle().key(Messages.LOG_SESSION_CREATED_2,
                    new Integer(m_sessionCountTotal), new Integer(m_sessionCountCurrent)));
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_SESSION_CREATED_1, event.getSession().getId()));
    }
}