@Test public void includeAndExcludePatterns() { MappedInterceptor mappedInterceptor = new MappedInterceptor( new String[] { "/**" }, new String[] { "/admin/**" }, this.interceptor); assertTrue(mappedInterceptor.matches("/foo", pathMatcher)); assertFalse(mappedInterceptor.matches("/admin/foo", pathMatcher)); }
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) { PathMatcher pathMatcher = new AntPathMatcher(); List<HandlerInterceptor> result = new ArrayList<>(); for (Object interceptor : this.registry.getInterceptors()) { if (interceptor instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; if (mappedInterceptor.matches(lookupPath, pathMatcher)) { result.add(mappedInterceptor.getInterceptor()); } } else if (interceptor instanceof HandlerInterceptor) { result.add((HandlerInterceptor) interceptor); } else { fail("Unexpected interceptor type: " + interceptor.getClass().getName()); } } return result; }
@Test public void noPatterns() { MappedInterceptor mappedInterceptor = new MappedInterceptor(null, null, this.interceptor); assertTrue(mappedInterceptor.matches("/foo", pathMatcher)); }
@Test public void customPathMatcher() { MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { "/foo/[0-9]*" }, this.interceptor); mappedInterceptor.setPathMatcher(new TestPathMatcher()); assertTrue(mappedInterceptor.matches("/foo/123", pathMatcher)); assertFalse(mappedInterceptor.matches("/foo/bar", pathMatcher)); }
@Test public void includePatternWithMatrixVariables() { MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { "/foo*/*" }, this.interceptor); assertTrue(mappedInterceptor.matches("/foo;q=1/bar;s=2", pathMatcher)); }
if (interceptor instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) { chain.addInterceptor(mappedInterceptor.getInterceptor());
if (interceptor instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) { chain.addInterceptor(mappedInterceptor.getInterceptor());
if (interceptor instanceof MappedInterceptor) { MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor; if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) { chain.addInterceptor(mappedInterceptor.getInterceptor());