List of usage examples for javax.servlet FilterRegistration.Dynamic setInitParameter
public boolean setInitParameter(String name, String value);
From source file:com.cami.spring.core.SpringSecurityInitializer.java
@Override protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*"); }
From source file:org.hyperledger.examples.dropwizard.BlockExplorerApp.java
@Override public void run(BlockExplorerConfiguration configuration, Environment environment) throws Exception { BCSAPI api = hyperLedgerBundle.getBCSAPI(); final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); // Configure CORS parameters cors.setInitParameter("allowedOrigins", "*"); cors.setInitParameter("allowedHeaders", "*"); cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD"); // Add URL mapping cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); environment.jersey().register(new ExplorerResource(api)); }
From source file:io.appform.nautilus.funnel.FunnelServerApp.java
private void configureCors(Environment environment) { FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS"); filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); filter.setInitParameter("allowCredentials", "true"); }
From source file:net.przemkovv.sphinx.config.ApplicationInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationConfig.class, JpaConfig.class); // rootContext.refresh(); rootContext.setDisplayName("Sphinx Web Application"); servletContext.addListener(new ContextLoaderListener(rootContext)); // servletContext.addListener(new HttpSessionEventPublisher()); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(WebMvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Spring MVC Servlet", new DispatcherServlet(dispatcherContext)); dispatcher.addMapping("/app/"); dispatcher.setLoadOnStartup(1);/* w w w .java2 s. co m*/ // servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")) // .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); servletContext.addFilter("UrlRewriteFilter", new UrlRewriteFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); servletContext.addFilter("HttpPutFormContentFilter", new HttpPutFormContentFilter()) .addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic charsetFilter = servletContext.addFilter("charsetFilter", new CharacterEncodingFilter()); charsetFilter.setInitParameter("encoding", "UTF-8"); charsetFilter.setInitParameter("forceEncoding", "true"); charsetFilter.addMappingForUrlPatterns(null, true, "/*"); FilterRegistration.Dynamic dustCompilingFilter = servletContext.addFilter("dustCompilingFilter", new DustCompilingFilter()); dustCompilingFilter.setInitParameter("templateNameRegex", "/template/(.*).dust.js$"); dustCompilingFilter.addMappingForUrlPatterns(null, true, "/*"); }
From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) { WebApplicationContext rootContext = createRootContext(servletContext); configureSpringMvc(servletContext, rootContext); // Add Perf4J graphing servlet ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("perf4j", org.perf4j.logback.servlet.GraphingServlet.class); servletRegistration.setInitParameter("graphNames", "graphOtherTimes,graphQueryTimes,graphQueriesPerSecond"); servletRegistration.addMapping("/perf4j"); String TAG_SWAP_FILTER_CLASS = "org.kew.servlet.filter.TagSwapFilter"; try {/*from w w w .jav a 2s. c o m*/ Class.forName(TAG_SWAP_FILTER_CLASS, false, this.getClass().getClassLoader()); String[] urlPatterns = { "/", "/about/*", "/admin", "/filematch/*", "/help" }; FilterRegistration.Dynamic cssLinkFilter = servletContext.addFilter("CssLinkFilter", TAG_SWAP_FILTER_CLASS); cssLinkFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/head.chunk"); cssLinkFilter.setInitParameter("tag_name", "[KEWCSS]"); cssLinkFilter.addMappingForUrlPatterns(null, true, urlPatterns); FilterRegistration.Dynamic headerFilter = servletContext.addFilter("HeaderFilter", TAG_SWAP_FILTER_CLASS); headerFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/bodytop.chunk"); headerFilter.setInitParameter("tag_name", "[KEWHEADER]"); headerFilter.addMappingForUrlPatterns(null, true, urlPatterns); FilterRegistration.Dynamic footerFilter = servletContext.addFilter("FooterFilter", TAG_SWAP_FILTER_CLASS); footerFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/bodybottom.chunk"); footerFilter.setInitParameter("tag_name", "[KEWFOOTER]"); footerFilter.addMappingForUrlPatterns(null, true, urlPatterns); } catch (ClassNotFoundException e) { log.error("Kew servlet filters not in use, class {} not on classpath", TAG_SWAP_FILTER_CLASS); } }
From source file:com.sandeep.prototypes.address.AddressApplication.java
@Override public void run(AddressConfiguration addressConfiguration, Environment environment) throws Exception { FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); cors.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "POST,GET,DELETE,PUT,OPTIONS"); cors.setInitParameter("allowCredentials", "true"); environment.jersey().register(new ApiListingResourceJSON()); environment.jersey().register(new ApiDeclarationProvider()); environment.jersey().register(new ResourceListingProvider()); environment.jersey().register(new AddressResource()); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); BeanConfig config = new BeanConfig(); config.setTitle(addressConfiguration.getApplicationTitle()); config.setDescription(addressConfiguration.getApplicationDescription()); config.setTermsOfServiceUrl(addressConfiguration.getApplicationTosUrl()); config.setContact(addressConfiguration.getApplicationContact()); config.setLicense(addressConfiguration.getLicense()); config.setVersion(addressConfiguration.getVersion()); config.setBasePath(addressConfiguration.getDocsPath()); config.setResourcePackage("com.sandeep.prototypes.address.resources"); config.setScan(true);/*from w w w . j a va 2s. co m*/ }
From source file:com.tcloud.bee.key.server.jetty.config.WebAppInitializer.java
/** * Register JerseyServlet Config/*from www. j a va 2 s .c o m*/ * * @param servletContext */ private void configurationJersey(ServletContext servletContext) { FilterRegistration.Dynamic filterDinamic = servletContext.addFilter("jersey", new org.glassfish.jersey.servlet.ServletContainer()); filterDinamic.setInitParameter("javax.ws.rs.Application", "org.apache.hadoop.io.crypto.bee.key.server.jetty.config.JerseyApplicationConfig"); filterDinamic.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/api/*"); }
From source file:org.smigo.config.WebAppInitializer.java
@Override protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { super.beforeSpringSecurityFilterChain(servletContext); log.info("Starting servlet context"); log.info("contextName: " + servletContext.getServletContextName()); log.info("contextPath:" + servletContext.getContextPath()); log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion()); log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion()); log.info("majorVersion:" + servletContext.getMajorVersion()); log.info("minorVersion:" + servletContext.getMinorVersion()); log.info("serverInfo:" + servletContext.getServerInfo()); // ", virtualServerName:" + servletContext.getVirtualServerName() + log.info("toString:" + servletContext.toString()); for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) { log.info("Attribute:" + e.nextElement()); }// w w w.j a v a 2 s .c om for (Map.Entry<String, String> env : System.getenv().entrySet()) { log.info("System env:" + env.toString()); } for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) { log.info("System prop:" + prop.toString()); } final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION); log.info("Starting with profile " + profile); WebApplicationContext context = new AnnotationConfigWebApplicationContext() { { register(WebConfiguration.class); setDisplayName("SomeRandomName"); getEnvironment().setActiveProfiles(profile); } }; FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*"); servletContext.addListener(new RequestContextListener()); servletContext.addListener(new ContextLoaderListener(context)); //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains // servletContext.getSessionCookieConfig().setDomain(getDomain()); DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setThrowExceptionIfNoHandlerFound(false); servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/"); }
From source file:com.sandeep.prototypes.person.PersonApplication.java
@Override public void run(PersonConfiguration configuration, Environment environment) throws Exception { // We need CORS enabled so that swagger can access the documentation endpoint and we can // retrieve the swagger compliant json FilterRegistration.Dynamic cors = environment.servlets().addFilter(CORS_FILTER, CrossOriginFilter.class); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); cors.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, CORS_HEADERS); cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, CORS_METHODS); cors.setInitParameter("allowCredentials", "true"); environment.jersey().register(new ApiListingResourceJSON()); environment.jersey().register(new ApiDeclarationProvider()); environment.jersey().register(new ResourceListingProvider()); // environment.jersey().register(new PersonResource(configuration.getMessage())); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); BeanConfig config = new BeanConfig(); config.setTitle(configuration.getApplicationTitle()); config.setDescription(configuration.getApplicationDescription()); config.setTermsOfServiceUrl(configuration.getApplicationTosUrl()); config.setContact(configuration.getApplicationContact()); config.setLicense(configuration.getLicense()); config.setVersion(configuration.getVersion()); config.setBasePath(configuration.getDocsPath()); config.setResourcePackage("com.sandeep.prototypes.person.resources"); config.setScan(true);//from ww w.j av a 2 s .c o m }
From source file:org.davidmendoza.demo.config.StartUpConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ComponentConfig.class, DataConfig.class, MailConfig.class, WebConfig.class); context.setDisplayName("DemoApp"); FilterRegistration.Dynamic sitemeshFilter = servletContext.addFilter("sitemeshFilter", new ConfigurableSiteMeshFilter()); sitemeshFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); servletContext.addListener(new ContextLoaderListener(context)); //servletContext.setInitParameter("defaultHtmlEscape", "false"); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", servlet); appServlet.setLoadOnStartup(1);// w w w . j a v a2 s . co m appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } }