本文整理汇总了Java中org.springframework.web.filter.CharacterEncodingFilter类的典型用法代码示例。如果您正苦于以下问题:Java CharacterEncodingFilter类的具体用法?Java CharacterEncodingFilter怎么用?Java CharacterEncodingFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharacterEncodingFilter类属于org.springframework.web.filter包,在下文中一共展示了CharacterEncodingFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeSpringSecurityFilterChain
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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"));
}
示例2: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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, "/*");
}
示例3: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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);
}
示例4: getServletFilters
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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};
}
示例5: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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, "/*");
}
示例6: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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("/");
}
示例7: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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");
}
示例8: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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));
}
示例9: setup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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();
}
示例10: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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, "/*");
}
示例11: onServletContextStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
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);
}
示例12: setup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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();
}
示例13: addFilter
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
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, "/*");
}
示例14: onStartup
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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));
}
示例15: configure
import org.springframework.web.filter.CharacterEncodingFilter; //导入依赖的package包/类
@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);
}