javax.servlet.http.HttpSessionBindingEvent

Here are the examples of the java api class javax.servlet.http.HttpSessionBindingEvent taken from open source projects.

1. ApplicationListeners#httpSessionAttributeReplaced()

Project: undertow
File: ApplicationListeners.java
public void httpSessionAttributeReplaced(final HttpSession session, final String name, final Object value) {
    if (!started) {
        return;
    }
    final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
    for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
        this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeReplaced(sre);
    }
}

2. ApplicationListeners#httpSessionAttributeRemoved()

Project: undertow
File: ApplicationListeners.java
public void httpSessionAttributeRemoved(final HttpSession session, final String name, final Object value) {
    if (!started) {
        return;
    }
    final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
    for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
        this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeRemoved(sre);
    }
}

3. ApplicationListeners#httpSessionAttributeAdded()

Project: undertow
File: ApplicationListeners.java
public void httpSessionAttributeAdded(final HttpSession session, final String name, final Object value) {
    if (!started) {
        return;
    }
    final HttpSessionBindingEvent sre = new HttpSessionBindingEvent(session, name, value);
    for (int i = 0; i < httpSessionAttributeListeners.length; ++i) {
        this.<HttpSessionAttributeListener>get(httpSessionAttributeListeners[i]).attributeAdded(sre);
    }
}

4. MySessionTest#testBindNotifiesValueIfIsHttpSessionBindingListener()

Project: sakai
File: MySessionTest.java
public void testBindNotifiesValueIfIsHttpSessionBindingListener() {
    MySession session = createSession();
    ListeningAttribValue attribValue = new ListeningAttribValue();
    session.bind("SESSION_KEY", attribValue);
    assertEquals(1, attribValue.httpSessionValueBoundInvokedWith.size());
    HttpSessionBindingEvent event = attribValue.httpSessionValueBoundInvokedWith.get(0);
    assertEventState(event, "SESSION_KEY", session, attribValue);
}

5. MySessionTest#testUnbindNotifiesValueIfIsHttpSessionBindingListener()

Project: sakai
File: MySessionTest.java
public void testUnbindNotifiesValueIfIsHttpSessionBindingListener() {
    MySession session = createSession();
    ListeningAttribValue attribValue = new ListeningAttribValue();
    session.unBind("SESSION_KEY", attribValue);
    assertEquals(1, attribValue.httpSessionValueUnboundInvokedWith.size());
    HttpSessionBindingEvent event = attribValue.httpSessionValueUnboundInvokedWith.get(0);
    assertEventState(event, "SESSION_KEY", session, attribValue);
}

6. ShutdownTest#testSessionShutdown()

Project: jodd
File: ShutdownTest.java
@Test
public void testSessionShutdown() {
    // http session
    HttpSession session = createSession("S2");
    HttpServletRequest request = createRequest(session);
    ServletRequestEvent requestEvent = createServletRequestEvent(request);
    HttpSessionBindingEvent event = createHttpSessionBindingEvent(session);
    // jodd
    RequestContextListener requestContextListener = new RequestContextListener();
    // start session, init request
    requestContextListener.requestInitialized(requestEvent);
    // petite
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Ses.class, null, null, null, false);
    Ses ses = (Ses) pc.getBean("ses");
    assertNotNull(ses);
    ses.setValue("jodd");
    // session not expired
    assertEquals("jodd", ses.getValue());
    // shutdown
    pc.shutdown();
    assertEquals("-jodd", ses.getValue());
}

7. ShutdownTest#testSessionExpired()

Project: jodd
File: ShutdownTest.java
@Test
public void testSessionExpired() {
    // http session
    HttpSession session = createSession("S1");
    HttpServletRequest request = createRequest(session);
    ServletRequestEvent requestEvent = createServletRequestEvent(request);
    HttpSessionBindingEvent event = createHttpSessionBindingEvent(session);
    // jodd
    RequestContextListener requestContextListener = new RequestContextListener();
    // start session, init request
    requestContextListener.requestInitialized(requestEvent);
    // petite
    PetiteContainer pc = new PetiteContainer();
    pc.registerPetiteBean(Ses.class, null, null, null, false);
    // callback not yet added
    SessionScope.SessionBeans sessionBeans = (SessionScope.SessionBeans) session.getAttribute(ATTR_NAME);
    assertNull(sessionBeans);
    Ses ses = (Ses) pc.getBean("ses");
    assertNotNull(ses);
    // callback added
    sessionBeans = (SessionScope.SessionBeans) session.getAttribute(ATTR_NAME);
    assertNotNull(sessionBeans);
    ses.setValue("jodd");
    // session expired
    sessionBeans.valueUnbound(event);
    assertEquals("-jodd", ses.getValue());
    pc.shutdown();
    assertEquals("-jodd", ses.getValue());
}

8. ServletsMockitoUtil#createHttpSessionBindingEvent()

Project: jodd
File: ServletsMockitoUtil.java
public static HttpSessionBindingEvent createHttpSessionBindingEvent(HttpSession session) {
    HttpSessionBindingEvent sessionBindingEvent = mock(HttpSessionBindingEvent.class);
    when(sessionBindingEvent.getSession()).thenReturn(session);
    return sessionBindingEvent;
}