Ejemplo n.º 1
0
  /**
   * Register and configure all Servlet container components necessary to power the web application.
   */
  @Override
  public void onStartup(final ServletContext sc) throws ServletException {
    System.out.println("MyWebAppInitializer.onStartup()");

    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("org.baeldung.config.parent");
    // root.getEnvironment().setDefaultProfiles("embedded");

    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));

    // Handles requests into the application
    final AnnotationConfigWebApplicationContext childWebApplicationContext =
        new AnnotationConfigWebApplicationContext();
    childWebApplicationContext.scan("org.baeldung.config.child");
    final ServletRegistration.Dynamic appServlet =
        sc.addServlet("api", new DispatcherServlet(childWebApplicationContext));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
      throw new IllegalStateException(
          "'appServlet' could not be mapped to '/' due "
              + "to an existing mapping. This is a known issue under Tomcat versions "
              + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }

    // spring security filter
    final DelegatingFilterProxy springSecurityFilterChain =
        new DelegatingFilterProxy("springSecurityFilterChain");
    final Dynamic addedFilter =
        sc.addFilter("springSecurityFilterChain", springSecurityFilterChain);
    addedFilter.addMappingForUrlPatterns(null, false, "/*");
  }
Ejemplo n.º 2
0
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    //        rootContext.register(WebConfig.class);
    rootContext.scan("org.saiku.admin.config");

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

    servletContext.addListener(new ContextLoaderListener(rootContext));

    //        FilterRegistration.Dynamic fr = servletContext.addFilter("encodingFilter",  new
    // CharacterEncodingFilter());
    //        fr.setInitParameter("encoding", "UTF-8");
    //        fr.setInitParameter("forceEncoding", "true");
    //        fr.addMappingForUrlPatterns(null, true, "/*");

    //        FilterRegistration.Dynamic fr = servletContext.addFilter("authFilter", new
    // AuthFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
    //
    //        fr = servletContext.addFilter("requestsLoggerServletFilter", new
    // RequestsLoggerServletFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
    //
    //        fr = servletContext.addFilter("TeeFilter", new
    // ch.qos.logback.access.servlet.TeeFilter());
    //        fr.addMappingForUrlPatterns(null, true, "/*");
  }
Ejemplo n.º 3
0
  @Override
  public void onStartup(ServletContext container) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(WebConfig.class);
    ctx.scan("com.taskstrategy.data", "com.taskstrategy.business");
    ctx.setServletContext(container);
    ctx.refresh();

    container.addListener(new ContextLoaderListener(ctx));
    container.setInitParameter("defaultHtmlEscape", "true");

    FilterRegistration.Dynamic securityFilter =
        container.addFilter(
            "securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
    securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    ServletRegistration.Dynamic registration =
        container.addServlet("dispatcher", new DispatcherServlet(ctx));
    registration.setLoadOnStartup(1);
    registration.setAsyncSupported(true);
    registration.addMapping("/");
  }
  private AnnotationConfigWebApplicationContext getContext() {

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.scan("com.noofinc");
    return context;
  }