本文整理匯總了Java中javax.servlet.http.HttpSessionBindingListener類的典型用法代碼示例。如果您正苦於以下問題:Java HttpSessionBindingListener類的具體用法?Java HttpSessionBindingListener怎麽用?Java HttpSessionBindingListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpSessionBindingListener類屬於javax.servlet.http包,在下文中一共展示了HttpSessionBindingListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: attributeUpdated
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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));
}
}
示例2: serializeState
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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;
}
示例3: shouldUnbindOnInvalidate
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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));
}
示例4: removeAttribute
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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);
}
示例5: serializeState
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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;
}
示例6: serializeState
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
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;
}
示例7: serializeState
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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;
}
示例8: setAttribute
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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) { }
}
}
示例9: cleanUpAttributes
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
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) { }
}
}
示例10: serializeState
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
/**
* 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;
}
示例11: isWeb
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
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;
}
示例12: removeAttribute
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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);
}
}
示例13: setAttribute
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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));
}
}
示例14: attributeAdded
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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));
}
}
示例15: attributeRemoved
import javax.servlet.http.HttpSessionBindingListener; //導入依賴的package包/類
@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));
}
}
}