public final class MappedInterceptor extends java.lang.Object implements HandlerInterceptor
HandlerInterceptor
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 type MappedInterceptor
are automatically detected by AbstractHandlerMethodMapping
(including
ancestor ApplicationContext's) which effectively means the interceptor is
registered "globally" with all handler mappings.
Modifier and Type | Field and Description |
---|---|
private java.lang.String[] |
excludePatterns |
private java.lang.String[] |
includePatterns |
private HandlerInterceptor |
interceptor |
private PathMatcher |
pathMatcher |
Constructor and Description |
---|
MappedInterceptor(java.lang.String[] includePatterns,
HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.
|
MappedInterceptor(java.lang.String[] includePatterns,
java.lang.String[] excludePatterns,
HandlerInterceptor interceptor)
Create a new MappedInterceptor instance.
|
MappedInterceptor(java.lang.String[] includePatterns,
java.lang.String[] excludePatterns,
WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.
|
MappedInterceptor(java.lang.String[] includePatterns,
WebRequestInterceptor interceptor)
Create a new MappedInterceptor instance.
|
Modifier and Type | Method and Description |
---|---|
void |
afterCompletion(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
java.lang.Exception ex)
Callback after completion of request processing, that is, after rendering
the view.
|
HandlerInterceptor |
getInterceptor()
The actual Interceptor reference.
|
PathMatcher |
getPathMatcher()
The configured PathMatcher, or
null if none. |
java.lang.String[] |
getPathPatterns()
The path into the application the interceptor is mapped to.
|
boolean |
matches(java.lang.String lookupPath,
PathMatcher pathMatcher)
Returns
true if the interceptor applies to the given request path. |
void |
postHandle(HttpServletRequest request,
HttpServletResponse response,
java.lang.Object handler,
ModelAndView modelAndView)
Intercept the execution of a handler.
|
boolean |
preHandle(HttpServletRequest request,
HttpServletResponse response,
java.lang.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 the
matches(String, org.springframework.util.PathMatcher)
method. |
@Nullable private final java.lang.String[] includePatterns
@Nullable private final java.lang.String[] excludePatterns
private final HandlerInterceptor interceptor
@Nullable private PathMatcher pathMatcher
public MappedInterceptor(@Nullable java.lang.String[] includePatterns, HandlerInterceptor interceptor)
includePatterns
- the path patterns to map with a null
value matching to all pathsinterceptor
- the HandlerInterceptor instance to map to the given patternspublic MappedInterceptor(@Nullable java.lang.String[] includePatterns, @Nullable java.lang.String[] excludePatterns, HandlerInterceptor interceptor)
includePatterns
- the path patterns to map with a null
value matching to all pathsexcludePatterns
- the path patterns to excludeinterceptor
- the HandlerInterceptor instance to map to the given patternspublic MappedInterceptor(@Nullable java.lang.String[] includePatterns, WebRequestInterceptor interceptor)
includePatterns
- the path patterns to map with a null
value matching to all pathsinterceptor
- the WebRequestInterceptor instance to map to the given patternspublic MappedInterceptor(@Nullable java.lang.String[] includePatterns, @Nullable java.lang.String[] excludePatterns, WebRequestInterceptor interceptor)
includePatterns
- the path patterns to map with a null
value matching to all pathsinterceptor
- the WebRequestInterceptor instance to map to the given patternspublic void setPathMatcher(@Nullable PathMatcher pathMatcher)
matches(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.@Nullable public PathMatcher getPathMatcher()
null
if none.@Nullable public java.lang.String[] getPathPatterns()
public HandlerInterceptor getInterceptor()
public boolean matches(java.lang.String lookupPath, PathMatcher pathMatcher)
true
if the interceptor applies to the given request path.lookupPath
- the current request pathpathMatcher
- a path matcher for path pattern matchingpublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler) throws java.lang.Exception
HandlerInterceptor
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
.
The default implementation returns true
.
preHandle
in interface HandlerInterceptor
request
- current HTTP requestresponse
- current HTTP responsehandler
- chosen handler to execute, for type and/or instance evaluationtrue
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.java.lang.Exception
- in case of errorspublic void postHandle(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, @Nullable ModelAndView modelAndView) throws java.lang.Exception
HandlerInterceptor
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.
postHandle
in interface HandlerInterceptor
request
- current HTTP requestresponse
- current HTTP responsehandler
- handler (or HandlerMethod
) that started asynchronous
execution, for type and/or instance examinationmodelAndView
- the ModelAndView
that the handler returned
(can also be null
)java.lang.Exception
- in case of errorspublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, java.lang.Object handler, @Nullable java.lang.Exception ex) throws java.lang.Exception
HandlerInterceptor
Note: Will only be called if this interceptor's preHandle
method has successfully completed and returned true
!
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
.
The default implementation is empty.
afterCompletion
in interface HandlerInterceptor
request
- current HTTP requestresponse
- current HTTP responsehandler
- handler (or HandlerMethod
) that started asynchronous
execution, for type and/or instance examinationex
- exception thrown on handler execution, if anyjava.lang.Exception
- in case of errors