SEC-2599: HttpSessionEventPublisher get required ApplicationContext

In order to get better error messages (avoid NullPointerException) the
HttpSessionEventPublisher now gets the required ApplicationContext which
throws an IllegalStateException with a good error message.
This commit is contained in:
Rob Winch 2014-07-22 09:19:50 -05:00
parent 47acf17323
commit 89c5c56849
2 changed files with 23 additions and 1 deletions

View File

@ -49,7 +49,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener {
//~ Methods ========================================================================================================
ApplicationContext getContext(ServletContext servletContext) {
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
/**

View File

@ -69,4 +69,26 @@ public class HttpSessionEventPublisherTests {
assertNull(listener.getCreatedEvent());
assertEquals(session, listener.getDestroyedEvent().getSession());
}
// SEC-2599
@Test(expected=IllegalStateException.class)
public void sessionCreatedNullApplicationContext() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
MockServletContext servletContext = new MockServletContext();
MockHttpSession session = new MockHttpSession(servletContext);
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionCreated(event);
}
// SEC-2599
@Test(expected=IllegalStateException.class)
public void sessionDestroyedNullApplicationContext() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
MockServletContext servletContext = new MockServletContext();
MockHttpSession session = new MockHttpSession(servletContext);
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionDestroyed(event);
}
}