Class WebContentInterceptor
- All Implemented Interfaces:
- Aware,- ApplicationContextAware,- ServletContextAware,- HandlerInterceptor
Cache settings may be configured for specific URLs via path pattern with
 addCacheMapping(CacheControl, String...) and
 setCacheMappings(Properties), along with a fallback on default
 settings for all URLs via WebContentGenerator.setCacheControl(CacheControl).
 
Pattern matching can be done with PathMatcher or with parsed
 PathPatterns. The syntax is largely the same with the latter being
 more tailored for web usage and more efficient. The choice depends on the
 presence of a resolved
 String lookupPath or a parsed RequestPath which in turn depends on the
 HandlerMapping that matched the current request.
 
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.
- Since:
- 27.11.2003
- Author:
- Juergen Hoeller, Brian Clozel, Rossen Stoyanchev
- See Also:
- 
Field SummaryFields inherited from class org.springframework.web.servlet.support.WebContentGeneratorHEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POSTFields inherited from class org.springframework.context.support.ApplicationObjectSupportlogger
- 
Constructor SummaryConstructorsConstructorDescriptionDefault constructor withPathPatternParser.defaultInstance.Constructor with aPathPatternParserto parse patterns with.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddCacheMapping(CacheControl cacheControl, String... paths) Map specific URL paths to a specificCacheControl.voidafterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) This implementation is empty.protected @Nullable CacheControllookupCacheControl(String lookupPath) Deprecated, for removal: This API element is subject to removal in a future version.protected @Nullable CacheControlFind aCacheControlinstance for the given parsedpath.lookupCacheSeconds(String lookupPath) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Find a cacheSeconds value for the given parsedpath.voidpostHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) This implementation is empty.booleanpreHandle(HttpServletRequest request, HttpServletResponse response, Object handler) Interception point before the execution of a handler.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath) Deprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)voidsetCacheMappings(Properties cacheMappings) Map settings for cache seconds to specific URL paths via patterns.voidsetPathMatcher(PathMatcher pathMatcher) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.voidsetUrlDecode(boolean urlDecode) Deprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)voidsetUrlPathHelper(UrlPathHelper urlPathHelper) Deprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)Methods inherited from class org.springframework.web.servlet.support.WebContentGeneratorapplyCacheControl, applyCacheSeconds, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isRequireSession, prepareResponse, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setVaryByRequestHeadersMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Constructor Details- 
WebContentInterceptorpublic WebContentInterceptor()Default constructor withPathPatternParser.defaultInstance.
- 
WebContentInterceptorConstructor with aPathPatternParserto parse patterns with.- Since:
- 5.3
 
 
- 
- 
Method Details- 
setAlwaysUseFullPathDeprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)Shortcut to thesame propertyon the configuredUrlPathHelper.
- 
setUrlDecodeDeprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)Shortcut to thesame propertyon the configuredUrlPathHelper.
- 
setUrlPathHelperDeprecated.as of 5.3, the path is resolved externally and obtained withServletRequestPathUtils.getCachedPathValue(ServletRequest)Set the UrlPathHelper to use for resolution of lookup paths.
- 
setPathMatcherDeprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Configure the PathMatcher to use to match URL paths against registered URL patterns to select the cache settings for a request.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.
- 
setCacheMappingsMap settings for cache seconds to specific URL paths via patterns.Overrides the default cache seconds setting of this interceptor. Can specify "-1" to exclude a URL path from default caching. For pattern syntax see AntPathMatcherandPathPatternas well as the class-level Javadoc for details for when each is used. The syntax is largely the same withPathPatternmore tailored for web usage.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).- Parameters:
- cacheMappings- a mapping between URL paths (as keys) and cache seconds (as values, need to be integer-parsable)
- See Also:
 
- 
addCacheMappingMap specific URL paths to a specificCacheControl.Overrides the default cache seconds setting of this interceptor. Can specify an empty CacheControlinstance to exclude a URL path from default caching.For pattern syntax see AntPathMatcherandPathPatternas well as the class-level Javadoc for details for when each is used. The syntax is largely the same withPathPatternmore tailored for web usage.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).- Parameters:
- cacheControl- the- CacheControlto use
- paths- the URL paths that will map to the given- CacheControl
- Since:
- 4.2
- See Also:
 
- 
preHandlepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException 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:
- ServletException
 
- 
lookupCacheControlFind aCacheControlinstance for the given parsedpath. This is used when theHandlerMappinguses parsedPathPatterns.- Parameters:
- path- the path to match to
- Returns:
- the matched CacheControl, ornullif no match
- Since:
- 5.3
 
- 
lookupCacheControl@Deprecated(since="7.0", forRemoval=true) protected @Nullable CacheControl lookupCacheControl(String lookupPath) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Find aCacheControlinstance for the given String lookupPath. This is used when theHandlerMappingrelies on String pattern matching withPathMatcher.- Parameters:
- lookupPath- the path to match to
- Returns:
- the matched CacheControl, ornullif no match
 
- 
lookupCacheSecondsFind a cacheSeconds value for the given parsedpath. This is used when theHandlerMappinguses parsedPathPatterns.- Parameters:
- path- the path to match to
- Returns:
- the matched cacheSeconds, or nullif there is no match
- Since:
- 5.3
 
- 
lookupCacheSeconds@Deprecated(since="7.0", forRemoval=true) protected @Nullable Integer lookupCacheSeconds(String lookupPath) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Find a cacheSeconds instance for the given String lookupPath. This is used when theHandlerMappingrelies on String pattern matching withPathMatcher.- Parameters:
- lookupPath- the path to match to
- Returns:
- the matched cacheSeconds, or nullif there is no match
 
- 
postHandlepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception This 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 This 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
 
 
- 
PathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.