@Test public void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = Mockito.mock(PathMatcher.class); registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher); MappedInterceptor mappedInterceptor = (MappedInterceptor) registry.getInterceptors().get(0); assertSame(pathMatcher, mappedInterceptor.getPathMatcher()); }
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>(); for (Object i : registry.getInterceptors()) { if (i instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) i; if (mappedInterceptor.matches(lookupPath, pathMatcher)) { result.add(mappedInterceptor.getInterceptor()); } } else if (i instanceof HandlerInterceptor) { result.add((HandlerInterceptor) i); } else { fail("Unexpected interceptor type: " + i.getClass().getName()); } } return result; }