Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/filter/NoCacheFilter.java @ 4423:687b7a6f09aa
Move GGInAFilter and NoCacheFilter to an own package
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 06 Nov 2012 13:39:00 +0100 |
parents | |
children | cc6323401643 |
comparison
equal
deleted
inserted
replaced
4422:95ffae40c8f2 | 4423:687b7a6f09aa |
---|---|
1 package de.intevation.flys.client.server.filter; | |
2 | |
3 import java.io.IOException; | |
4 import java.util.Enumeration; | |
5 import java.util.Date; | |
6 | |
7 import javax.servlet.Filter; | |
8 import javax.servlet.FilterChain; | |
9 import javax.servlet.FilterConfig; | |
10 import javax.servlet.ServletException; | |
11 import javax.servlet.ServletRequest; | |
12 import javax.servlet.ServletResponse; | |
13 | |
14 import javax.servlet.http.HttpServletRequest; | |
15 import javax.servlet.http.HttpServletResponse; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 /** ServletFilter to avoid caching for GWTs *.nocache.* files. */ | |
20 public class NoCacheFilter implements Filter { | |
21 | |
22 private static final long DAY = 86400000L; | |
23 | |
24 private static final String NO_CACHE = ".nocache."; | |
25 | |
26 private static Logger log = Logger.getLogger(NoCacheFilter.class); | |
27 | |
28 /** | |
29 * Initialize. | |
30 */ | |
31 @Override | |
32 public void init(FilterConfig config) | |
33 throws ServletException | |
34 { | |
35 } | |
36 | |
37 | |
38 /** | |
39 * Called when filter in chain invoked. | |
40 * @param req request to servlet | |
41 * @param resp response of servlet | |
42 * @param chain the filter chain | |
43 */ | |
44 @Override | |
45 public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) | |
46 throws IOException, ServletException | |
47 { | |
48 HttpServletRequest httpreq = (HttpServletRequest)req; | |
49 String uri = httpreq.getRequestURI(); | |
50 | |
51 if (uri.contains(NO_CACHE)) { | |
52 log.debug("Set no-cache for " + uri); | |
53 | |
54 Date now = new Date(); | |
55 HttpServletResponse httpresp = (HttpServletResponse)resp; | |
56 httpresp.setDateHeader("Date", now.getTime()); | |
57 httpresp.setDateHeader("Expires", now.getTime() - DAY); | |
58 httpresp.setHeader("Pragma", "no-cache"); | |
59 httpresp.setHeader("Cache-control", | |
60 "no-cache, no-store, must-revalidate"); | |
61 } | |
62 | |
63 chain.doFilter(req, resp); | |
64 } | |
65 | |
66 | |
67 /** | |
68 * Do nothing at destruction. | |
69 */ | |
70 @Override | |
71 public void destroy() { | |
72 } | |
73 } | |
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |