root / src / gr / ebs / gss / server / CacheFilter.java @ 6b5bd65e
History | View | Annotate | Download (2.6 kB)
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 |
@Override
|
41 |
public void doFilter( ServletRequest request, ServletResponse response, |
42 |
FilterChain filterChain) throws IOException, ServletException { |
43 |
HttpServletRequest httpRequest = (HttpServletRequest)request; |
44 |
String requestURI = httpRequest.getRequestURI();
|
45 |
String contextPath = httpRequest.getContextPath();
|
46 |
if (requestURI.contains(".nocache.")) { |
47 |
HttpServletResponse httpResponse = (HttpServletResponse)response; |
48 |
httpResponse.setHeader("Expires", "Fri, 01 Jan 1990 00:00:00 GMT"); |
49 |
httpResponse.setHeader("Pragma", "no-cache"); |
50 |
httpResponse.setHeader("Cache-control", "no-cache, must-revalidate"); |
51 |
} else if (requestURI.contains(".cache.")) { |
52 |
long today = new Date().getTime(); |
53 |
HttpServletResponse httpResponse = (HttpServletResponse)response; |
54 |
httpResponse.setDateHeader("Expires", today+31536000000L); |
55 |
} else if (!requestURI.startsWith(contextPath + "/nonce") && |
56 |
!requestURI.startsWith(contextPath + "/token") &&
|
57 |
!requestURI.startsWith(contextPath + "/login") &&
|
58 |
!requestURI.startsWith(contextPath + "/rest") &&
|
59 |
!requestURI.startsWith(contextPath + "/policy")) {
|
60 |
long today = new Date().getTime(); |
61 |
HttpServletResponse httpResponse = (HttpServletResponse)response; |
62 |
httpResponse.setDateHeader("Expires", today+3456000000L); |
63 |
} |
64 |
filterChain.doFilter(request, response); |
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void destroy() { |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void init(FilterConfig filterConfig) { |
73 |
} |
74 |
} |