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: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 w ww .j  a v  a2  s  . co  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  w w . j a  va 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);
        }
    }
}

From source file:org.kuali.rice.krad.web.listener.NonSerializableSessionListener.java

/**
 * Tests whether the attribute value is serializable and logs an error if it isn't.  Note, this can be expensive
 * so we avoid it in production environments.
 * @param se the session binding event//from   www .  jav a  2 s . com
 * @param action the listener event for logging purposes (added or replaced)
 */
protected void checkSerialization(final HttpSessionBindingEvent se, String action) {
    final Object o = se.getValue();
    if (o != null) {
        if (!isSerializable(o)) {
            LOG.error("Attribute of class " + o.getClass().getName() + " with name " + se.getName()
                    + " from source " + se.getSource().getClass().getName() + " was " + action
                    + " to session and does not implement " + Serializable.class.getName());
        } else if (!canBeSerialized((Serializable) o)) {
            LOG.error("Attribute of class " + o.getClass().getName() + " with name " + se.getName()
                    + " from source " + se.getSource().getClass().getName() + " was " + action
                    + " to session and cannot be Serialized");
        }
    }
}

From source file:org.projectforge.web.debug.SessionSerializableChecker.java

/**
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeAdded(javax.servlet.http.HttpSessionBindingEvent)
 *//*from w  w w. j  a  v a 2  s . com*/
public void attributeAdded(final HttpSessionBindingEvent evt) {
    if (WebConfiguration.isDevelopmentMode() == true) {
        check(evt.getSession(), evt.getName(), evt.getValue());
    }
}

From source file:org.projectforge.web.debug.SessionSerializableChecker.java

/**
 * @see javax.servlet.http.HttpSessionAttributeListener#attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)
 *//*from w  w w  .  j ava 2  s.co m*/
public void attributeReplaced(final HttpSessionBindingEvent evt) {
    if (WebConfiguration.isDevelopmentMode() == true) {
        check(evt.getSession(), evt.getName(), evt.getValue());
    }
}