@Override
public void attributeUpdated(final Session session, final String name, final Object value, final Object old) {
if(name.startsWith(IO_UNDERTOW)) {
return;
}
final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, false);
if (old != value) {
if (old instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) old).valueUnbound(new HttpSessionBindingEvent(httpSession, name, old));
}
applicationListeners.httpSessionAttributeReplaced(httpSession, name, old);
}
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(httpSession, name, value));
}
}
java类javax.servlet.http.HttpSessionBindingListener的实例源码
SessionListenerBridge.java 文件源码
项目:lams
阅读 54
收藏 0
点赞 0
评论 0
NettyHttpSession.java 文件源码
项目:nebo
阅读 33
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
MockHttpSession.java 文件源码
项目:spring4-understanding
阅读 41
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
MockHttpSession.java 文件源码
项目:spring4-understanding
阅读 36
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
VertxWrappedSessionUT.java 文件源码
项目:vaadin-vertx-samples
阅读 31
收藏 0
点赞 0
评论 0
@Test
public void shouldUnbindOnInvalidate() throws Exception {
Map<String, Object> sampleData = new HashMap<>();
HttpSessionBindingListener mockA = mock(HttpSessionBindingListener.class);
HttpSessionBindingListener mockC = mock(HttpSessionBindingListener.class);
sampleData.put("a", mockA);
sampleData.put("b", "b");
sampleData.put("c", mockC);
sampleData.put("b", "b");
when(session.data()).thenReturn(sampleData);
vertxWrappedSession.invalidate();
verify(session).destroy();
ArgumentCaptor<HttpSessionBindingEvent> sessionBindingEventCaptor = ArgumentCaptor.forClass(HttpSessionBindingEvent.class);
verify(mockA).valueUnbound(sessionBindingEventCaptor.capture());
verify(mockC).valueUnbound(sessionBindingEventCaptor.capture());
assertThat(sessionBindingEventCaptor.getAllValues()).hasSize(2);
assertHttpSessionBindingEvent("a", mockA, sessionBindingEventCaptor.getAllValues().get(0));
assertHttpSessionBindingEvent("c", mockC, sessionBindingEventCaptor.getAllValues().get(1));
}
MockHttpSession.java 文件源码
项目:nbone
阅读 40
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
HttpSessionImpl.java 文件源码
项目:opengse
阅读 46
收藏 0
点赞 0
评论 0
/**
* Removes the object bound with the specified name from
* this session.
*/
public void removeAttribute(String name) {
maybeThrowIllegalStateException();
checkValid();
Object value = getAttribute(name);
// notify binding listeners
if (value != null) {
sessionData_.remove(name);
updateCache();
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(
new HttpSessionBindingEvent(this, name));
}
}
// notify attribute listeners
ServletSessionCache.getCache(cacheId_).
notifySessionAttributeRemoved(this, name);
}
MockHttpSession.java 文件源码
项目:live-chat-engine
阅读 34
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can
* be turned into a byte array with standard Java serialization.
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap state = new HashMap();
for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
XSLWebHttpSession.java 文件源码
项目:xslweb
阅读 33
收藏 0
点赞 0
评论 0
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
EntityHttpServletRequest.java 文件源码
项目:sakai
阅读 27
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can
* be turned into a byte array with standard Java serialization.
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Object> state = new HashMap<String, Object>();
for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, value);
}
else {
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
FakeSession.java 文件源码
项目:youtube-cache
阅读 39
收藏 0
点赞 0
评论 0
/**
* Binds an object to this session, using the name specified. If an object of
* the same name is already bound to the session, the object is replaced.
* @param name The name to which the object is bound; cannot be null.
* @param value The object to be bound.
*/
public void setAttribute(String name, Object value) {
if (!isValid())
throw new IllegalStateException(
"Method is called on an invalidated session");
if (value == null) removeAttribute(name);
else {
attributes.put(name, value);
try {
HttpSessionBindingListener listener = (HttpSessionBindingListener) value;
listener.valueBound(new HttpSessionBindingEvent(this, name, value));
listener.notifyAll();
}
catch (ClassCastException e) { }
}
}
FakeSession.java 文件源码
项目:youtube-cache
阅读 38
收藏 0
点赞 0
评论 0
private void cleanUpAttributes() {
if (!isValid())
throw new IllegalStateException(
"Method is called on an invalidated session");
Iterator iter = attributes.entrySet().iterator();
while (iter.hasNext()) {
Entry e = (Entry) iter.next();
String name = e.getKey() + "";
Object value = e.getValue();
iter.remove();
try {
HttpSessionBindingListener listener = (HttpSessionBindingListener) value;
listener.valueUnbound(new HttpSessionBindingEvent(this, name, value));
listener.notifyAll();
}
catch (ClassCastException err) { }
}
}
MockHttpSession.java 文件源码
项目:class-guard
阅读 39
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
MockHttpSession.java 文件源码
项目:class-guard
阅读 41
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
*
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
EntityHttpServletRequest.java 文件源码
项目:sakai
阅读 31
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can
* be turned into a byte array with standard Java serialization.
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Object> state = new HashMap<String, Object>();
for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, value);
}
else {
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
MockHttpSession.java 文件源码
项目:gocd
阅读 41
收藏 0
点赞 0
评论 0
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<>();
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof Serializable) {
state.put(name, (Serializable) value);
}
else {
// Not serializable... Servlet containers usually automatically
// unbind the attribute in this case.
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
return state;
}
WebContext.java 文件源码
项目:tomee
阅读 34
收藏 0
点赞 0
评论 0
private static boolean isWeb(final Class<?> beanClass) {
if (Servlet.class.isAssignableFrom(beanClass)
|| Filter.class.isAssignableFrom(beanClass)) {
return true;
}
if (EventListener.class.isAssignableFrom(beanClass)) {
return HttpSessionAttributeListener.class.isAssignableFrom(beanClass)
|| ServletContextListener.class.isAssignableFrom(beanClass)
|| ServletRequestListener.class.isAssignableFrom(beanClass)
|| ServletContextAttributeListener.class.isAssignableFrom(beanClass)
|| HttpSessionListener.class.isAssignableFrom(beanClass)
|| HttpSessionBindingListener.class.isAssignableFrom(beanClass)
|| HttpSessionActivationListener.class.isAssignableFrom(beanClass)
|| HttpSessionIdListener.class.isAssignableFrom(beanClass)
|| ServletRequestAttributeListener.class.isAssignableFrom(beanClass);
}
return false;
}
HttpSessionImpl.java 文件源码
项目:tasfe-framework
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void removeAttribute(String name) {
if (attributes != null) {
Object value = attributes.get(name);
if (value != null && value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
attributes.remove(name);
}
}
HttpSessionImpl.java 文件源码
项目:tasfe-framework
阅读 39
收藏 0
点赞 0
评论 0
@Override
public void setAttribute(String name, Object value) {
attributes.put(name, value);
if (value != null && value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
}
}
SessionListenerBridge.java 文件源码
项目:lams
阅读 55
收藏 0
点赞 0
评论 0
@Override
public void attributeAdded(final Session session, final String name, final Object value) {
if(name.startsWith(IO_UNDERTOW)) {
return;
}
final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, false);
applicationListeners.httpSessionAttributeAdded(httpSession, name, value);
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(httpSession, name, value));
}
}
SessionListenerBridge.java 文件源码
项目:lams
阅读 42
收藏 0
点赞 0
评论 0
@Override
public void attributeRemoved(final Session session, final String name, final Object old) {
if(name.startsWith(IO_UNDERTOW)) {
return;
}
final HttpSessionImpl httpSession = SecurityActions.forSession(session, servletContext, false);
if (old != null) {
applicationListeners.httpSessionAttributeRemoved(httpSession, name, old);
if (old instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) old).valueUnbound(new HttpSessionBindingEvent(httpSession, name, old));
}
}
}
MockHttpServletRequest.java 文件源码
项目:jaffa-framework
阅读 43
收藏 0
点赞 0
评论 0
public void setAttribute(String string, Object object) {
Object originalValue = attr.put(string, object);
if (originalValue != null && originalValue instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) originalValue).valueUnbound(new HttpSessionBindingEvent(this, string));
}
if (object != null && object instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) object).valueBound(new HttpSessionBindingEvent(this, string));
}
}
HttpSessionNotifier.java 文件源码
项目:HttpSessionReplacer
阅读 36
收藏 0
点赞 0
评论 0
/**
* Notifies listeners that attribute was added. See {@link SessionNotifier}
* {@link #attributeAdded(RepositoryBackedSession, String, Object)}.
* <p>
* If the added attribute <code>value</code> is a HttpSessionBindingListener,
* it will receive the {@link HttpSessionBindingEvent}. If there are
* {@link HttpSessionAttributeListener} instances associated to
* {@link ServletContext}, they will be notified via
* {@link HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)}
* .
*/
@Override
public void attributeAdded(RepositoryBackedSession session, String key, Object value) {
// If the
if (session instanceof HttpSession && value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent((HttpSession)session, key));
}
HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession)session, key, value);
for (HttpSessionAttributeListener listener : descriptor.getHttpSessionAttributeListeners()) {
listener.attributeAdded(event);
}
}
TestHttpSessionNotifier.java 文件源码
项目:HttpSessionReplacer
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testAttributeAdded() {
HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
descriptor.addHttpSessionAttributeListener(listener);
notifier.attributeAdded(session, "Test", "value");
verify(listener).attributeAdded(any(HttpSessionBindingEvent.class));
HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
notifier.attributeAdded(session, "Test", bindingListener);
verify(listener, times(2)).attributeAdded(any(HttpSessionBindingEvent.class));
verify(bindingListener).valueBound(any(HttpSessionBindingEvent.class));
}
TestHttpSessionNotifier.java 文件源码
项目:HttpSessionReplacer
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void testAttributeReplaced() {
HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
notifier.attributeReplaced(session, "Test", "very-old-value");
verify(listener, never()).attributeReplaced(any(HttpSessionBindingEvent.class));
descriptor.addHttpSessionAttributeListener(listener);
notifier.attributeReplaced(session, "Test", "old-value");
verify(listener).attributeReplaced(any(HttpSessionBindingEvent.class));
HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
notifier.attributeReplaced(session, "Test", bindingListener);
verify(listener, times(2)).attributeReplaced(any(HttpSessionBindingEvent.class));
verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class));
}
TestHttpSessionNotifier.java 文件源码
项目:HttpSessionReplacer
阅读 39
收藏 0
点赞 0
评论 0
@Test
public void testAttributeRemoved() {
notifier.attributeRemoved(session, "Test", "very-old-value");
HttpSessionAttributeListener listener = mock(HttpSessionAttributeListener.class);
descriptor.addHttpSessionAttributeListener(listener);
notifier.attributeRemoved(session, "Test", "old-value");
verify(listener).attributeRemoved(any(HttpSessionBindingEvent.class));
HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
notifier.attributeRemoved(session, "Test", bindingListener);
verify(listener, times(2)).attributeRemoved(any(HttpSessionBindingEvent.class));
verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class));
}
NettyHttpSession.java 文件源码
项目:nebo
阅读 39
收藏 0
点赞 0
评论 0
@Override
public void setAttribute(String name, Object value) {
assertIsValid();
Assert.notNull(name, "Attribute name must not be null");
if (value != null) {
this.attributes.put(name, value);
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
}
}
else {
removeAttribute(name);
}
}
NettyHttpSession.java 文件源码
项目:nebo
阅读 40
收藏 0
点赞 0
评论 0
@Override
public void removeAttribute(String name) {
assertIsValid();
Assert.notNull(name, "Attribute name must not be null");
Object value = this.attributes.remove(name);
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
NettyHttpSession.java 文件源码
项目:nebo
阅读 40
收藏 0
点赞 0
评论 0
/**
* Clear all of this session's attributes.
*/
public void clearAttributes() {
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
}
}
}
MockPortletSession.java 文件源码
项目:spring4-understanding
阅读 33
收藏 0
点赞 0
评论 0
protected void doClearAttributes(Map<String, Object> attributes) {
for (Iterator<Map.Entry<String, Object>> it = attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry<String, Object> entry = it.next();
String name = entry.getKey();
Object value = entry.getValue();
it.remove();
if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(
new HttpSessionBindingEvent(new MockHttpSession(), name, value));
}
}
}