class ServletContextHelper {

    public List<FilterMapping> getFilterMappingsForPath(final ServletContext servletContext, final String path) {
        Objects.requireNonNull(servletContext);
        String inContextPath = getPathInContext(servletContext, path);

        List<FilterMapping> filterMappings = new ArrayList<>();
        for (FilterMapping filterMapping : servletContext.getFilterMappings()) {
            if (filterMapping.getUrlPattern().matcher(inContextPath).matches()) {
                if (filterMapping.getUrlExcludePattern() != null) {
                    if (!filterMapping.getUrlExcludePattern().matcher(inContextPath).matches()) {
                        filterMappings.add(filterMapping);
                    }
                } else {
                    filterMappings.add(filterMapping);
                }
            }
        }

        return filterMappings;
    }

}