@Override public void addListener( Class<? extends EventListener> aClass ) { proxy.addListener( aClass ); }
@Override public void addListener( String s ) { proxy.addListener( s ); }
@Override public <T extends EventListener> void addListener( T t ) { proxy.addListener( t ); }
/** * Register a {@link ServletContextListener} that closes the given * application context when the servlet context is destroyed. * @param servletContext the servlet context to listen to * @param applicationContext the application context that is to be * closed when {@code servletContext} is destroyed */ protected void registerCloseListener(ServletContext servletContext, ApplicationContext applicationContext) { if (applicationContext instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext; ServletContextDestroyedListener listener = new ServletContextDestroyedListener(cac); servletContext.addListener(listener); } }
@Override protected void register(String description, ServletContext servletContext) { try { servletContext.addListener(this.listener); } catch (RuntimeException ex) { throw new IllegalStateException( "Failed to add listener '" + this.listener + "' to servlet context", ex); } }
/** * Register a {@link ServletContextListener} that closes the given * application context when the servlet context is destroyed. * @param servletContext the servlet context to listen to * @param applicationContext the application context that is to be * closed when {@code servletContext} is destroyed */ protected void registerCloseListener(ServletContext servletContext, ApplicationContext applicationContext) { if (applicationContext instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext; ServletContextDestroyedListener listener = new ServletContextDestroyedListener(cac); servletContext.addListener(listener); } }
@Override public void onStartup(ServletContext sc) throws ServletException { if (sc.getInitParameter(PAR_NAME_CTX_CONFIG_LOCATION) == null) { LOGGER.config(LocalizationMessages.REGISTERING_CTX_LOADER_LISTENER()); sc.setInitParameter(PAR_NAME_CTX_CONFIG_LOCATION, "classpath:applicationContext.xml"); sc.addListener("org.springframework.web.context.ContextLoaderListener"); sc.addListener("org.springframework.web.context.request.RequestContextListener"); } else { LOGGER.config(LocalizationMessages.SKIPPING_CTX_LODAER_LISTENER_REGISTRATION()); } } }
public void addListeners(ServletContext webappContext) { serverData.getRootContext() .getBeansOfType(ServletContextListener.class) .values() .stream() .peek(this::logListener) .forEach(listener -> webappContext.addListener(listener)); listenerData.forEach(it -> webappContext.addListener(it)); serverData.getRootContext() .getBeansOfType(ServletRequestListener.class) .values() .stream() .peek(this::logListener) .forEach(listener -> webappContext.addListener(listener)); listenerRequestData.forEach(it -> webappContext.addListener(it)); } private void logListener(ServletContextListener listener) {
@Override public void onStartup(Set<Class<?>> c, ServletContext servletContext) throws ServletException { servletContext.log("Initializing NinjaFramework in container..."); servletContext.addListener(NinjaServletListener.class); servletContext.addFilter("NinjaServletFilter", NinjaServletFilter.class) .addMappingForUrlPatterns(null, false, "/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Logger initialization is deferred in case an ordered // LogServletContextInitializer is being used this.logger = LogFactory.getLog(getClass()); WebApplicationContext rootAppContext = createRootApplicationContext( servletContext); if (rootAppContext != null) { servletContext.addListener(new ContextLoaderListener(rootAppContext) { @Override public void contextInitialized(ServletContextEvent event) { // no-op because the application context is already initialized } }); } else { this.logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not " + "return an application context"); } }
/** * Register a {@link ContextLoaderListener} against the given servlet context. The * {@code ContextLoaderListener} is initialized with the application context returned * from the {@link #createRootApplicationContext()} template method. * @param servletContext the servlet context to register the listener against */ protected void registerContextLoaderListener(ServletContext servletContext) { WebApplicationContext rootAppContext = createRootApplicationContext(); if (rootAppContext != null) { ContextLoaderListener listener = new ContextLoaderListener(rootAppContext); listener.setContextInitializers(getRootApplicationContextInitializers()); servletContext.addListener(listener); } else { logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not return an application context"); } }
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { super.onStartup(c, ctx); ctx.addListener(new StartupServletContextListener()); } }
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { if (isDisabledByConfiguration(ctx)) { StatusViaSLF4JLoggerFactory.addInfo("Due to deployment instructions will NOT register an instance of " + LogbackServletContextListener.class + " to the current web-app", this); return; } StatusViaSLF4JLoggerFactory.addInfo("Adding an instance of " + LogbackServletContextListener.class + " to the current web-app", this); LogbackServletContextListener lscl = new LogbackServletContextListener(); ctx.addListener(lscl); }
/** * Register a {@link ContextLoaderListener} against the given servlet context. The * {@code ContextLoaderListener} is initialized with the application context returned * from the {@link #createRootApplicationContext()} template method. * @param servletContext the servlet context to register the listener against */ protected void registerContextLoaderListener(ServletContext servletContext) { WebApplicationContext rootAppContext = createRootApplicationContext(); if (rootAppContext != null) { ContextLoaderListener listener = new ContextLoaderListener(rootAppContext); listener.setContextInitializers(getRootApplicationContextInitializers()); servletContext.addListener(listener); } else { logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not return an application context"); } }
/** * Alternative way for registering Joy listeners. * Sometimes servlet container does not allow adding new listener * from already added listener. This method therefore registers * the listener <i>before</i> container actually called the * callback methods. */ public static void registerInServletContext( final ServletContext servletContext, final Class<? extends JoyContextListener> joyContextListenerClass ) { try { final JoyContextListener joyContextListener = ClassUtil.newInstance(joyContextListenerClass); joyContextListener.createJoyAndInitServletContext(servletContext); } catch (Exception e) { throw new JoyException(e); } servletContext.addListener(joyContextListenerClass); }
/** * Configures servlet context. */ private void configureServletContext(final ServletContext servletContext) { servletContext.addListener(jodd.servlet.RequestContextListener.class); if (decoraEnabled) { final FilterRegistration filter = servletContext.addFilter("decora", jodd.decora.DecoraServletFilter.class); filter.addMappingForUrlPatterns(null, true, contextPath); } final FilterRegistration filter = servletContext.addFilter("madvoc", jodd.madvoc.MadvocServletFilter.class); filter.addMappingForUrlPatterns(madvocDispatcherTypes, true, contextPath); }
c.addListener(new ServletRequestListener() { @Override public void requestDestroyed(ServletRequestEvent sre) { boolean sessionSupport = Boolean.valueOf(s); if (sessionSupport && c.getMajorVersion() > 2) { c.addListener(SessionSupport.class); c.log("AtmosphereFramework : Installed " + SessionSupport.class);
public class MyWebAppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebSpringConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
@Test public void testLoadSessionEventPublisher() throws Exception { Mockito.when(context.getResource(ArgumentMatchers.contains("${APPLICATION_CONFIG_URL}"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); ArgumentCaptor<HttpSessionEventPublisher> httpSessionEventPublisherArgumentCaptor = ArgumentCaptor.forClass(HttpSessionEventPublisher.class); verify(servletContext, atLeastOnce()).addListener(httpSessionEventPublisherArgumentCaptor.capture()); assertNotNull(httpSessionEventPublisherArgumentCaptor.getValue()); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { beforeSessionRepositoryFilter(servletContext); if (this.configurationClasses != null) { AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext(); rootAppContext.register(this.configurationClasses); servletContext.addListener(new ContextLoaderListener(rootAppContext)); } insertSessionRepositoryFilter(servletContext); afterSessionRepositoryFilter(servletContext); }