org.springframework.web.filter.CharacterEncodingFilter Java Examples
The following examples show how to use
org.springframework.web.filter.CharacterEncodingFilter.
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: DSSSpringApplication.java From DataSphereStudio with Apache License 2.0 | 6 votes |
@Bean public WebServerFactoryCustomizer<JettyServletWebServerFactory> jettyFactoryCustomizer() { return new WebServerFactoryCustomizer<JettyServletWebServerFactory>() { public void customize(JettyServletWebServerFactory jettyServletWebServerFactory) { jettyServletWebServerFactory.addServerCustomizers(new JettyServerCustomizer() { public void customize(Server server) { Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class); final WebAppContext webApp = (WebAppContext) childHandlersByClass[0]; FilterHolder filterHolder = new FilterHolder(CharacterEncodingFilter.class); filterHolder.setInitParameter("encoding", Configuration.BDP_ENCODING().getValue()); filterHolder.setInitParameter("forceEncoding", "true"); webApp.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class)); BDPJettyServerHelper.setupRestApiContextHandler(webApp); if(ServerConfiguration.BDP_SERVER_SOCKET_MODE().getValue()) { BDPJettyServerHelper.setupControllerServer(webApp); } if(!ServerConfiguration.BDP_SERVER_DISTINCT_MODE().getValue()) { BDPJettyServerHelper.setupWebAppContext(webApp); } } }); } }; }
Example #2
Source File: CentralizeInitializer.java From java-platform with Apache License 2.0 | 6 votes |
@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)); }
Example #3
Source File: DhisWebSpringTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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(); }
Example #4
Source File: Initializer.java From alf.io with GNU General Public License v3.0 | 6 votes |
@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); }
Example #5
Source File: CommonWebFilterInitializer.java From onetwo with Apache License 2.0 | 6 votes |
public void onServletContextStartup(ServletContext servletContext) throws ServletException { //encodingFilter registeredEncodingFilter(servletContext, CharacterEncodingFilter.class); // multipartFilter registeredMultipartFilter(servletContext); //hiddenHttpMethodFilter registeredHiddenMethodFilter(servletContext, HiddenHttpMethodFilter.class); //multipartFilter // registeredMultipartFilter(servletContext, SpringMultipartFilterProxy.class); //systemFilter registeredInitFilter(servletContext, BaseInitFilter.class); //ajaxAnywhere // registeredAjaxAnywhere(servletContext, AAFilter.class); }
Example #6
Source File: AbstractWebApplicationInitializer.java From bearchoke with Apache License 2.0 | 5 votes |
protected void createFilters(ServletContext ctx) { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); SimpleCORSFilter corsFilter = new SimpleCORSFilter(); corsFilter.setCorsAllowCredentials("true"); corsFilter.setCorsAllowMethods("GET, POST, PUT, PATCH, DELETE, OPTIONS"); corsFilter.setCorsAllowHeaders("content-type, x-requested-with, origin, accept, authorization, username, password, x-app-type, x-app-version, x-auth-token, soapaction"); corsFilter.setCorsExposeHeaders("content-type, cookie, x-requested-with, origin, accept, username, password, x-app-type, x-app-version, x-auth-token, soapaction"); corsFilter.setCorsMaxAge("3600"); ctx.addFilter("springSessionRepositoryFilter", DelegatingFilterProxy.class).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("simpleCORSFilter", DelegatingFilterProxy.class).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); // ctx.addFilter("SimpleCorsFilter", corsFilter).addMappingForUrlPatterns( // EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("JsonHttpRequestFilter", new JsonHttpRequestFilter()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/api/authenticate"); ctx.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("CharacterEncodingFilter", characterEncodingFilter).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("HiddenHttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("HttpPutFormContentFilter", new HttpPutFormContentFilter()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); ctx.addFilter("ShallowEtagHeaderFilter", new ShallowEtagHeaderFilter()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, FILTER_MAPPING); }
Example #7
Source File: MockMvcBuilderMethodChainTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void chainMultiple() { MockMvcBuilders .webAppContextSetup(wac) .addFilter(new CharacterEncodingFilter() ) .defaultRequest(get("/").contextPath("/mywebapp")) .build(); }
Example #8
Source File: SpringWebConfig.java From spring-mvc-react with MIT License | 5 votes |
@Bean public FilterRegistrationBean filterRegistrationBean() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registrationBean.setFilter(filter); registrationBean.addUrlPatterns("/*"); return registrationBean; }
Example #9
Source File: MoonInitializer.java From moon-api-gateway with MIT License | 5 votes |
/** * The project has set the default encodingType to UTF-8 for Web requests and responses via CharacterEncodingFilter. */ @Override protected Filter[] getServletFilters() { CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(Constant.SERVER_DEFAULT_ENCODING_TYPE); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
Example #10
Source File: WebContentServiceWebApplicationInitializer.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); return new Filter[]{characterEncodingFilter}; }
Example #11
Source File: BusinessIntelligenceServiceWebApplicationInitializer.java From abixen-platform with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); return new Filter[]{characterEncodingFilter}; }
Example #12
Source File: AmqpConfig.java From demo_springboot_rabbitmq with Apache License 2.0 | 5 votes |
@Bean public CharacterEncodingFilter characterEncodingFilter() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); return filter; }
Example #13
Source File: ServletContainerConfig.java From portal-de-servicos with MIT License | 5 votes |
@Bean public Filter characterEncodingFilter() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); filter.setForceEncoding(true); return filter; }
Example #14
Source File: WarInitializer.java From herd with Apache License 2.0 | 5 votes |
/** * Initializes the character encoding filter which provides UTF-8 encoding. * * @param servletContext the servlet context. */ protected void initCharacterEncodingFilter(ServletContext servletContext) { // Add a filter that encodes incoming requests and outgoing responses with UTF-8 encoding. FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); filterRegistration.setInitParameter("encoding", StandardCharsets.UTF_8.name()); filterRegistration.setInitParameter("forceEncoding", "true"); filterRegistration.addMappingForUrlPatterns(null, true, "/*"); }
Example #15
Source File: MockMvcBuilderMethodChainTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void chainMultiple() { MockMvcBuilders .webAppContextSetup(wac) .addFilter(new CharacterEncodingFilter() ) .defaultRequest(get("/").contextPath("/mywebapp")) .build(); }
Example #16
Source File: SpringBootInitializer.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Bean public Filter characterEncodingFilter() { CharacterEncodingFilter cef = new CharacterEncodingFilter(); cef.setEncoding("UTF-8"); cef.setForceEncoding(true); return cef; }
Example #17
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
Example #18
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { HiddenHttpMethodFilter httpMethodFilter = new HiddenHttpMethodFilter(); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { httpMethodFilter, encodingFilter }; }
Example #19
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
Example #20
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { HiddenHttpMethodFilter httpMethodFilter = new HiddenHttpMethodFilter(); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { httpMethodFilter, encodingFilter }; }
Example #21
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { HiddenHttpMethodFilter httpMethodFilter = new HiddenHttpMethodFilter(); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { httpMethodFilter, encodingFilter }; }
Example #22
Source File: AppInitializer.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding("UTF-8"); encodingFilter.setForceEncoding(true); return new Filter[] { encodingFilter }; }
Example #23
Source File: WebAppInitializer.java From thymeleafexamples-layouts with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); DelegatingFilterProxy securityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain"); return new Filter[] {characterEncodingFilter, securityFilterChain}; }
Example #24
Source File: WebInitializer.java From Spring with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter cef = new CharacterEncodingFilter(); cef.setEncoding("UTF-8"); cef.setForceEncoding(true); return new Filter[]{new HiddenHttpMethodFilter(), cef}; }
Example #25
Source File: WebInitializer.java From Spring with Apache License 2.0 | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter cef = new CharacterEncodingFilter(); cef.setEncoding("UTF-8"); cef.setForceEncoding(true); return new Filter[]{new HiddenHttpMethodFilter(), cef}; }
Example #26
Source File: Initializer.java From SA47 with The Unlicense | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); return new Filter[] { characterEncodingFilter, new SiteMeshFilter() }; }
Example #27
Source File: Initializer.java From SA47 with The Unlicense | 5 votes |
@Override protected Filter[] getServletFilters() { CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); return new Filter[] { characterEncodingFilter, new SiteMeshFilter() }; }
Example #28
Source File: RoothubApplication.java From Roothub with GNU Affero General Public License v3.0 | 5 votes |
@Bean public FilterRegistrationBean filterRegistrationBean() { FilterRegistrationBean registrationBean = new FilterRegistrationBean(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setForceEncoding(true); characterEncodingFilter.setEncoding("UTF-8"); registrationBean.setFilter(characterEncodingFilter); return registrationBean; }
Example #29
Source File: WebServer.java From metamodel-membrane with Apache License 2.0 | 5 votes |
public static void startServer(int port, boolean enableCors) 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 HttpHandler handler; if (enableCors) { CorsHandlers corsHandlers = new CorsHandlers(); handler = corsHandlers.allowOrigin(manager.start()); } else { handler = manager.start(); } final Undertow server = Undertow.builder().addHttpListener(port, "0.0.0.0").setHandler(handler).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(); } }); }
Example #30
Source File: SpringWebConfig.java From spring-mvc-react with MIT License | 5 votes |
@Bean public FilterRegistrationBean filterRegistrationBean() { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding("UTF-8"); FilterRegistrationBean registrationBean = new FilterRegistrationBean(); registrationBean.setFilter(filter); registrationBean.addUrlPatterns("/*"); return registrationBean; }