List of usage examples for javax.servlet.http HttpSessionBindingEvent HttpSessionBindingEvent
public HttpSessionBindingEvent(HttpSession session, String name, Object value)
From source file:org.terasoluna.gfw.web.logging.HttpSessionEventLoggingListenerTest.java
@Before public void setup() throws Exception { mockHttpSession = new MockHttpSession(); httpSessionEvent = new HttpSessionEvent(mockHttpSession); sessionBindingEvent = new HttpSessionBindingEvent(mockHttpSession, "terasoluna", "AA"); listener = new HttpSessionEventLoggingListener(); @SuppressWarnings("unchecked") Appender<ILoggingEvent> mockAppender = mock(Appender.class); this.mockAppender = mockAppender; Logger logger = (Logger) LoggerFactory.getLogger(HttpSessionEventLoggingListener.class); logger.addAppender(mockAppender);//from w ww .ja v a2 s . co m }
From source file:org.apache.catalina.cluster.session.DeltaSession.java
public void removeAttribute(String name, boolean notify, boolean addDeltaRequest) { // Validate our current state if (!isValid()) throw new IllegalStateException(sm.getString("standardSession.removeAttribute.ise")); // Remove this attribute from our collection Object value = null;//from ww w. j a v a2s .c o m boolean found = false; synchronized (attributes) { found = attributes.containsKey(name); if (found) { value = attributes.get(name); attributes.remove(name); } else { return; } } if (addDeltaRequest && (deltaRequest != null)) deltaRequest.removeAttribute(name); // Do we need to do valueUnbound() and attributeRemoved() notification? if (!notify) { return; } // Call the valueUnbound() method if necessary HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession) this, name, value); if ((value != null) && (value instanceof HttpSessionBindingListener)) ((HttpSessionBindingListener) value).valueUnbound(event); // Notify interested application event listeners Context context = (Context) manager.getContainer(); Object listeners[] = context.getApplicationEventListeners(); if (listeners == null) return; for (int i = 0; i < listeners.length; i++) { if (!(listeners[i] instanceof HttpSessionAttributeListener)) continue; HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i]; try { fireContainerEvent(context, "beforeSessionAttributeRemoved", listener); listener.attributeRemoved(event); fireContainerEvent(context, "afterSessionAttributeRemoved", listener); } catch (Throwable t) { try { fireContainerEvent(context, "afterSessionAttributeRemoved", listener); } catch (Exception e) { ; } // FIXME - should we do anything besides log these? log.error(sm.getString("standardSession.attributeEvent"), t); } } }
From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java
/** * Sets a session attribute. If the value is a listener, notify it of the objectModified. If the value has changed * mark the session as changed for persistent sessions. * /*ww w . j a v a 2 s .c om*/ * @param name * the name of the attribute * @param value * the value of the attribute */ @Override public void setAttribute(String name, Object value) { if (!_isValid) throw new IllegalStateException( this + ": can't call setAttribute(String, Object) when session is no longer valid."); Object oldValue; if (value != null && !(value instanceof Serializable) && debug) { log.debug(this + " attribute '" + name + "' value is non-serializable type '" + value.getClass().getName() + "'"); } synchronized (_values) { if (value != null) oldValue = _values.put(name, value); else oldValue = _values.remove(name); } if (oldValue instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener; listener = (HttpSessionBindingListener) oldValue; listener.valueUnbound(new HttpSessionBindingEvent(HttpSessionImpl.this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener; listener = (HttpSessionBindingListener) value; listener.valueBound(new HttpSessionBindingEvent(HttpSessionImpl.this, name, value)); } // Notify the attribute listeners ArrayList listeners = _manager.getAttributeListeners(); if (listeners != null && listeners.size() > 0) { HttpSessionBindingEvent event; if (oldValue != null) event = new HttpSessionBindingEvent(this, name, oldValue); else event = new HttpSessionBindingEvent(this, name, value); for (int i = 0; i < listeners.size(); i++) { HttpSessionAttributeListener listener; listener = (HttpSessionAttributeListener) listeners.get(i); if (oldValue != null) listener.attributeReplaced(event); else listener.attributeAdded(event); } } }
From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java
/** * Notify any Attribute unbound listeners. *//*w ww .jav a 2 s . com*/ private void notifyAttributeRemoved(String name, Object oldValue) { if (oldValue == null) return; if (oldValue instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener; listener = (HttpSessionBindingListener) oldValue; listener.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } // Notify the attributes listeners ArrayList listeners = _manager.getAttributeListeners(); if (listeners != null) { HttpSessionBindingEvent event; event = new HttpSessionBindingEvent(this, name, oldValue); for (int i = 0; i < listeners.size(); i++) { HttpSessionAttributeListener listener; listener = (HttpSessionAttributeListener) listeners.get(i); listener.attributeRemoved(event); } } }
From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java
/** * Notify any value unbound listeners.// w w w . j a va 2s. c o m */ private void notifyValueUnbound(String name, Object oldValue) { if (oldValue == null) return; if (oldValue instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener; listener = (HttpSessionBindingListener) oldValue; listener.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } // Notify the attributes listeners ArrayList listeners = _manager.getAttributeListeners(); if (listeners != null) { HttpSessionBindingEvent event; event = new HttpSessionBindingEvent(this, name, oldValue); for (int i = 0; i < listeners.size(); i++) { HttpSessionAttributeListener listener; listener = (HttpSessionAttributeListener) listeners.get(i); listener.attributeRemoved(event); } } }
From source file:org.sakaiproject.tool.impl.MyLittleSession.java
/** * Unbind the value if it's a SessionBindingListener. Also does the HTTP unbinding if it's a HttpSessionBindingListener. * /* w w w . j ava2 s . c o m*/ * @param name * The attribute name bound. * @param value * The bond value. */ protected void unBind(String name, Object value) { if (value instanceof SessionBindingListener) { SessionBindingEvent event = new MySessionBindingEvent(name, null, value); ((SessionBindingListener) value).valueUnbound(event); } // also unbind any objects that are regular HttpSessionBindingListeners if (value instanceof HttpSessionBindingListener) { HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); ((HttpSessionBindingListener) value).valueUnbound(event); } // Added for testing purposes. Very much unsure whether this is a proper // use of MySessionBindingEvent. if (sessionListener != null) { sessionListener.attributeRemoved(new MySessionBindingEvent(name, m_session, value)); } }
From source file:org.sakaiproject.tool.impl.MyLittleSession.java
/** * Bind the value if it's a SessionBindingListener. Also does the HTTP binding if it's a HttpSessionBindingListener. * /*from ww w .jav a2 s.c o m*/ * @param name * The attribute name bound. * @param value * The bond value. */ protected void bind(String name, Object value) { if (value instanceof SessionBindingListener) { SessionBindingEvent event = new MySessionBindingEvent(name, m_session, value); ((SessionBindingListener) value).valueBound(event); } if (value instanceof HttpSessionBindingListener) { HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); ((HttpSessionBindingListener) value).valueBound(event); } // Added for testing purposes. Very much unsure whether this is a proper // use of MySessionBindingEvent. if (sessionListener != null) { sessionListener.attributeAdded(new MySessionBindingEvent(name, m_session, value)); } }
From source file:org.sakaiproject.tool.impl.MySession.java
/** * Unbind the value if it's a SessionBindingListener. Also does the HTTP unbinding if it's a HttpSessionBindingListener. * /*from w w w . j a v a 2 s . c o m*/ * @param name * The attribute name bound. * @param value * The bond value. */ protected void unBind(String name, Object value) { if (value instanceof SessionBindingListener) { SessionBindingEvent event = new MySessionBindingEvent(name, this, value); ((SessionBindingListener) value).valueUnbound(event); } // also unbind any objects that are regular HttpSessionBindingListeners if (value instanceof HttpSessionBindingListener) { HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); ((HttpSessionBindingListener) value).valueUnbound(event); } // Added for testing purposes. Very much unsure whether this is a proper // use of MySessionBindingEvent. if (sessionListener != null) { sessionListener.attributeRemoved(new MySessionBindingEvent(name, this, value)); } }
From source file:org.sakaiproject.tool.impl.MySession.java
/** * Bind the value if it's a SessionBindingListener. Also does the HTTP binding if it's a HttpSessionBindingListener. * /*from w ww. j a va2s. c o m*/ * @param name * The attribute name bound. * @param value * The bond value. */ protected void bind(String name, Object value) { if (value instanceof SessionBindingListener) { SessionBindingEvent event = new MySessionBindingEvent(name, this, value); ((SessionBindingListener) value).valueBound(event); } // also bind any objects that are regular HttpSessionBindingListeners if (value instanceof HttpSessionBindingListener) { HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, name, value); ((HttpSessionBindingListener) value).valueBound(event); } // Added for testing purposes. Very much unsure whether this is a proper // use of MySessionBindingEvent. if (sessionListener != null) { sessionListener.attributeAdded(new MySessionBindingEvent(name, this, value)); } }
From source file:org.springframework.session.web.http.HttpSessionAdapter.java
@Override public void setAttribute(String name, Object value) { checkState();//www . j a v a 2s. co m Object oldValue = this.session.getAttribute(name); this.session.setAttribute(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) oldValue) .valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); } } if (value instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); } } } }