类javax.servlet.http.HttpSessionBindingListener源码实例Demo

下面列出了怎么用javax.servlet.http.HttpSessionBindingListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: spring-analysis-note   文件: MockHttpSession.java
@Override
public void setAttribute(String name, @Nullable Object value) {
	assertIsValid();
	Assert.notNull(name, "Attribute name must not be null");
	if (value != null) {
		Object oldValue = this.attributes.put(name, value);
		if (value != oldValue) {
			if (oldValue instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
			}
			if (value instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
			}
		}
	}
	else {
		removeAttribute(name);
	}
}
 
源代码2 项目: spring-analysis-note   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码3 项目: spring-analysis-note   文件: MockHttpSession.java
@Override
public void setAttribute(String name, @Nullable Object value) {
	assertIsValid();
	Assert.notNull(name, "Attribute name must not be null");
	if (value != null) {
		Object oldValue = this.attributes.put(name, value);
		if (value != oldValue) {
			if (oldValue instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
			}
			if (value instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
			}
		}
	}
	else {
		removeAttribute(name);
	}
}
 
源代码4 项目: spring-analysis-note   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码5 项目: quarkus-http   文件: SessionListenerBridge.java
@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));
    }
}
 
源代码6 项目: java-technology-stack   文件: MockHttpSession.java
@Override
public void setAttribute(String name, @Nullable Object value) {
	assertIsValid();
	Assert.notNull(name, "Attribute name must not be null");
	if (value != null) {
		Object oldValue = this.attributes.put(name, value);
		if (value != oldValue) {
			if (oldValue instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
			}
			if (value instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
			}
		}
	}
	else {
		removeAttribute(name);
	}
}
 
源代码7 项目: java-technology-stack   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码8 项目: java-technology-stack   文件: MockHttpSession.java
@Override
public void setAttribute(String name, @Nullable Object value) {
	assertIsValid();
	Assert.notNull(name, "Attribute name must not be null");
	if (value != null) {
		Object oldValue = this.attributes.put(name, value);
		if (value != oldValue) {
			if (oldValue instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
			}
			if (value instanceof HttpSessionBindingListener) {
				((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value));
			}
		}
	}
	else {
		removeAttribute(name);
	}
}
 
源代码9 项目: java-technology-stack   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码10 项目: vertx-vaadin   文件: VertxWrappedSessionUT.java
@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));
}
 
源代码11 项目: vertx-vaadin   文件: VertxWrappedSessionUT.java
@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));
}
 
源代码12 项目: lams   文件: SessionListenerBridge.java
@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));
    }
}
 
@Test
public void testSessionDestroyed() {
  HttpSessionBindingListener bindingListener = mock(HttpSessionBindingListener.class);
  String dummy = "dummy";
  when(session.getAttribute("binding")).thenReturn(bindingListener);
  when(session.getAttribute("attribute")).thenReturn(dummy);
  when(session.getAttributeNamesWithValues()).thenReturn(Arrays.asList("binding", "attribute"));
  HttpSessionListener listener = mock(HttpSessionListener.class);
  descriptor.addHttpSessionListener(listener);
  notifier.sessionDestroyed(session, false);
  verify(bindingListener).valueUnbound(any(HttpSessionBindingEvent.class));
  verify(listener).sessionDestroyed(any(HttpSessionEvent.class));
  HttpSessionListener listener2 = mock(HttpSessionListener.class);
  HttpSessionBindingListener bindingListener2 = mock(HttpSessionBindingListener.class);
  when(session.getAttribute("binding2")).thenReturn(bindingListener2);
  when(session.getAttributeNamesWithValues()).thenReturn(Arrays.asList("binding", "attribute", "binding2"));
  descriptor.addHttpSessionListener(listener2);
  notifier.sessionDestroyed(session, false);
  verify(listener, times(2)).sessionDestroyed(any(HttpSessionEvent.class));
  verify(bindingListener, times(2)).valueUnbound(any(HttpSessionBindingEvent.class));
  verify(bindingListener2).valueUnbound(any(HttpSessionBindingEvent.class));
  verify(listener2).sessionDestroyed(any(HttpSessionEvent.class));
}
 
源代码14 项目: spring4-understanding   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码15 项目: spring4-understanding   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码16 项目: live-chat-engine   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码17 项目: sakai   文件: EntityHttpServletRequest.java
/**
 * 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;
}
 
源代码18 项目: sakai   文件: EntityHttpServletRequest.java
/**
 * 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;
}
 
源代码19 项目: gocd   文件: MockHttpSession.java
/**
 * 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;
}
 
源代码20 项目: tomee   文件: WebContext.java
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;
}
 
private HttpSession createSessionExpectations(CrawlerSessionManagerValve valve, boolean isBot) {
    HttpSession session = EasyMock.createMock(HttpSession.class);
    if (isBot) {
        EasyMock.expect(session.getId()).andReturn("id").times(2);
        session.setAttribute(EasyMock.eq(valve.getClass().getName()), EasyMock.anyObject(HttpSessionBindingListener.class));
        EasyMock.expectLastCall();
        session.setMaxInactiveInterval(60);
        EasyMock.expectLastCall();
    }
    return session;
}
 
源代码22 项目: spring-analysis-note   文件: MockHttpSession.java
@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));
	}
}
 
源代码23 项目: spring-analysis-note   文件: MockHttpSession.java
/**
 * 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));
		}
	}
}
 
源代码24 项目: spring-analysis-note   文件: MockHttpSession.java
@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));
	}
}
 
源代码25 项目: spring-analysis-note   文件: MockHttpSession.java
/**
 * 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));
		}
	}
}
 
源代码26 项目: quarkus-http   文件: SessionListenerBridge.java
@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));
    }
}
 
源代码27 项目: quarkus-http   文件: SessionListenerBridge.java
@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));
        }
    }
}
 
源代码28 项目: java-technology-stack   文件: MockHttpSession.java
@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));
	}
}
 
源代码29 项目: java-technology-stack   文件: MockHttpSession.java
/**
 * 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));
		}
	}
}
 
源代码30 项目: java-technology-stack   文件: MockHttpSession.java
@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));
	}
}