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:
		
							parent
							
								
									9654817fd8
								
							
						
					
					
						commit
						e14e5b42fc
					
				|  | @ -49,7 +49,7 @@ public class HttpSessionEventPublisher implements HttpSessionListener { | ||||||
|     //~ Methods ======================================================================================================== |     //~ Methods ======================================================================================================== | ||||||
| 
 | 
 | ||||||
|     ApplicationContext getContext(ServletContext servletContext) { |     ApplicationContext getContext(ServletContext servletContext) { | ||||||
|         return WebApplicationContextUtils.getWebApplicationContext(servletContext); |         return WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
|  | @ -69,4 +69,26 @@ public class HttpSessionEventPublisherTests { | ||||||
|         assertNull(listener.getCreatedEvent()); |         assertNull(listener.getCreatedEvent()); | ||||||
|         assertEquals(session, listener.getDestroyedEvent().getSession()); |         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); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue