@Override // Questo serve (anche) per consentire il file upload verso url protette: // The first option is to ensure that the MultipartFilter is specified before the Spring Security filter. // Specifying the MultipartFilter before the Spring Security filter means that there is no authorization // for invoking the MultipartFilter which means anyone can place temporary files on your server. // However, only authorized users will be able to submit a File that is processed by your application. // In general, this is the recommended approach because the temporary file upload should have a // negligble impact on most servers. protected void beforeSpringSecurityFilterChain(ServletContext servletContext) { // Per aggiungere altri filtri basta metterli in fila, in ordine di esecuzione // insertFilters(servletContext, new YadaMultipartExceptionHandler(), new MultipartFilter()); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); // L'AuditFilter lo metto prima di tutto almeno viene eseguito prima dell'autorizzazione e riesco a capire il motivo di eventuali 403 // For some reason the characterEncodingFilter can not be after the MultipartFilter otherwise encoding in forms doesn't work (for non-multipart forms). insertFilters(servletContext, new CheckSessionFilter(), characterEncodingFilter, new AuditFilter(), new MultipartFilter(), new DelegatingFilterProxy("yadaLocalePathVariableFilter")); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { //register config classes AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebMvcConfig.class); rootContext.register(JPAConfig.class); rootContext.register(WebSecurityConfig.class); rootContext.register(ServiceConfig.class); //set session timeout servletContext.addListener(new SessionListener(maxInactiveInterval)); //set dispatcher servlet and mapping ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.addMapping("/"); dispatcher.setLoadOnStartup(1); //register filters FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("endcodingFilter", new CharacterEncodingFilter()); filterRegistration.setInitParameter("encoding", "UTF-8"); filterRegistration.setInitParameter("forceEncoding", "true"); //make sure encodingFilter is matched first filterRegistration.addMappingForUrlPatterns(null, false, "/*"); //disable appending jsessionid to the URL filterRegistration = servletContext.addFilter("disableUrlSessionFilter", new DisableUrlSessionFilter()); filterRegistration.addMappingForUrlPatterns(null, true, "/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = getContext(); servletContext.addListener(new ContextLoaderListener(context)); servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8")); DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); CXFServlet cxf = new CXFServlet(); BusFactory.setDefaultBus(cxf.getBus()); ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf); cxfServlet.setLoadOnStartup(1); cxfServlet.addMapping("/services/*"); servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false, "/*"); servletContext.getSessionCookieConfig().setSecure(cookieSecure); }
@Override protected Filter[] getServletFilters(){ // создание фильтра кодировки, который позволит работать с русскими символами CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); // создание фильтра, который добавляет поддержку HTTP методов(например,таких как PUT) HiddenHttpMethodFilter httpMethodFilter = new HiddenHttpMethodFilter(); return new Filter[]{characterEncodingFilter, httpMethodFilter}; }
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.getServletRegistration("default").addMapping("/resources/*"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootApplicationContextConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext servletContextConfig = new AnnotationConfigWebApplicationContext(); servletContextConfig.register(ServletApplicationContextConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("springDispatcher", new DispatcherServlet(servletContextConfig)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); FilterRegistration.Dynamic registration = servletContext.addFilter("preSecFilter", new PreSescLoggingFilter()); registration.addMappingForUrlPatterns(null, false, "/*"); FilterRegistration.Dynamic reg = servletContext.addFilter("encoding", new CharacterEncodingFilter("UTF-8", true)); reg.addMappingForUrlPatterns(null, false, "/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // 基于注解配置的Web容器上下文 AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(WebAppConfig.class); // 添加编码过滤器并进行映射 CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true); FilterRegistration.Dynamic dynamicFilter = servletContext.addFilter("characterEncodingFilter", characterEncodingFilter); dynamicFilter.addMappingForUrlPatterns(null, true, "/*"); // 添加静态资源映射 ServletRegistration defaultServletRegistration = servletContext.getServletRegistration("default"); defaultServletRegistration.addMapping("*.html"); Servlet dispatcherServlet = new DispatcherServlet(context); ServletRegistration.Dynamic dynamicServlet = servletContext.addServlet("dispatcher", dispatcherServlet); dynamicServlet.addMapping("/"); }
@Override public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(SpringConfig.class); ctx.setServletContext(container); ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.setLoadOnStartup(1); servlet.addMapping("/"); //编码设置 FilterRegistration.Dynamic fr = container.addFilter("encodingFilter", new CharacterEncodingFilter()); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { Map<String, String> filterChainDefinitionMap = Application.getSecurityFilterChainDefinitionMap(); filterChainDefinitionMap.put("/admin", DefaultFilter.authc.name()); filterChainDefinitionMap.put("/admin/logout", DefaultFilter.logout.name()); filterChainDefinitionMap.put("/admin/**", DefaultFilter.authc.name()); List<Filter> filters = Application.getFilters(); DelegatingFilterProxy shiroFilter = new DelegatingFilterProxy("shiroFilter"); shiroFilter.setTargetFilterLifecycle(true); filters.add(shiroFilter); filters.add(new RequestContextFilter()); filters.add(new CharacterEncodingFilter("UTF-8", true)); }
@Before public void setup() throws Exception { userService = _userService; CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding( "UTF-8" ); characterEncodingFilter.setForceEncoding( true ); mvc = MockMvcBuilders.webAppContextSetup( webApplicationContext ) .addFilters( characterEncodingFilter, new ShallowEtagHeaderFilter(), filterChainProxy ) .apply( documentationConfiguration( this.restDocumentation ) ) .build(); executeStartupRoutines(); setUpTest(); }
@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); 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, "/*"); }
public void onServletContextStartup(ServletContext servletContext) throws ServletException { //encodingFilter registeredEncodingFilter(servletContext, CharacterEncodingFilter.class); //hiddenHttpMethodFilter registeredHiddenMethodFilter(servletContext, HiddenHttpMethodFilter.class); //multipartFilter registeredMultipartFilter(servletContext, SpringMultipartFilterProxy.class); //systemFilter registeredInitFilter(servletContext, BaseInitFilter.class); //ajaxAnywhere // registeredAjaxAnywhere(servletContext, AAFilter.class); }
@Before public void setup() throws Exception { objectMapper = new ObjectMapperFactoryBean().getObject(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding( "UTF-8" ); characterEncodingFilter.setForceEncoding( true ); mvc = MockMvcBuilders.webAppContextSetup( wac ) .addFilters( characterEncodingFilter, new ShallowEtagHeaderFilter(), filterChainProxy ) .build(); executeStartupRoutines(); setUpTest(); }
protected void addFilter(final ServletContext ctx) { AccessFilter af= (AccessFilter) rootContext.getBean("accessFilter"); CharacterEncodingFilter cef = (CharacterEncodingFilter) rootContext.getBean("characterEncodingFilter"); DelegatingFilterProxy dfp = new DelegatingFilterProxy("springSecurityFilterChain"); EnumSet<DispatcherType> dts=EnumSet.allOf(DispatcherType.class); // Access log filter ctx.addFilter("accessFilter",af).addMappingForUrlPatterns(dts,true,"/*"); // Error wrapper filter // Character encoding filter ctx.addFilter("characterEncodingFilter", cef).addMappingForUrlPatterns(dts, true, "/*"); // Spring security filter ctx.addFilter("spring-security", dfp).addMappingForUrlPatterns(dts, true, "/*"); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
@Override protected void configure(HttpSecurity http) throws Exception { // NOSONAR the authorizeRequests() throws it and // can't be omitted CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); http.addFilterBefore(filter, CsrfFilter.class); http.authorizeRequests() .accessDecisionManager(decisionManager) .antMatchers(AdminController.CONTROLLER_PATH + "/**") .authenticated() .and() .exceptionHandling() .authenticationEntryPoint(getAuthenticationEntryPoint()) .accessDeniedHandler(exceptionHandler); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { super.onStartup(servletContext); Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler()); configureSessionCookie(servletContext); CharacterEncodingFilter cef = new CharacterEncodingFilter(); cef.setEncoding("UTF-8"); cef.setForceEncoding(true); Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter", cef); characterEncodingFilter.setAsyncSupported(true); characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*"); //force log initialization, then disable it XRLog.setLevel(XRLog.EXCEPTION, Level.WARNING); XRLog.setLoggingEnabled(false); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); servletContext.addFilter("characterEncodingFilter", filter).addMappingForUrlPatterns(null, false, "/*"); servletContext.addFilter("openEntityManagerInViewFilter", new OpenEntityManagerInViewFilter()).addMappingForUrlPatterns(null, false, "/*"); DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy(); delegatingFilterProxy.setTargetFilterLifecycle(true); servletContext.addFilter("shiroFilter", delegatingFilterProxy).addMappingForUrlPatterns(null, false, "/*"); servletContext.addServlet("kaptcha", new KaptchaServlet()).addMapping("/kaptcha"); super.onStartup(servletContext); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
@Before public void setup() throws Exception { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilter(filter, "/*").build(); Assert.assertNotNull(mockMvc); if (uuidGenerator instanceof PesudoUUIDGenerator) { ((PesudoUUIDGenerator)uuidGenerator).reset(); } if ( idRestClient instanceof IdServiceRestClientOfflineDemoImpl) { ((IdServiceRestClientOfflineDemoImpl)idRestClient).reset(); } if (s3Client instanceof TestS3Client) { final TestS3Client testS3Client = (TestS3Client) s3Client; testS3Client.freshBucketStore(); testS3Client.createBucket(buildBucketName); testS3Client.createBucket(publishedBucketName); } }
@RefreshScope @Bean public FilterRegistrationBean characterEncodingFilter() { final FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new CharacterEncodingFilter( casProperties.getHttpWebRequest().getWeb().getEncoding(), casProperties.getHttpWebRequest().getWeb().isForceEncoding())); bean.setUrlPatterns(Collections.singleton("/*")); bean.setName("characterEncodingFilter"); bean.setAsyncSupported(true); return bean; }
@Bean @Order(Ordered.HIGHEST_PRECEDENCE) public CharacterEncodingFilter characterEncodingFilter() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); return filter; }
@Override protected Filter[] getServletFilters() { final CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(CHARACTER_ENCODING); encodingFilter.setForceEncoding(true); return new Filter[]{encodingFilter}; }
public static void startServer(int port) throws Exception { final DeploymentInfo deployment = Servlets.deployment().setClassLoader(WebServer.class.getClassLoader()); deployment.setContextPath(""); deployment.setDeploymentName("membrane"); deployment.addInitParameter("contextConfigLocation", "classpath:context/application-context.xml"); deployment.setResourceManager(new FileResourceManager(new File("."), 0)); deployment.addListener(Servlets.listener(ContextLoaderListener.class)); deployment.addListener(Servlets.listener(RequestContextListener.class)); deployment.addServlet(Servlets.servlet("dispatcher", DispatcherServlet.class).addMapping("/*") .addInitParam("contextConfigLocation", "classpath:context/dispatcher-servlet.xml")); deployment.addFilter(Servlets.filter(CharacterEncodingFilter.class).addInitParam("forceEncoding", "true") .addInitParam("encoding", "UTF-8")); final DeploymentManager manager = Servlets.defaultContainer().addDeployment(deployment); manager.deploy(); final Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0").setHandler(manager.start()).build(); server.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { // graceful shutdown of everything server.stop(); try { manager.stop(); } catch (ServletException e) { } manager.undeploy(); } }); }
@Bean public FilterRegistrationBean filterRegistrationBean() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registrationBean.setFilter(filter); registrationBean.addUrlPatterns("/*"); return registrationBean; }
@Override public void onStartup(ServletContext servletContext) throws ServletException { //If you want to use the XML configuration, comment the following two lines out. AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); // rootContext.scan("com.pigdroid.social.config"); //If you want to use the XML configuration, uncomment the following lines. //XmlWebApplicationContext rootContext = new XmlWebApplicationContext(); //rootContext.setConfigLocation("classpath:exampleApplicationContext.xml"); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic sitemesh = servletContext.addFilter("sitemesh", new ConfigurableSiteMeshFilter()); sitemesh.addMappingForUrlPatterns(dispatcherTypes, true, "*.jsp"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
/** * Web服务过滤器 * * @return */ @Override protected Filter[] getServletFilters() { //所有内容按UTF-8编码 CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); //跨域访问支持 Filter corsfilter = new CORSFilter(); return new Filter[]{encodingFilter, corsfilter}; }
/** * 添加过滤器 * * @return */ @Bean public FilterRegistrationBean filterRegistrationBean () { // 过滤器注册 FilterRegistrationBean registrationBean = new FilterRegistrationBean(); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding( StandardCharsets.UTF_8.displayName() ); encodingFilter.setForceEncoding( true ); // 字符过滤器 registrationBean.setFilter( encodingFilter ); // 日志处理过滤器 registrationBean.setFilter( requestLoggingFilter() ); return registrationBean; }
@Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); registrationBean.setFilter(characterEncodingFilter); return registrationBean; }
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter filter1 = new CharacterEncodingFilter(); filter1.setEncoding("utf-8"); filter1.setForceEncoding(true); HttpPutFormContentFilter filter2 = new HttpPutFormContentFilter(); HiddenHttpMethodFilter filter3 = new HiddenHttpMethodFilter(); LOG.info("Adding filter to dispatcher servlet[CharacterEncodingFilter,HttpPutFormContentFilter,HiddenHttpMethodFilter]"); return new Filter[]{filter1, filter2, filter3}; }
@Bean public CharacterEncodingFilter characterEncodingFilter() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); return filter; }
/** * Register SetCharacterEncodingFilter to convert specical characters correctly. * * @return filter */ @Bean public FilterRegistrationBean setCharacterEncodingFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(false); this.beanFactory.autowireBean(characterEncodingFilter); registration.setFilter(characterEncodingFilter); registration.addUrlPatterns("/*"); return registration; }
@Bean public FilterRegistrationBean encodingFilter() { FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new CharacterEncodingFilter()); bean.addInitParameter("encoding", "UTF-8"); //FIXME: https://github.com/Netflix/eureka/issues/702 // bean.addInitParameter("forceEncoding", "true"); bean.setName("encodingFilter"); bean.addUrlPatterns("/*"); bean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD); return bean; }
@Override protected Filter[] getServletFilters() { final CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
@Override protected Filter[] getServletFilters() { final CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(CHARACTER_ENCODING); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
@Test public void chainMultiple() { MockMvcBuilders .webAppContextSetup(wac) .addFilter(new CharacterEncodingFilter() ) .defaultRequest(get("/").contextPath("/mywebapp")) .build(); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { logger.info("== ServletContextInitializer"); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encoding-filter", new CharacterEncodingFilter()); encodingFilter.setInitParameter("encoding", "UTF-8"); encodingFilter.setInitParameter("forceEncoding", "true"); encodingFilter.addMappingForUrlPatterns(null, true, "/*"); //servletContext.addListener(new BackgroundJobService()); }
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); return new Filter[] {characterEncodingFilter}; }
/** * This opts out of adding charset to png resources. * * <p>By default, {@linkplain CharacterEncodingFilter} adds a charset qualifier to all resources, * which helps, as javascript assets include extended character sets. However, the filter also * adds charset to well-known binary ones like png. This creates confusing content types, such as * "image/png;charset=UTF-8". * * See https://github.com/spring-projects/spring-boot/issues/5459 */ @Bean @Order(Ordered.HIGHEST_PRECEDENCE) public CharacterEncodingFilter characterEncodingFilter() { CharacterEncodingFilter filter = new CharacterEncodingFilter() { @Override protected boolean shouldNotFilter(HttpServletRequest request) { return request.getServletPath().endsWith(".png"); } }; filter.setEncoding("UTF-8"); filter.setForceEncoding(true); return filter; }