Java Code Examples for javax.servlet.FilterRegistration#getUrlPatternMappings()

The following examples show how to use javax.servlet.FilterRegistration#getUrlPatternMappings() . 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: WebDiagnosticCollector.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
private Map<String, Object> buildFilterList() {
    Map<String, Object> filterMap = new HashMap<>();
    for (Map.Entry<String, ? extends FilterRegistration> filterRegistrationEntry : servletContext
            .getFilterRegistrations().entrySet()) {
        FilterRegistration filterRegistration = filterRegistrationEntry.getValue();
        Map<String, Object> filterRegistrationInfo = new HashMap<>();

        filterRegistrationInfo.put("class", filterRegistration.getClassName());
        filterRegistrationInfo.put("parameters", filterRegistration.getInitParameters());
        Collection<String> mappings = filterRegistration.getServletNameMappings();
        if (mappings == null) {
            mappings = new ArrayList<>();
        }
        filterRegistrationInfo.put("servletNameMappings", Sets.newLinkedHashSet(mappings));
        Collection<String> patterns = filterRegistration.getUrlPatternMappings();
        if (patterns == null) {
            patterns = new ArrayList<>();
        }
        filterRegistrationInfo.put("urlPatternMappings", Sets.newLinkedHashSet(patterns));

        filterMap.put(filterRegistrationEntry.getKey(), filterRegistrationInfo);
    }

    return filterMap;
}
 
Example 2
Source File: PippoFilter.java    From pippo with Apache License 2.0 5 votes vote down vote up
private void initFilterPathFromWebXml(FilterConfig filterConfig) {
    String filterName = filterConfig.getFilterName();
    FilterRegistration filterRegistration = filterConfig.getServletContext().getFilterRegistration(filterName);
    Collection<String> mappings = filterRegistration.getUrlPatternMappings();
    int size = mappings.size();

    if (size > 1) {
        throw new PippoRuntimeException("Expected one filter path for '{}' but found multiple", filterName);
    }

    if (size == 1) {
        String urlPattern = mappings.iterator().next();
        initFilterPath(urlPattern);
    }
}