Example usage for javax.servlet.http HttpSessionBindingEvent getValue

List of usage examples for javax.servlet.http HttpSessionBindingEvent getValue

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionBindingEvent getValue.

Prototype

public Object getValue() 

Source Link

Document

Returns the value of the attribute that has been added, removed or replaced.

Usage

From source file:alpha.portal.webapp.listener.UserCounterListener.java

/**
 * Needed for Acegi Security 1.0, as it adds an anonymous user to the
 * session and then replaces it after authentication.
 * http://forum.springframework.org/showthread.php?p=63593
 * /*from w  ww.j a v  a  2  s  .  c om*/
 * @param event
 *            the session binding event
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
 */
public void attributeReplaced(final HttpSessionBindingEvent event) {
    if (event.getName().equals(UserCounterListener.EVENT_KEY) && !this.isAnonymous()) {
        final SecurityContext securityContext = (SecurityContext) event.getValue();
        if ((securityContext.getAuthentication() != null)
                && (securityContext.getAuthentication().getPrincipal() instanceof User)) {
            final User user = (User) securityContext.getAuthentication().getPrincipal();
            this.addUsername(user);
        }
    }
}

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  w w w  .  ja v a 2  s . c om

    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 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();//from  ww w .jav  a  2  s.  c  om

    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.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 ww  w . j ava2s  .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();//w  ww . j  a  v  a2 s . com

    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 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();// www  . j a v  a  2  s.  c om

    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 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 w  w  w  .j  a  v a  2s . co  m*/

    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 ww w. j  a v a2s .  co  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   w w w.j  ava  2 s.  com*/

    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 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);//w  ww .  ja va2s .c  o m
    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);
}