Example usage for javax.servlet ServletContext addListener

List of usage examples for javax.servlet ServletContext addListener

Introduction

In this page you can find the example usage for javax.servlet ServletContext addListener.

Prototype

public void addListener(Class<? extends EventListener> listenerClass);

Source Link

Document

Adds a listener of the given class type to this ServletContext.

Usage

From source file:ru.war.name.application.config.Initializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    // ??   Spring ?
    ctx.register(SpringWebConfig.class);
    ctx.register(SpringSecurityConfig.class);
    servletContext.addListener(new ContextLoaderListener(ctx));

    ctx.setServletContext(servletContext);

    Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);// w  w  w .ja  v a2 s  .  c  o  m
}

From source file:org.shaigor.rest.retro.client.config.ClientSecureWebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    super.onStartup(servletContext);
    registerProxyFilter(servletContext, "springSecurityFilterChain");
    registerProxyFilter(servletContext, "oauth2ClientContextFilter");
    registerProxyFilter(servletContext, "customOauth2ClientContextFilter");
    servletContext.addListener(RequestContextListener.class);
}

From source file:com.oreilly.springdata.rest.RestWebApplicationInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(ApplicationConfig.class);

    // Manage the lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

    // Register and map the dispatcher servlet
    DispatcherServlet servlet = new RepositoryRestExporterServlet();
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", servlet);
    dispatcher.setLoadOnStartup(1);//www  . j  av  a 2  s .  com
    dispatcher.addMapping("/");
}

From source file:ch.javaee.basicMvc.WebInitializer.java

@Override
public void onStartup(ServletContext container) throws ServletException {

    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppConfiguration.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);/*  w  w w. j ava  2s . c om*/
    dispatcher.addMapping("/");

}

From source file:org.avidj.zuul.rs.ZuulInitializer.java

@Override
public void onStartup(ServletContext container) {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootContextConfiguration.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(MvcContextConfiguration.class);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(dispatcherContext));
    dispatcher.setLoadOnStartup(1);/*from  w  w w.j  av  a 2 s .  c  om*/
    dispatcher.addMapping("/");
}

From source file:com.sky.HibakeSeoBootApplication.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    log.info(" prerenderFilter ");
    //servletContext.addFilter("prerenderFilter", PrerenderFilter.class);
    servletContext.addFilter("seoFilter", CustomSEOFilter.class);
    WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
    if (rootAppContext != null) {
        servletContext.addListener(new ContextLoaderListener(rootAppContext) {
            @Override/*from www.j  av  a  2 s .  c o  m*/
            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");
    }

}

From source file:com.olegchir.fadeok.init.AppInitializer.java

public void onStartup(ServletContext servletContext) throws ServletException {
    System.out.println("Initializing Application for " + servletContext.getServerInfo());

    //Create webapp context
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.setConfigLocation(CONFIG_LOCATION);

    servletContext.addListener(new ContextLoaderListener(applicationContext));
    //        servletContext.addListener(new CompleteAutoloadTilesListener());

    // Add the servlet mapping manually and make it initialize automatically
    DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet);

    servlet.addMapping("/");
    servlet.setAsyncSupported(true);//from   w  ww  .j a  va  2  s  .  c  o m
    servlet.setLoadOnStartup(1);
}

From source file:com.digitgroup.fullstackroad.spring.config.web.WebAppInitializer.java

@Override
public void onStartup(ServletContext container) {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppRootConfig.class, PersistenceConfig.class);

    // Manage the lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(WebConfig.class);

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);//from   w w  w  .  jav a  2 s. co  m
    dispatcher.addMapping("/");

}

From source file:com.econcept.init.MainWebAppplicationInitializer.java

@Override
public void onStartup(ServletContext pContainer) throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext lRootContext = new AnnotationConfigWebApplicationContext();
    lRootContext.scan("com.econcept.init");

    // Manage the lifecycle of the root application context
    pContainer.addListener(new ContextLoaderListener(lRootContext));

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic lDispatcher = pContainer.addServlet("CFXServlet", CXFServlet.class);
    lDispatcher.addMapping("/rest/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    FilterRegistration.Dynamic lFilter = pContainer.addFilter("unicodeFilter", new UnicodeFilter());
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    // Apply Spring OAuthSecurity to both forward and request dispatcher
    lFilter = pContainer.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");

    pContainer.addListener(AppHttpSessionListener.class);

}

From source file:com.gantzgulch.sharing.configuration.WebInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    appContext.getEnvironment().setActiveProfiles("production");
    appContext.scan("com.gantzgulch.sharing");

    ContextLoaderListener contextListener = new ContextLoaderListener(appContext);
    servletContext.addListener(contextListener);

    DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration.Dynamic filter = servletContext.addFilter("securityFilter", filterProxy);
    filter.addMappingForUrlPatterns(null, false, "/*");

    AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
    webContext.register(MvcAppConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("sharing",
            new DispatcherServlet(webContext));
    dispatcher.setLoadOnStartup(1);//from   www.  ja  va2s  . c o m
    dispatcher.addMapping("*.htm");
}