Class MappedInterceptor
- All Implemented Interfaces:
- HandlerInterceptor
HandlerInterceptor and uses URL patterns to determine whether
 it applies to a given request.
 Pattern matching can be done with PathMatcher or with parsed
 PathPattern. The syntax is largely the same with the latter being more
 tailored for web usage and more efficient. The choice is driven by the
 presence of a resolved
 String lookupPath or a parsed RequestPath which in turn depends on the
 HandlerMapping that matched the current request.
 
MappedInterceptor is supported by subclasses of
 AbstractHandlerMethodMapping which detect beans of type
 MappedInterceptor and also check if interceptors directly registered
 with it are of this type.
- Since:
- 3.0
- Author:
- Keith Donald, Rossen Stoyanchev, Brian Clozel
- 
Constructor SummaryConstructorsConstructorDescriptionMappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with aWebRequestInterceptoras the target.MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)without a provided parser.MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor, PathPatternParser parser) Create an instance with the given include and exclude patterns along with the target interceptor for the mappings.MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with aWebRequestInterceptoras the target.MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with include patterns only.
- 
Method SummaryModifier and TypeMethodDescriptionvoidafterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) Callback after completion of request processing, that is, after rendering the view.The targetHandlerInterceptorto invoke in case of a match.TheconfiguredPathMatcher.String[]Return the patterns this interceptor is mapped to.booleanmatches(HttpServletRequest request) Check whether this interceptor is mapped to the request.booleanmatches(String lookupPath, PathMatcher pathMatcher) Deprecated.voidpostHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) Interception point after successful execution of a handler.booleanpreHandle(HttpServletRequest request, HttpServletResponse response, Object handler) Interception point before the execution of a handler.voidsetPathMatcher(PathMatcher pathMatcher) Configure the PathMatcher to use to match URL paths with against include and exclude patterns.
- 
Constructor Details- 
MappedInterceptorpublic MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, HandlerInterceptor interceptor, @Nullable PathPatternParser parser) Create an instance with the given include and exclude patterns along with the target interceptor for the mappings.- Parameters:
- includePatterns- patterns to which requests must match, or null to match all paths
- excludePatterns- patterns to which requests must not match
- interceptor- the target interceptor
- parser- a parser to use to pre-parse patterns into- PathPattern; when not provided,- PathPatternParser.defaultInstanceis used.
- Since:
- 5.3
 
- 
MappedInterceptorVariant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with include patterns only.
- 
MappedInterceptorpublic MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, HandlerInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)without a provided parser.
- 
MappedInterceptorVariant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with aWebRequestInterceptoras the target.
- 
MappedInterceptorpublic MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, WebRequestInterceptor interceptor) Variant ofMappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)with aWebRequestInterceptoras the target.
 
- 
- 
Method Details- 
getPathPatternsReturn the patterns this interceptor is mapped to.
- 
getInterceptorThe targetHandlerInterceptorto invoke in case of a match.
- 
setPathMatcherConfigure the PathMatcher to use to match URL paths with against include and exclude patterns.This is an advanced property that should be used only when a customized AntPathMatcheror a custom PathMatcher is required.By default this is AntPathMatcher.Note: Setting PathMatcherenforces use of String pattern matching even when aparsedRequestPathis available.
- 
getPathMatcherTheconfiguredPathMatcher.
- 
matchesCheck whether this interceptor is mapped to the request.The request mapping path is expected to have been resolved externally. See also class-level Javadoc. - Parameters:
- request- the request to match to
- Returns:
- trueif the interceptor should be applied to the request
 
- 
matchesDeprecated.as of 5.3 in favor ofmatches(HttpServletRequest)Determine a match for the given lookup path.- Parameters:
- lookupPath- the current request path
- pathMatcher- a path matcher for path pattern matching
- Returns:
- trueif the interceptor applies to the given request path
 
- 
preHandlepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception Description copied from interface:HandlerInterceptorInterception point before the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler.DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response. Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.The default implementation returns true.- Specified by:
- preHandlein interface- HandlerInterceptor
- Parameters:
- request- current HTTP request
- response- current HTTP response
- handler- chosen handler to execute, for type and/or instance evaluation
- Returns:
- trueif the execution chain should proceed with the next interceptor or the handler itself. Else, DispatcherServlet assumes that this interceptor has already dealt with the response itself.
- Throws:
- Exception- in case of errors
 
- 
postHandlepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception Description copied from interface:HandlerInterceptorInterception point after successful execution of a handler. Called after HandlerAdapter actually invoked the handler, but before the DispatcherServlet renders the view. Can expose additional model objects to the view via the given ModelAndView.DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can post-process an execution, getting applied in inverse order of the execution chain. Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.The default implementation is empty. - Specified by:
- postHandlein interface- HandlerInterceptor
- Parameters:
- request- current HTTP request
- response- current HTTP response
- handler- the handler (or- HandlerMethod) that started asynchronous execution, for type and/or instance examination
- modelAndView- the- ModelAndViewthat the handler returned (can also be- null)
- Throws:
- Exception- in case of errors
 
- 
afterCompletionpublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception Description copied from interface:HandlerInterceptorCallback after completion of request processing, that is, after rendering the view. Will be called on any outcome of handler execution, thus allows for proper resource cleanup.Note: Will only be called if this interceptor's preHandlemethod has successfully completed and returnedtrue!As with the postHandlemethod, the method will be invoked on each interceptor in the chain in reverse order, so the first interceptor will be the last to be invoked.Note: special considerations apply for asynchronous request processing. For more details see AsyncHandlerInterceptor.The default implementation is empty. - Specified by:
- afterCompletionin interface- HandlerInterceptor
- Parameters:
- request- current HTTP request
- response- current HTTP response
- handler- the handler (or- HandlerMethod) that started asynchronous execution, for type and/or instance examination
- ex- any exception thrown on handler execution, if any; this does not include exceptions that have been handled through an exception resolver
- Throws:
- Exception- in case of errors
 
 
- 
matches(HttpServletRequest)