public class WebContentInterceptor extends WebContentGenerator implements HandlerInterceptor
CacheControl
builder.
See superclass bean properties for configuration options.
All the settings supported by this interceptor can also be set on
AbstractController
. This interceptor is mainly intended for applying
checks and preparations to a set of controllers mapped by a HandlerMapping.
AbstractController
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
logger
Constructor and Description |
---|
WebContentInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
addCacheMapping(CacheControl cacheControl,
String... paths)
Map specific URL paths to a specific
CacheControl . |
void |
afterCompletion(HttpServletRequest request,
HttpServletResponse response,
Object handler,
Exception ex)
This implementation is empty.
|
protected CacheControl |
lookupCacheControl(String urlPath)
Look up a
CacheControl instance for the given URL path. |
protected Integer |
lookupCacheSeconds(String urlPath)
Look up a cacheSeconds integer value for the given URL path.
|
void |
postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView)
This implementation is empty.
|
boolean |
preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler)
Intercept the execution of a handler.
|
void |
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlying
UrlPathHelper . |
void |
setCacheMappings(Properties cacheMappings)
Map specific URL paths to specific cache seconds.
|
void |
setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths
against registered URL patterns, for determining cache mappings.
|
void |
setUrlDecode(boolean urlDecode)
Shortcut to same property on underlying
UrlPathHelper . |
void |
setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.
|
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
UrlPathHelper
.
Only relevant for the "cacheMappings" setting.
public void setUrlDecode(boolean urlDecode)
UrlPathHelper
.
Only relevant for the "cacheMappings" setting.
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers.
Only relevant for the "cacheMappings" setting.
public void setCacheMappings(Properties cacheMappings)
Overrides the default cache seconds setting of this interceptor. Can specify "-1" to exclude a URL path from default caching.
Supports direct matches, e.g. a registered "/test" matches "/test", and a various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher javadoc.
NOTE: Path patterns are not supposed to overlap. If a request
matches several mappings, it is effectively undefined which one will apply
(due to the lack of key ordering in java.util.Properties
).
cacheMappings
- a mapping between URL paths (as keys) and
cache seconds (as values, need to be integer-parsable)WebContentGenerator.setCacheSeconds(int)
,
AntPathMatcher
public void addCacheMapping(CacheControl cacheControl, String... paths)
CacheControl
.
Overrides the default cache seconds setting of this interceptor.
Can specify a empty CacheControl
instance
to exclude a URL path from default caching.
Supports direct matches, e.g. a registered "/test" matches "/test", and a various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher javadoc.
NOTE: Path patterns are not supposed to overlap. If a request
matches several mappings, it is effectively undefined which one will apply
(due to the lack of key ordering in the underlying java.util.HashMap
).
cacheControl
- the CacheControl
to usepaths
- the URL paths that will map to the given CacheControl
WebContentGenerator.setCacheSeconds(int)
,
AntPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException
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.ServletException
@Nullable protected CacheControl lookupCacheControl(String urlPath)
CacheControl
instance for the given URL path.
Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
urlPath
- the URL the bean is mapped toCacheControl
, or null
if not foundAntPathMatcher
@Nullable protected Integer lookupCacheSeconds(String urlPath)
Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.
urlPath
- the URL the bean is mapped tonull
if not foundAntPathMatcher
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception
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
)Exception
- in case of errorspublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception
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 anyException
- in case of errors