下面列出了javax.servlet.annotation.WebFilter#initParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addFilter(ServletContextHandler context, Class clso, WebFilter anno) {
DispatcherType[] ds = anno.dispatcherTypes( );
List <DispatcherType> ls = Arrays .asList(ds);
EnumSet<DispatcherType> es = EnumSet.copyOf(ls);
FilterHolder hd = new FilterHolder (clso );
hd.setName (anno.filterName( ));
hd.setAsyncSupported(anno.asyncSupported());
for(WebInitParam nv : anno.initParams ()) {
hd.setInitParameter(nv.name( ), nv.value());
}
for(String ur : anno.urlPatterns()) {
context.addFilter (hd, ur, es);
}
}
private void configure(final ServletEnvironment environment, final Filter filter,
final String name, final WebFilter annotation) {
final FilterRegistration.Dynamic mapping = environment.addFilter(name, filter);
final EnumSet<DispatcherType> dispatcherTypes = EnumSet.copyOf(Arrays.asList(annotation.dispatcherTypes()));
if (annotation.servletNames().length > 0) {
mapping.addMappingForServletNames(dispatcherTypes, false, annotation.servletNames());
} else {
final String[] urlPatterns = annotation.urlPatterns().length > 0
? annotation.urlPatterns() : annotation.value();
mapping.addMappingForUrlPatterns(dispatcherTypes, false, urlPatterns);
}
if (annotation.initParams().length > 0) {
for (WebInitParam param : annotation.initParams()) {
mapping.setInitParameter(param.name(), param.value());
}
}
mapping.setAsyncSupported(annotation.asyncSupported());
}
private Map<String, String> readAnnotatedInitParams() {
Map<String, String> initParams = new HashMap<>();
if (isAnnotated()) {
WebFilter regAnnotation = filter.getClass().getAnnotation(WebFilter.class);
for (WebInitParam param : regAnnotation.initParams()) {
initParams.put(param.name(), param.value());
}
}
return initParams;
}
private void processFilters() {
Consumer<Class<? extends Filter>> c = filter -> {
WebFilter webFilter = ClassUtils.getAnnotation(filter, WebFilter.class);
if(webFilter != null) {
FilterDescriptor filterDescriptor = new FilterDescriptor(webFilter.filterName(),
webFilter.value(), mapUrls(webFilter.urlPatterns()), webFilter.dispatcherTypes(),
webFilter.initParams(), webFilter.asyncSupported(), webFilter.servletNames(),
filter);
webServer.addFilter(filterDescriptor);
}
};
extension.processFilters(c);
}