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:com.controller.config.MainWebApplicationInitizer.java

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

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.scan("com.controller.config");

    servletContext.addListener(new ContextLoaderListener(rootContext));

    ServletRegistration.Dynamic dispather = servletContext.addServlet("CXFServlet", CXFServlet.class);

    dispather.addMapping("/rest/*");
}

From source file:com.kabiliravi.kaman.web.KamanApplicationInitializer.java

private void registerDispatcherServlet(final ServletContext servletContext) {
    WebApplicationContext dispatcherContext = createContext(WebMvcContextConfiguration.class);
    servletContext.addListener(new ContextLoaderListener(dispatcherContext));
    servletContext.addListener(new RequestContextListener());
    DispatcherServlet dispatcherServlet = new DispatcherServlet(dispatcherContext);
    ServletRegistration.Dynamic dispatcher;
    dispatcher = servletContext.addServlet("dispatcher", dispatcherServlet);
    dispatcher.setLoadOnStartup(1);//  w  w w.  jav  a 2 s  .  c  o m
    dispatcher.addMapping("/");
}

From source file:de.interseroh.report.webapp.UiWebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    logger.info("WebApp *report-cockpit-birt-web* starts...");

    WebApplicationContext rootContext = getRootContext();
    servletContext.addListener(new ContextLoaderListener(rootContext));
    servletContext.addListener(new SessionListener());

    addMvcServlet(servletContext);/* ww  w .  j a v  a2s  .com*/
    addSecurityFilter(servletContext);

    logger.info("WebApp *report-cockpit-birt-web* ready...");
}

From source file:gr.pskoufos.initializer.AppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(AppConfig.class);
    ctx.setServletContext(servletContext);
    servletContext.addListener(new ContextLoaderListener(ctx));
    servletContext.addListener(new RequestContextListener());
    Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
    dynamic.addMapping("/");
    dynamic.setLoadOnStartup(1);/*from   w  ww  . ja  v  a 2s.  c  o m*/
}

From source file:com.coffeebeans.services.config.initializer.WebAppInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppConfig.class);
    servletContext.addListener(new ContextLoaderListener(rootContext));

    AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet(MVC_DISPATCHER_NAME,
            new DispatcherServlet(dispatcherServlet));
    dispatcher.setLoadOnStartup(1);/* w w  w  .j  a v a  2 s. c om*/
    dispatcher.addMapping("/1/*");
    dispatcher.addMapping("/oauth/token");

    FilterRegistration charEncodingFilterReg = servletContext.addFilter("CharacterEncodingFilter",
            CharacterEncodingFilter.class);
    charEncodingFilterReg.setInitParameter("encoding", "UTF-8");
    charEncodingFilterReg.setInitParameter("forceEncoding", "true");
    charEncodingFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");

}

From source file:com.github.marsbits.restfbmessenger.sample.EchoWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation(this.getClass().getPackage().getName());
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet",
            new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);/*from   w w w.j a  v  a2  s  .c o  m*/
    dispatcher.addMapping("/*");
}

From source file:net.rgielen.actionframeworks.struts2.ApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ApplicationConfig.class);
    servletContext.addListener(new ContextLoaderListener(context));

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);/* www . j av a  2  s .c  o  m*/
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*");

    final FilterRegistration.Dynamic struts = servletContext.addFilter("struts",
            new StrutsPrepareAndExecuteFilter());
    struts.addMappingForUrlPatterns(dispatcherTypes, false, "/*");
}

From source file:net.rgielen.actionframeworks.springmvc.ApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ApplicationConfig.class);
    servletContext.addListener(new ContextLoaderListener(context));

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);//from   ww w.jav a 2  s .  co m
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*");

    ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher",
            new DispatcherServlet(context));
    registration.setLoadOnStartup(1);
    registration.addMapping("/");

}

From source file:com.cimait.invoicec.portal.util.servlet.SBServletInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
    if (rootAppContext != null) {
        servletContext.addListener(new ContextLoaderListener(rootAppContext) {
            @Override/*from   w  w w. j a va  2 s.com*/
            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:eu.enhan.timelord.web.init.TimelordWebInit.java

/**
 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
 *///from w ww  .j a v a2  s .  com
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext();
    rootCtx.register(AppConfig.class);
    servletContext.addListener(new ContextLoaderListener(rootCtx));

    AnnotationConfigWebApplicationContext webAppCtx = new AnnotationConfigWebApplicationContext();
    webAppCtx.setParent(rootCtx);
    webAppCtx.register(WebConfig.class);

    XmlWebApplicationContext securityCtx = new XmlWebApplicationContext();
    securityCtx.setServletContext(servletContext);
    securityCtx.setParent(rootCtx);
    securityCtx.setConfigLocation("classpath:/spring/security.xml");

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(webAppCtx));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");

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

}