@Override
  public void addFilter(final FilterModel filterModel) {
    LOG.debug("add filter [{}]", filterModel);
    final ServletContext servletContext = findOrCreateServletContext(filterModel);
    final FilterRegistration.Dynamic filterRegistration =
        servletContext.addFilter(filterModel.getName(), filterModel.getFilter());
    if (filterModel.getServletNames() != null) {
      filterRegistration.addMappingForServletNames(
          getDispatcherTypes(filterModel), /*
													 * TODO get asynch
													 * supported?
													 */ false, filterModel.getServletNames());
    } else if (filterModel.getUrlPatterns() != null) {
      filterRegistration.addMappingForServletNames(
          getDispatcherTypes(filterModel), /*
													 * TODO get asynch
													 * supported?
													 */ false, filterModel.getUrlPatterns());
    } else {
      throw new AddFilterException(
          "cannot add filter to the context; at least a not empty list of servlet names or URL patterns in exclusive mode must be provided: "
              + filterModel);
    }
    filterRegistration.setInitParameters(filterModel.getInitParams());
    // filterRegistration.setAsyncSupported(filterModel.); TODO FIXME see
    // how to get this info... ? see above
  }
  /**
   * A Molgenis common web application initializer
   *
   * @param servletContext
   * @param appConfig
   * @param isDasUsed is the molgenis-omx-das module used?
   * @throws ServletException
   */
  protected void onStartup(ServletContext servletContext, Class<?> appConfig, boolean isDasUsed)
      throws ServletException {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(appConfig);

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

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcherServlet =
        servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    if (dispatcherServlet == null) {
      logger.warn(
          "ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'");
    } else {
      final int maxSize = 32 * 1024 * 1024;
      int loadOnStartup = (isDasUsed ? 2 : 1);
      dispatcherServlet.setLoadOnStartup(loadOnStartup);
      dispatcherServlet.addMapping("/");
      dispatcherServlet.setMultipartConfig(
          new MultipartConfigElement(null, maxSize, maxSize, maxSize));
      dispatcherServlet.setInitParameter("dispatchOptionsRequest", "true");
    }

    // add filters
    javax.servlet.FilterRegistration.Dynamic etagFilter =
        servletContext.addFilter("etagFilter", new ShallowEtagHeaderFilter());
    etagFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "dispatcher");

    // enable use of request scoped beans in FrontController
    servletContext.addListener(new RequestContextListener());
  }
示例#3
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.info("Web application configuration");

    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(ApplicationConfiguration.class);
    rootContext.refresh();

    servletContext.setAttribute(
        WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);

    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfig =
        new AnnotationConfigWebApplicationContext();
    dispatcherServletConfig.setParent(rootContext);
    dispatcherServletConfig.register(DispatcherServletConfig.class);

    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet =
        servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfig));
    dispatcherServlet.addMapping("/tatami/*");
    dispatcherServlet.setLoadOnStartup(2);

    log.debug("Registering Meteor Servlet for online users");

    ServletRegistration.Dynamic meteorServlet =
        servletContext.addServlet("atmosphereServlet", new MeteorServlet());

    meteorServlet.setAsyncSupported(true);
    meteorServlet.addMapping("/realtime/*");
    meteorServlet.setLoadOnStartup(3);

    meteorServlet.setInitParameter(
        "org.atmosphere.servlet", "fr.ippon.tatami.web.atmosphere.users.OnlineUsersServlet");

    meteorServlet.setInitParameter(
        "org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.HeaderBroadcasterCache");

    meteorServlet.setInitParameter(
        "org.atmosphere.cpr.broadcastFilterClasses",
        "org.atmosphere.client.TrackMessageSizeFilter");

    meteorServlet.setInitParameter("org.atmosphere.useNative", "true");

    log.debug("Registering Spring Security Filter");
    FilterRegistration.Dynamic springSecurityFilter =
        servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
    EnumSet<DispatcherType> disps =
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    springSecurityFilter.addMappingForServletNames(disps, true, "dispatcher", "atmosphereServlet");

    log.debug("Web application fully configured");
  }
示例#4
0
 @Override
 protected void doAdditionalModuleStartLogic() throws Exception {
   if (StringUtils.isNotBlank(dispatchServletName)) {
     DispatcherServlet loaderServlet =
         new DispatcherServlet(
             (WebApplicationContext)
                 ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0))
                     .getContext());
     ServletRegistration registration =
         getServletContext().addServlet(dispatchServletName, loaderServlet);
     registration.addMapping("/" + dispatchServletName + "/*");
     if (dispatchServletMappings != null) {
       dispatchServletMappings
           .stream()
           .map(mapping -> "/" + mapping + "/*")
           .forEach(registration::addMapping);
     }
     if (mapFilters) {
       for (String filterName : filtersToMap) {
         FilterRegistration filter = getServletContext().getFilterRegistration(filterName);
         filter.addMappingForServletNames(null, true, dispatchServletName);
       }
     }
     if (enableSpringSecurity) {
       DelegatingFilterProxy filterProxy =
           new DelegatingFilterProxy(
               SPRING_SECURITY_FILTER_CHAIN,
               (WebApplicationContext)
                   ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0))
                       .getContext());
       FilterRegistration.Dynamic securityFilter =
           getServletContext()
               .addFilter(KC_PREFIX + getModuleName() + SPRING_SECURITY_FILTER_PROXY, filterProxy);
       securityFilter.addMappingForServletNames(null, true, dispatchServletName);
     }
   }
 }
示例#5
0
 private void registerHiddenHttpMethodFilter(ServletContext servletContext) {
   FilterRegistration.Dynamic fr =
       servletContext.addFilter("hiddenHttpMethodFilter", HiddenHttpMethodFilter.class);
   fr.addMappingForServletNames(
       EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, DISPATCHER_SERVLET_NAME);
 }