Class MappedInterceptor
- java.lang.Object
- org.springframework.web.servlet.handler.MappedInterceptor
- All Implemented Interfaces:
HandlerInterceptor
public final class MappedInterceptor extends Object implements HandlerInterceptor
Contains and delegates calls to aHandlerInterceptor
along with include (and optionally exclude) path patterns to which the interceptor should apply. Also provides matching logic to test if the interceptor applies to a given request path.A MappedInterceptor can be registered directly with any
AbstractHandlerMethodMapping
. Furthermore, beans of typeMappedInterceptor
are automatically detected byAbstractHandlerMethodMapping
(including ancestor ApplicationContext's) which effectively means the interceptor is registered "globally" with all handler mappings.- Since:
- 3.0
- Author:
- Keith Donald, Rossen Stoyanchev, Brian Clozel
Constructor Summary
Constructors Constructor Description MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
Callback after completion of request processing, that is, after rendering the view.HandlerInterceptor
getInterceptor()
The actualHandlerInterceptor
reference.PathMatcher
getPathMatcher()
The configured PathMatcher, ornull
if none.String[]
getPathPatterns()
The path into the application the interceptor is mapped to.boolean
matches(String lookupPath, PathMatcher pathMatcher)
Determine a match for the given lookup path.void
postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
Intercept the execution of a handler.boolean
preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
Intercept the execution of a handler.void
setPathMatcher(PathMatcher pathMatcher)
Configure a PathMatcher to use with this MappedInterceptor instead of the one passed by default to thematches(String, org.springframework.util.PathMatcher)
method.
Constructor Detail
MappedInterceptor
public MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.- Parameters:
includePatterns
- the path patterns to map (empty for matching to all paths)interceptor
- the HandlerInterceptor instance to map to the given patterns
MappedInterceptor
public MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.- Parameters:
includePatterns
- the path patterns to map (empty for matching to all paths)excludePatterns
- the path patterns to exclude (empty for no specific excludes)interceptor
- the HandlerInterceptor instance to map to the given patterns
MappedInterceptor
public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.- Parameters:
includePatterns
- the path patterns to map (empty for matching to all paths)interceptor
- the WebRequestInterceptor instance to map to the given patterns
MappedInterceptor
public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.- Parameters:
includePatterns
- the path patterns to map (empty for matching to all paths)excludePatterns
- the path patterns to exclude (empty for no specific excludes)interceptor
- the WebRequestInterceptor instance to map to the given patterns
Method Detail
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Configure a PathMatcher to use with this MappedInterceptor instead of the one passed by default to thematches(String, org.springframework.util.PathMatcher)
method.This is an advanced property that is only required when using custom PathMatcher implementations that support mapping metadata other than the Ant-style path patterns supported by default.
getPathMatcher
public PathMatcher getPathMatcher()
The configured PathMatcher, ornull
if none.
getPathPatterns
public String[] getPathPatterns()
The path into the application the interceptor is mapped to.
getInterceptor
public HandlerInterceptor getInterceptor()
The actualHandlerInterceptor
reference.
matches
public boolean matches(String lookupPath, PathMatcher pathMatcher)
Determine a match for the given lookup path.- Parameters:
lookupPath
- the current request pathpathMatcher
- a path matcher for path pattern matching
preHandle
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
Description copied from interface:HandlerInterceptor
Intercept 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 a HTTP error or writing a custom response.
Note: special considerations apply for asynchronous request processing. For more details see
AsyncHandlerInterceptor
.- Specified by:
preHandle
in interfaceHandlerInterceptor
- Parameters:
request
- current HTTP requestresponse
- current HTTP responsehandler
- chosen handler to execute, for type and/or instance evaluation- Returns:
true
if 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
postHandle
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception
Description copied from interface:HandlerInterceptor
Intercept the 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
.- Specified by:
postHandle
in interfaceHandlerInterceptor
- Parameters:
request
- current HTTP requestresponse
- current HTTP responsehandler
- handler (orHandlerMethod
) that started asynchronous execution, for type and/or instance examinationmodelAndView
- theModelAndView
that the handler returned (can also benull
)- Throws:
Exception
- in case of errors
afterCompletion
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception
Description copied from interface:HandlerInterceptor
Callback 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
preHandle
method has successfully completed and returnedtrue
!As with the
postHandle
method, 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
.- Specified by:
afterCompletion
in interfaceHandlerInterceptor
- Parameters:
request
- current HTTP requestresponse
- current HTTP responsehandler
- handler (orHandlerMethod
) that started asynchronous execution, for type and/or instance examinationex
- exception thrown on handler execution, if any- Throws:
Exception
- in case of errors