|
1 |
/*
|
|
2 |
* Copyright 2009 Electronic Business Systems Ltd.
|
|
3 |
*
|
|
4 |
* This file is part of GSS.
|
|
5 |
*
|
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* GSS is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
|
18 |
*/
|
|
19 |
package gr.ebs.gss.server;
|
|
20 |
|
|
21 |
import java.io.IOException;
|
|
22 |
import java.util.Date;
|
|
23 |
|
|
24 |
import javax.servlet.Filter;
|
|
25 |
import javax.servlet.FilterChain;
|
|
26 |
import javax.servlet.FilterConfig;
|
|
27 |
import javax.servlet.ServletException;
|
|
28 |
import javax.servlet.ServletRequest;
|
|
29 |
import javax.servlet.ServletResponse;
|
|
30 |
import javax.servlet.http.HttpServletRequest;
|
|
31 |
import javax.servlet.http.HttpServletResponse;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* A cache filter that properly caches GWT-generated files.
|
|
35 |
*
|
|
36 |
* @author past
|
|
37 |
*
|
|
38 |
*/
|
|
39 |
public class CacheFilter implements Filter {
|
|
40 |
public void doFilter( ServletRequest request, ServletResponse response,
|
|
41 |
FilterChain filterChain) throws IOException, ServletException {
|
|
42 |
HttpServletRequest httpRequest = (HttpServletRequest)request;
|
|
43 |
String requestURI = httpRequest.getRequestURI();
|
|
44 |
if (requestURI.contains(".nocache.")) {
|
|
45 |
HttpServletResponse httpResponse = (HttpServletResponse)response;
|
|
46 |
httpResponse.setHeader("Expires", "Fri, 01 Jan 1990 00:00:00 GMT");
|
|
47 |
httpResponse.setHeader("Pragma", "no-cache");
|
|
48 |
httpResponse.setHeader("Cache-control", "no-cache, must-revalidate");
|
|
49 |
} else if (requestURI.contains(".cache.")) {
|
|
50 |
long today = new Date().getTime();
|
|
51 |
HttpServletResponse httpResponse = (HttpServletResponse)response;
|
|
52 |
httpResponse.setDateHeader("Expires", today+31536000000L);
|
|
53 |
} else {
|
|
54 |
long today = new Date().getTime();
|
|
55 |
HttpServletResponse httpResponse = (HttpServletResponse)response;
|
|
56 |
httpResponse.setDateHeader("Expires", today+3456000000L);
|
|
57 |
}
|
|
58 |
filterChain.doFilter(request, response);
|
|
59 |
}
|
|
60 |
|
|
61 |
@Override
|
|
62 |
public void destroy() {
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public void init(FilterConfig filterConfig) {
|
|
67 |
}
|
|
68 |
}
|