Fixed SEC-395

This commit is contained in:
Ray Krueger 2006-11-20 19:09:45 +00:00
parent 9d2fe0e037
commit 74e8efc4e9
2 changed files with 6 additions and 29 deletions

View File

@ -45,9 +45,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
//~ Instance fields ================================================================================================
private ApplicationContext appContext;
private ServletContext servletContext = null;
//~ Methods ========================================================================================================
/**
@ -67,21 +64,10 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
if (log.isDebugEnabled()) {
log.debug("Received ServletContextEvent: " + event);
}
appContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
if (appContext == null) {
log.warn("Web application context is null. Will delay initialization until it's first used.");
servletContext = event.getServletContext();
}
}
ApplicationContext getContext() {
if (appContext == null) {
appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
return appContext;
ApplicationContext getContext(ServletContext servletContext) {
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
}
/**
@ -97,7 +83,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
log.debug("Publishing event: " + e);
}
getContext().publishEvent(e);
getContext(event.getSession().getServletContext()).publishEvent(e);
}
/**
@ -113,6 +99,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
log.debug("Publishing event: " + e);
}
getContext().publishEvent(e);
getContext(event.getSession().getServletContext()).publishEvent(e);
}
}

View File

@ -46,16 +46,6 @@ public class HttpSessionEventPublisherTests extends TestCase {
context.setServletContext(servletContext);
}
public void testGetContextThrowsExceptionIfContextNotSet() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
publisher.contextInitialized(new ServletContextEvent(new MockServletContext()));
try {
publisher.getContext();
fail("IllegalStateException expected when no context set");
} catch (IllegalStateException expected) {}
}
/**
* It's not that complicated so we'll just run it straight through here.
*/
@ -73,10 +63,11 @@ public class HttpSessionEventPublisherTests extends TestCase {
publisher.contextInitialized(new ServletContextEvent(servletContext));
MockHttpSession session = new MockHttpSession();
MockHttpSession session = new MockHttpSession(servletContext);
TestListener listener = (TestListener) context.getBean("listener");
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionCreated(event);
assertNotNull(listener.getCreatedEvent());