Java 类org.apache.catalina.filters.CorsFilter 实例源码

项目:Spring-5.0-Cookbook    文件:SpringWebInitializer.java   
private void addDispatcherContext(ServletContext container) {
    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(SpringDispatcherConfig.class);

    // Declare <servlet> and <servlet-mapping> for the DispatcherServlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
            new DispatcherServlet(dispatcherContext));
    dispatcher.addMapping("*.html");
    dispatcher.setLoadOnStartup(1);

    FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
    corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
    corsFilter.addMappingForUrlPatterns(null, true, "/*");

    FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
    filter.addMappingForServletNames(null, true, "/*");

    FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
    multipartFilter.addMappingForUrlPatterns(null, true, "/*");

}
项目:Spring-5.0-Cookbook    文件:SpringWebinitializer.java   
private void addDispatcherContext(ServletContext container) {
    // Create the dispatcher servlet's Spring application context
    AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
    dispatcherContext.register(SpringDispatcherConfig.class);

    // Declare <servlet> and <servlet-mapping> for the DispatcherServlet
    ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
            new DispatcherServlet(dispatcherContext));
    dispatcher.addMapping("*.html");
    dispatcher.setLoadOnStartup(1);

    FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
    corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
    corsFilter.addMappingForUrlPatterns(null, true, "/*");

    FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
    filter.addMappingForServletNames(null, true, "/*");

    FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
    multipartFilter.addMappingForUrlPatterns(null, true, "/*");

}
项目:che    文件:WsMasterServletModule.java   
@Override
protected void configureServlets() {
  getServletContext().addListener(new org.everrest.websockets.WSConnectionTracker());

  final Map<String, String> corsFilterParams = new HashMap<>();
  corsFilterParams.put("cors.allowed.origins", "*");
  corsFilterParams.put(
      "cors.allowed.methods", "GET," + "POST," + "HEAD," + "OPTIONS," + "PUT," + "DELETE");
  corsFilterParams.put(
      "cors.allowed.headers",
      "Content-Type,"
          + "X-Requested-With,"
          + "accept,"
          + "Origin,"
          + "Access-Control-Request-Method,"
          + "Access-Control-Request-Headers");
  corsFilterParams.put("cors.support.credentials", "true");
  // preflight cache is available for 10 minutes
  corsFilterParams.put("cors.preflight.maxage", "10");
  bind(CorsFilter.class).in(Singleton.class);

  filter("/*").through(CorsFilter.class, corsFilterParams);
  filter("/*").through(RequestIdLoggerFilter.class);

  serveRegex("^/(?!ws$|ws/|websocket.?)(.*)").with(GuiceEverrestServlet.class);
  install(new org.eclipse.che.swagger.deploy.BasicSwaggerConfigurationModule());

  if (Boolean.valueOf(System.getenv("CHE_MULTIUSER"))) {
    configureMultiUserMode();
  } else {
    configureSingleUserMode();
  }
}
项目:codenvy    文件:OnPremisesIdeApiServletModule.java   
@Override
protected void configureServlets() {
  filter(pathForLoginFilter).through(com.codenvy.auth.sso.client.LoginFilter.class);

  // comma separated list of paths like "/service1,/service2"
  bindConstant().annotatedWith(Names.named("csrf_filter.paths_accepting_parameters")).to("/ssh");
  filter(pathForLoginFilter).through(CodenvyCsrfFilter.class);

  final Map<String, String> corsFilterParams = new HashMap<>();
  corsFilterParams.put("cors.allowed.origins", DEFAULT_ALLOWED_ORIGINS);
  corsFilterParams.put(
      "cors.allowed.methods", "GET," + "POST," + "HEAD," + "OPTIONS," + "PUT," + "DELETE");
  corsFilterParams.put(
      "cors.allowed.headers",
      "Content-Type,"
          + "X-Requested-With,"
          + "accept,"
          + "Origin,"
          + "Access-Control-Request-Method,"
          + "Access-Control-Request-Headers");
  corsFilterParams.put("cors.support.credentials", "true");
  // preflight cache is available for 10 minutes
  corsFilterParams.put("cors.preflight.maxage", "10");
  bind(CorsFilter.class).in(Singleton.class);
  filter("/*").through(CorsFilter.class, corsFilterParams);

  bind(com.codahale.metrics.servlets.ThreadDumpServlet.class).in(Singleton.class);
  bind(com.codahale.metrics.servlets.PingServlet.class).in(Singleton.class);
  serve("/metrics/ping").with(com.codahale.metrics.servlets.PingServlet.class);
  serve("/metrics/threaddump").with(com.codahale.metrics.servlets.ThreadDumpServlet.class);

  serve("/oauth").with(com.codenvy.auth.sso.oauth.OAuthLoginServlet.class);
  filter("/oauth").through(com.codenvy.auth.sso.oauth.OauthLoginFilter.class);
  install(new com.codenvy.auth.sso.client.deploy.SsoClientServletModule());
  serveRegex("^((?!(\\/(ws|eventbus|websocket)($|\\/.*)))\\/.*)")
      .with(org.everrest.guice.servlet.GuiceEverrestServlet.class);

  getServletContext().addListener(new WSConnectionTracker());
  install(new com.codenvy.auth.sso.client.deploy.SsoClientServletModule());
  install(new BasicSwaggerConfigurationModule());
}
项目:che    文件:CheCorsFilter.java   
@Override
public void init(FilterConfig filterConfig) throws ServletException {
  corsFilter = new CorsFilter();

  corsFilter.init(new CheCorsFilterConfig());
}
项目:swutils    文件:CorsValve.java   
public CorsValve() throws ServletException {
    super(new CorsFilter());
}