This project has retired. For details please refer to its Attic page.
YesCacheFilter xref
View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.webconsole;
17  
18  import java.io.IOException;
19  import java.text.SimpleDateFormat;
20  import java.util.Calendar;
21  import java.util.GregorianCalendar;
22  import javax.servlet.Filter;
23  import javax.servlet.FilterChain;
24  import javax.servlet.FilterConfig;
25  import javax.servlet.ServletException;
26  import javax.servlet.ServletRequest;
27  import javax.servlet.ServletResponse;
28  import javax.servlet.http.HttpServletResponse;
29  
30  /**
31   *
32   * @author Alex O'Ree
33   */
34  public class YesCacheFilter implements Filter {
35          
36          @Override
37          public void init(FilterConfig fc) throws ServletException {
38                  
39          }
40          
41          @Override
42          public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
43                  HttpServletResponse hsr = (HttpServletResponse) res;
44                  hsr.setHeader("Cache-Control", "public, max-age=86400"); // HTTP 1.1.
45                  Calendar c = new GregorianCalendar();
46                  c.add(Calendar.MONTH, -1);
47                  SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
48                  
49                  hsr.setHeader("Last-Modified", sdf.format(c.getTime())); // HTTP 1.0.
50                  hsr.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 60 * 60 * 1000)); // 1 month.
51                  chain.doFilter(req, res);
52                  
53          }
54          
55          @Override
56          public void destroy() {
57                  
58          }
59          
60  }