Search in sources :

Example 16 with HttpSessionBindingEvent

use of javax.servlet.http.HttpSessionBindingEvent in project spring-framework by spring-projects.

the class MockHttpSession method setAttribute.

@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);
    }
}
Also used : HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) HttpSessionBindingListener(javax.servlet.http.HttpSessionBindingListener)

Example 17 with HttpSessionBindingEvent

use of javax.servlet.http.HttpSessionBindingEvent in project spring-framework by spring-projects.

the class MockHttpSession method clearAttributes.

/**
	 * 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));
        }
    }
}
Also used : HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) HttpSessionBindingListener(javax.servlet.http.HttpSessionBindingListener) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with HttpSessionBindingEvent

use of javax.servlet.http.HttpSessionBindingEvent in project wildfly by wildfly.

the class InfinispanSessionManager method removed.

@CacheEntryRemoved
public void removed(CacheEntryRemovedEvent<SessionCreationMetaDataKey, ?> event) {
    if (event.isPre()) {
        String id = event.getKey().getValue();
        InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be removed", id);
        Map.Entry<MV, AV> value = this.factory.findValue(id);
        if (value != null) {
            ImmutableSession session = this.factory.createImmutableSession(id, value);
            ImmutableSessionAttributes attributes = session.getAttributes();
            HttpSession httpSession = new ImmutableHttpSessionAdapter(session, this.context);
            for (String name : attributes.getAttributeNames()) {
                Object attribute = attributes.getAttribute(name);
                if (attribute instanceof HttpSessionBindingListener) {
                    HttpSessionBindingListener listener = (HttpSessionBindingListener) attribute;
                    listener.valueUnbound(new HttpSessionBindingEvent(httpSession, name, attribute));
                }
            }
            if (this.recorder != null) {
                this.recorder.record(session);
            }
        }
    }
}
Also used : HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) ImmutableSessionAttributes(org.wildfly.clustering.web.session.ImmutableSessionAttributes) ImmutableSession(org.wildfly.clustering.web.session.ImmutableSession) HttpSession(javax.servlet.http.HttpSession) HttpSessionBindingListener(javax.servlet.http.HttpSessionBindingListener) Map(java.util.Map) ImmutableHttpSessionAdapter(org.wildfly.clustering.web.session.ImmutableHttpSessionAdapter) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved)

Example 19 with HttpSessionBindingEvent

use of javax.servlet.http.HttpSessionBindingEvent in project gocd by gocd.

the class MockHttpSession method removeAttribute.

@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));
    }
}
Also used : HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) HttpSessionBindingListener(javax.servlet.http.HttpSessionBindingListener)

Example 20 with HttpSessionBindingEvent

use of javax.servlet.http.HttpSessionBindingEvent in project gocd by gocd.

the class MockHttpSession method setAttribute.

@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);
    }
}
Also used : HttpSessionBindingEvent(javax.servlet.http.HttpSessionBindingEvent) HttpSessionBindingListener(javax.servlet.http.HttpSessionBindingListener)

Aggregations

HttpSessionBindingEvent (javax.servlet.http.HttpSessionBindingEvent)22 HttpSessionBindingListener (javax.servlet.http.HttpSessionBindingListener)17 Map (java.util.Map)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 HttpSession (javax.servlet.http.HttpSession)4 Serializable (java.io.Serializable)3 HttpSessionAttributeListener (javax.servlet.http.HttpSessionAttributeListener)3 IOException (java.io.IOException)2 NotSerializableException (java.io.NotSerializableException)2 WriteAbortedException (java.io.WriteAbortedException)2 ServletContext (javax.servlet.ServletContext)2 ServletRequestEvent (javax.servlet.ServletRequestEvent)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ServletsMockitoUtil.createHttpSessionBindingEvent (jodd.petite.ServletsMockitoUtil.createHttpSessionBindingEvent)2 ServletsMockitoUtil.createServletRequestEvent (jodd.petite.ServletsMockitoUtil.createServletRequestEvent)2 Ses (jodd.petite.tst.Ses)2 RequestContextListener (jodd.servlet.RequestContextListener)2 Context (org.apache.catalina.Context)2 Test (org.junit.Test)2