1 package de.halbekunst.juplo.cachecontrol;
3 import de.halbekunst.juplo.cachecontrol.AcceleratorFilter.AccelerationWrapper;
4 import de.halbekunst.juplo.cachecontrol.annotations.Cacheable;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.web.servlet.HandlerInterceptor;
11 import org.springframework.web.servlet.ModelAndView;
17 public class CacheControlInterceptor implements HandlerInterceptor {
18 private final static Logger log = LoggerFactory.getLogger(CacheControlInterceptor.class);
21 private CacheControl cacheControl;
25 public boolean preHandle(
26 HttpServletRequest request,
27 HttpServletResponse response,
31 Cacheable cacheable = handler.getClass().getAnnotation(Cacheable.class);
32 if (cacheable == null) {
33 /** Der Handler ist nicht mit @Cacheable annotiert: keine Dekorationen anbringen! */
37 AccelerationWrapper wrapper = (AccelerationWrapper)request.getAttribute(AcceleratorFilter.RESPONSE_WRAPPER);
39 wrapper.supressGuessing();
41 /** CacheControll initialisieren (Handler nach annotierte Methoden scannen etc.) */
42 cacheControl.init(handler, wrapper);
44 if (cacheable.eager()) {
45 return cacheControl.decorate(request, response);
53 public void postHandle(
54 HttpServletRequest request,
55 HttpServletResponse response,
57 ModelAndView modelAndView
61 * Dekoration nur dann anstossen, wenn sie nicht bereits von dem
62 * AcceleratorFilter ausgelöst wird.
64 if (request.getAttribute(AcceleratorFilter.RESPONSE_WRAPPER) == null)
65 cacheControl.decorate(request, response);
69 public void afterCompletion(
70 HttpServletRequest request,
71 HttpServletResponse response,
72 Object handler, Exception ex
75 cacheControl.release();
80 public void setCacheControl(CacheControl cacheControl) {
81 this.cacheControl = cacheControl;