Java Code Examples for javax.servlet.annotation.WebFilter#initParams()

The following examples show how to use javax.servlet.annotation.WebFilter#initParams() . 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: ServerCmdlet.java    From HongsCORE with MIT License 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: WebFilterInstaller.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
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());
}
 
Example 3
Source File: FilterHolder.java    From aws-serverless-java-container with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: StartWebServer.java    From hammock with Apache License 2.0 5 votes vote down vote up
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);
}