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.jahia.bin.listeners.JahiaContextLoaderListener.java

@Override
public void sessionDidActivate(HttpSessionEvent se) {
    if (isEventInterceptorActivated("interceptHttpSessionActivationEvents")) {
        SpringContextSingleton.getInstance().publishEvent(new HttpSessionDidActivateEvent(se.getSession()));
    }//from  w  w  w.  j  a  v a  2s .c om
}

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

public void testDestroyHttpSessionWithoutListener(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();//ww w.  ja v  a 2 s . com

    session.destroy();

    // analyse results
    assertTrue(events.size() == 1);
    {
        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);
    }
    events.clear();
}

From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java

@Override
public void sessionWillPassivate(HttpSessionEvent se) {
    if (isEventInterceptorActivated("interceptHttpSessionActivationEvents")) {
        SpringContextSingleton.getInstance().publishEvent(new HttpSessionWillPassivateEvent(se.getSession()));
    }/*from   w  ww  .jav  a  2  s  .  co  m*/
}

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

public void testSetAttribute(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    events.clear();//from w w  w  .ja v  a  2s.  c o m

    String key = "foo";
    Object val = new Listener();
    session.setAttribute(key, val);
    assertTrue(events.size() == 2); // valueBound, attributeAdded
    {
        Pair pair = (Pair) events.get(0);
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeAdded"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
}

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

public void testPutValue(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    events.clear();/* ww w  .  j  a va 2  s. c o m*/

    String key = "foo";
    Object val = new Listener();
    session.putValue(key, val);
    assertTrue(events.size() == 2); // valueBound, attributeAdded
    {
        Pair pair = (Pair) events.get(0);
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeAdded"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
}

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

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

    session.removeValue(key);
    assertTrue(events.size() == 2); // valueUnBound, attributeRemoved

    {
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getAttribute(key) == null);
}

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

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

    session.setAttribute(key, null);
    assertTrue(events.size() == 2); // valueUnBound, attributeRemoved

    {
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getAttribute(key) == null);
}

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

public void testPutValueNull(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    String key = "foo";
    Object val = new Listener();
    session.setAttribute(key, val);
    assertTrue(events.size() == 3); // valueBound, attributeAdded
    events.clear();/*from  ww w.j  a va  2  s.c  o m*/

    session.putValue(key, null);
    assertTrue(events.size() == 2); // valueUnBound, attributeRemoved

    {
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getAttribute(key) == null);
}

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

public void testRemoveAttribute(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    assertTrue(events.size() == 1); // sessionCreated
    String key = "foo";
    Object val = new Listener();
    session.setAttribute(key, val);
    assertTrue(events.size() == 3); // valueBound, attributeAdded
    events.clear();/*w  w  w  .j  a  v a2  s. c o m*/

    session.removeAttribute(key);
    assertTrue(events.size() == 2); // valueUnBound, attributeRemoved
    {
        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() == val);
    }
    {
        Pair pair = (Pair) events.get(1);
        assertTrue(pair != null);
        assertTrue(pair.getType().equals("attributeRemoved"));
        HttpSessionEvent e = pair.getEvent();
        assertTrue(session == e.getSession());
        HttpSessionBindingEvent be = (HttpSessionBindingEvent) e;
        assertTrue(be.getName() == key);
        assertTrue(be.getValue() == val);
    }
    events.clear();
    assertTrue(events.size() == 0);
    assertTrue(session.getAttribute(key) == null);

    // try removing it again !
    session.removeAttribute(key);
    assertTrue(events.size() == 0);

}

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

public void testReplaceValue(Manager manager) {
    HttpSession session = ((WADIHttpSession) manager.create(null)).getWrapper();
    String key = "foo";
    Object oldVal = new Listener();
    Object newVal = new Listener();
    session.setAttribute(key, oldVal);//from www .  j  a  v a 2s . com
    events.clear();

    session.putValue(key, newVal);
    {
        Pair pair = (Pair) events.remove(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.remove(0);
        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.remove(0);
        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);
    }
    assertTrue(session.getValue(key) == newVal);
    assertTrue(events.size() == 0);
}