List of usage examples for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns);
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:fi.helsinki.opintoni.config.WebConfigurer.java
/** * Initializes Metrics.// w w w . j a v a 2 s . c o m */ private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) { log.debug("Initializing Metrics registries"); servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, metricRegistry); servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); log.debug("Registering Metrics Filter"); FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter", new InstrumentedFilter()); metricsFilter.addMappingForUrlPatterns(disps, true, "/*"); metricsFilter.setAsyncSupported(true); log.debug("Registering Metrics Servlet"); ServletRegistration.Dynamic metricsAdminServlet = servletContext.addServlet("metricsServlet", new MetricsServlet()); metricsAdminServlet.addMapping("/metrics/metrics/*"); metricsAdminServlet.setAsyncSupported(true); metricsAdminServlet.setLoadOnStartup(2); }
From source file:org.brutusin.rpc.RpcWebInitializer.java
public void onStartup(final ServletContext ctx) throws ServletException { final RpcServlet rpcServlet = registerRpcServlet(ctx); final WebsocketFilter websocketFilter = new WebsocketFilter(); FilterRegistration.Dynamic dynamic = ctx.addFilter(WebsocketFilter.class.getName(), websocketFilter); dynamic.addMappingForUrlPatterns(null, false, RpcConfig.getInstance().getPath() + "/wskt"); JsonCodec.getInstance().registerStringFormat(MetaDataInputStream.class, "inputstream"); final Bean<RpcSpringContext> rpcCtxBean = new Bean<RpcSpringContext>(); ctx.addListener(new ServletRequestListener() { public void requestDestroyed(ServletRequestEvent sre) { GlobalThreadLocal.clear();//from ww w. j a v a 2 s.c o m } public void requestInitialized(ServletRequestEvent sre) { GlobalThreadLocal.set(new GlobalThreadLocal((HttpServletRequest) sre.getServletRequest(), null)); } }); ctx.addListener(new ServletContextListener() { public void contextInitialized(ServletContextEvent sce) { RpcSpringContext rpcCtx = createRpcSpringContext(ctx); rpcCtxBean.setValue(rpcCtx); rpcServlet.setRpcCtx(rpcCtx); initWebsocketRpcRuntime(ctx, rpcCtx); ctx.setAttribute(RpcSpringContext.class.getName(), rpcCtx); } public void contextDestroyed(ServletContextEvent sce) { LOGGER.info("Destroying RPC context"); if (rpcCtxBean.getValue() != null) { rpcCtxBean.getValue().destroy(); } } }); ctx.addListener(new ServletContextAttributeListener() { public void attributeAdded(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } public void attributeRemoved(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } public void attributeReplaced(ServletContextAttributeEvent event) { if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) { updateRootContext(); } } private void updateRootContext() { WebApplicationContext rootCtx = WebApplicationContextUtils.getWebApplicationContext(ctx); if (rootCtx != null) { if (rpcCtxBean.getValue() != null) { rpcCtxBean.getValue().setParent(rootCtx); } if (rootCtx.containsBean("springSecurityFilterChain")) { LOGGER.info("Moving WebsocketFilter behind springSecurityFilterChain"); websocketFilter.disable(); FilterChainProxy fcp = (FilterChainProxy) rootCtx.getBean("springSecurityFilterChain"); fcp.getFilterChains().get(0).getFilters().add(new WebsocketFilter()); } } } }); }
From source file:com.zxy.commons.hystrix.web.HystrixInitializer.java
/** * {@inheritDoc}/* w w w.j ava2s. c o m*/ */ public void onStartup(ServletContext container) throws ServletException { // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); Properties properties = load(); String enabled = properties.getProperty(HystrixProperties.HYSTRIX_ENABLED); String streamEnabled = properties.getProperty(HystrixProperties.HYSTRIX_STREAM_ENABLED); if ((StringUtils.isBlank(enabled) || "true".equalsIgnoreCase(enabled)) && (StringUtils.isBlank(streamEnabled) || "true".equalsIgnoreCase(streamEnabled))) { // AnnotationConfigWebApplicationContext ctx = new // AnnotationConfigWebApplicationContext(); // ctx.register(AppConfig.class); // ctx.setServletContext(container); // ServletRegistration.Dynamic servlet = // container.addServlet("dispatcher", new DispatcherServlet(ctx)); // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); // servlet.setLoadOnStartup(1); // servlet.addMapping("/"); FilterRegistration.Dynamic hystrixRequestContextServletFilter = container .addFilter("HystrixRequestContextServletFilter", new HystrixRequestContextServletFilter()); hystrixRequestContextServletFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FilterRegistration.Dynamic hystrixRequestLogViaResponseHeaderServletFilter = container.addFilter( "HystrixRequestLogViaResponseHeaderServletFilter", new HystrixRequestLogViaResponseHeaderServletFilter()); hystrixRequestLogViaResponseHeaderServletFilter .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); ServletRegistration.Dynamic hystrixMetricsStreamServlet = container .addServlet("HystrixMetricsStreamServlet", new HystrixMetricsStreamServlet()); hystrixMetricsStreamServlet.addMapping("/hystrix.stream"); // ServletRegistration.Dynamic proxyStreamServlet = // container.addServlet("ProxyStreamServlet", new // ProxyStreamServlet()); // proxyStreamServlet.addMapping("/proxy.stream"); } }
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);/*from w w w. jav a 2s . c om*/ // 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.obiba.mica.config.WebConfiguration.java
private void initAllowedMethods(ServletContext servletContext) { log.debug("Registering Allowed Methods Filter"); FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("noTrace", new NoTraceFilter()); filterRegistration.addMappingForUrlPatterns(EnumSet.of(REQUEST, FORWARD, ASYNC, INCLUDE, ERROR), true, "/*"); filterRegistration.setAsyncSupported(true); }
From source file:fr.treeptik.cloudunit.initializer.ApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CloudUnitApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/*from w ww . j a v a 2s . c om*/ dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); dispatcher.setAsyncSupported(true); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/nopublic/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:cn.org.once.cstack.initializer.ApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(CloudUnitApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/*from w ww. ja va2 s .com*/ dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); dispatcher.setAsyncSupported(true); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/scripting/*"); security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/gitlab/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
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)); }