net.rossillo.spring.web.mvc
Class CacheControlHandlerInterceptor

java.lang.Object
  extended by org.springframework.web.servlet.handler.HandlerInterceptorAdapter
      extended by net.rossillo.spring.web.mvc.CacheControlHandlerInterceptor
All Implemented Interfaces:
org.springframework.web.servlet.HandlerInterceptor

public class CacheControlHandlerInterceptor
extends org.springframework.web.servlet.handler.HandlerInterceptorAdapter
implements org.springframework.web.servlet.HandlerInterceptor

Provides a cache control handler interceptor to assign cache-control headers to HTTP responses.

Author:
Scott Rossillo

Constructor Summary
CacheControlHandlerInterceptor()
          Creates a new cache control handler interceptor.
 
Method Summary
protected  void assignCacheControlHeader(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler)
          Assigns a CacheControl header to the given response.
protected  String createCacheControlHeader(CacheControl cacheControl)
          Returns cache control header value from the given CacheControl annotation.
protected  long createExpiresHeader(CacheControl cacheControl)
          Returns an expires header value generated from the given CacheControl annotation.
protected  CacheControl getCacheControl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler)
          Returns the CacheControl annotation specified for the given request, response and handler.
 boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler)
           
 void setUseExpiresHeader(boolean useExpiresHeader)
          True to set an expires header when a CacheControl annotation is present on a handler; false otherwise.
 
Methods inherited from class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
afterCompletion, postHandle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.web.servlet.HandlerInterceptor
afterCompletion, postHandle
 

Constructor Detail

CacheControlHandlerInterceptor

public CacheControlHandlerInterceptor()
Creates a new cache control handler interceptor.

Method Detail

assignCacheControlHeader

protected final void assignCacheControlHeader(javax.servlet.http.HttpServletRequest request,
                                              javax.servlet.http.HttpServletResponse response,
                                              Object handler)
Assigns a CacheControl header to the given response.

Parameters:
request - the HttpServletRequest
response - the HttpServletResponse
handler - the handler for the given request

createCacheControlHeader

protected final String createCacheControlHeader(CacheControl cacheControl)
Returns cache control header value from the given CacheControl annotation.

Parameters:
cacheControl - the CacheControl annotation from which to create the returned cache control header value
Returns:
the cache control header value

createExpiresHeader

protected final long createExpiresHeader(CacheControl cacheControl)
Returns an expires header value generated from the given CacheControl annotation.

Parameters:
cacheControl - the CacheControl annotation from which to create the returned expires header value
Returns:
the expires header value

getCacheControl

protected final CacheControl getCacheControl(javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response,
                                             Object handler)
Returns the CacheControl annotation specified for the given request, response and handler.

Parameters:
request - the current HttpServletRequest
response - the current HttpServletResponse
handler - the current request handler
Returns:
the CacheControl annotation specified by the given handler if present; null otherwise

preHandle

public final boolean preHandle(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response,
                               Object handler)
                        throws Exception
Specified by:
preHandle in interface org.springframework.web.servlet.HandlerInterceptor
Overrides:
preHandle in class org.springframework.web.servlet.handler.HandlerInterceptorAdapter
Throws:
Exception

setUseExpiresHeader

public final void setUseExpiresHeader(boolean useExpiresHeader)
True to set an expires header when a CacheControl annotation is present on a handler; false otherwise. Defaults to true.

Parameters:
useExpiresHeader - true to set an expires header when a CacheControl annotation is present on a handler; false otherwise


Copyright © 2015. All rights reserved.