use of cn.taketoday.web.servlet.initializer.WebFilterInitializer in project today-framework by TAKETODAY.
the class WebServletApplicationLoader method configureFilterInitializers.
/**
* Configure {@link Filter}
*
* @param applicationContext {@link ApplicationContext}
* @param contextInitializers {@link WebApplicationInitializer}s
*/
protected void configureFilterInitializers(WebApplicationContext applicationContext, List<WebApplicationInitializer> contextInitializers) {
List<Filter> filters = applicationContext.getAnnotatedBeans(WebFilter.class);
for (Filter filter : filters) {
Class<?> beanClass = filter.getClass();
WebFilterInitializer<Filter> webFilterInitializer = new WebFilterInitializer<>(filter);
WebFilter webFilter = beanClass.getAnnotation(WebFilter.class);
Set<String> urlPatterns = new HashSet<>();
Collections.addAll(urlPatterns, webFilter.value());
Collections.addAll(urlPatterns, webFilter.urlPatterns());
webFilterInitializer.addUrlMappings(StringUtils.toStringArray(urlPatterns));
webFilterInitializer.addServletNames(webFilter.servletNames());
webFilterInitializer.setAsyncSupported(webFilter.asyncSupported());
for (WebInitParam initParam : webFilter.initParams()) {
webFilterInitializer.addInitParameter(initParam.name(), initParam.value());
}
String name = webFilter.filterName();
if (StringUtils.isEmpty(name)) {
String displayName = webFilter.displayName();
if (StringUtils.isEmpty(displayName)) {
name = BeanDefinitionBuilder.defaultBeanName(beanClass);
} else {
name = displayName;
}
}
webFilterInitializer.setName(name);
webFilterInitializer.setDispatcherTypes(webFilter.dispatcherTypes());
contextInitializers.add(webFilterInitializer);
}
}
Aggregations