List of usage examples for javax.servlet.http HttpSessionBindingEvent getName
public String getName()
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();// w w w. j ava 2 s . c o m 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 w ww . ja v a 2 s.co 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();/*from w w w . j ava 2 s.c om*/ 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();// w w w.ja v a 2s . 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 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 . j a v a 2 s .c o 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 a 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 w w w .ja v a 2 s . c om*/ 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 w w . ja v a 2 s.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); }
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 ww w. ja va2s.c o m*/ 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); }
From source file:org.everit.authentication.cas.CasAuthentication.java
/** * Handles the case when a special session attribute is added. If an attribute added (manually or * when restoring a persistent session) with name starting with * {@link CasHttpSessionActivationListener#SESSION_ATTR_NAME_SERVICE_PID_PREFIX} this listener * method will://from w ww . ja v a 2 s .c om * <ul> * <li>Register a {@link CasHttpSessionActivationListener} instance to the session and remove the * added session attribute if the {@link CasHttpSessionActivationListener} IS NOT REGISTERED to * the session already with the Service PID stored in the session. This is necessary to * re-register the EventListener when a session is restored from its persistent state.</li> * <li>Remove the {@link CasHttpSessionActivationListener} instance from the session if the * {@link CasHttpSessionActivationListener} IS REGISTERED to the session already with the Service * PID stored in the session. This is necessary to remove the EventListener from the session * before it will be Serialized, because the {@link CasHttpSessionActivationListener} is not * {@link java.io.Serializable} and cannot be instantiated/deserialized by a non-OSGi technology * </li> * </ul> */ @Override public void attributeAdded(final HttpSessionBindingEvent event) { String addedAttributeName = event.getName(); if (addedAttributeName.startsWith(CasHttpSessionActivationListener.SESSION_ATTR_NAME_SERVICE_PID_PREFIX)) { String servicePid = (String) event.getValue(); String casHttpSessionActivationListenerSessionAttrName = CasHttpSessionActivationListener .createSessionAttrNameInstance(servicePid); HttpSession httpSession = event.getSession(); if (httpSession.getAttribute(casHttpSessionActivationListenerSessionAttrName) == null) { CasHttpSessionActivationListener.registerInstance(servicePid, httpSession); String attributeNameToRemove = CasHttpSessionActivationListener .createSessionAttrNameServicePid(servicePid); if (attributeNameToRemove.equals(addedAttributeName)) { httpSession.removeAttribute(attributeNameToRemove); } } else { CasHttpSessionActivationListener.removeInstance(servicePid, httpSession); } } }