org.apache.catalina.filters.CorsFilter Java Examples
The following examples show how to use
org.apache.catalina.filters.CorsFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringWebInitializer.java From Spring-5.0-Cookbook with MIT License | 6 votes |
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, "/*"); }
Example #2
Source File: SpringWebinitializer.java From Spring-5.0-Cookbook with MIT License | 6 votes |
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, "/*"); }
Example #3
Source File: CheCorsFilter.java From che with Eclipse Public License 2.0 | 5 votes |
@Override public void init(FilterConfig filterConfig) throws ServletException { corsFilter = new CorsFilter(); corsFilter.init(cheCorsFilterConfig); LOG.debug( "CORS initialized with parameters: 'cors.support.credentials': '{}', 'cors.allowed.origins': '{}'", cheCorsFilterConfig.getInitParameter("cors.support.credentials"), cheCorsFilterConfig.getInitParameter("cors.allowed.origins")); }
Example #4
Source File: OnPremisesIdeApiServletModule.java From codenvy with Eclipse Public License 1.0 | 4 votes |
@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()); }