List of usage examples for javax.servlet FilterRegistration setInitParameter
public boolean setInitParameter(String name, String value);
From source file:org.devgateway.toolkit.forms.wicket.WebInitializer.java
@Override public void onStartup(final ServletContext sc) throws ServletException { sc.addFilter("Spring OpenEntityManagerInViewFilter", org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.class) .addMappingForUrlPatterns(null, false, "/*"); FilterRegistration filter = sc.addFilter("wicket-filter", WicketFilter.class); filter.setInitParameter(WicketFilter.APP_FACT_PARAM, SpringWebApplicationFactory.class.getName()); filter.setInitParameter(PARAM_APP_BEAN, "formsWebApplication"); // This line is the only surprise when comparing to the equivalent // web.xml. Without some initialization seems to be missing. filter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*"); filter.addMappingForUrlPatterns(null, false, "/*"); // // Request Listener sc.addListener(new RequestContextListener()); sc.addListener(new HttpSessionEventPublisher()); }
From source file:com.coffeebeans.services.config.initializer.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(AppConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(MvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(MVC_DISPATCHER_NAME, new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1);//from w ww . ja v a 2 s . co m dispatcher.addMapping("/1/*"); dispatcher.addMapping("/oauth/token"); FilterRegistration charEncodingFilterReg = servletContext.addFilter("CharacterEncodingFilter", CharacterEncodingFilter.class); charEncodingFilterReg.setInitParameter("encoding", "UTF-8"); charEncodingFilterReg.setInitParameter("forceEncoding", "true"); charEncodingFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); }
From source file:net.bull.javamelody.JavaMelodyAutoConfiguration.java
/** * Registers the JavaMelody {@link MonitoringFilter}. The filter can be overridden completely by creating a custom * {@link FilterRegistrationBean} with the name "javamelody-registration" in the application context. * @param properties JavaMelodyConfigurationProperties * @param servletContext ServletContext/*w w w .ja va 2s . c o m*/ * @return FilterRegistrationBean */ @Bean(name = REGISTRATION_BEAN_NAME) @ConditionalOnMissingBean(name = REGISTRATION_BEAN_NAME) public FilterRegistrationBean monitoringFilter(JavaMelodyConfigurationProperties properties, ServletContext servletContext) { final FilterRegistrationBean registrationBean = new FilterRegistrationBean(); // Create the monitoring filter and set its configuration parameters. final MonitoringFilter filter = new MonitoringFilter(); filter.setApplicationType("Spring Boot"); // Wrap the monitoring filter in the registration bean. registrationBean.setFilter(filter); registrationBean.setAsyncSupported(true); registrationBean.setName("javamelody"); registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC); // Set the initialization parameter for the monitoring filter. for (final Entry<String, String> parameter : properties.getInitParameters().entrySet()) { registrationBean.addInitParameter(parameter.getKey(), parameter.getValue()); } // Set the URL patterns to activate the monitoring filter for. registrationBean.addUrlPatterns("/*"); final FilterRegistration filterRegistration = servletContext.getFilterRegistration("javamelody"); if (filterRegistration != null) { // if webapp deployed as war in a container with MonitoringFilter already added by web-fragment.xml, // do not try to add it again registrationBean.setEnabled(false); for (final Map.Entry<String, String> entry : registrationBean.getInitParameters().entrySet()) { filterRegistration.setInitParameter(entry.getKey(), entry.getValue()); } } return registrationBean; }