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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16package org.apache.juddi.webconsole;
1718import java.io.IOException;
19import java.text.SimpleDateFormat;
20import java.util.Calendar;
21import java.util.GregorianCalendar;
22import javax.servlet.Filter;
23import javax.servlet.FilterChain;
24import javax.servlet.FilterConfig;
25import javax.servlet.ServletException;
26import javax.servlet.ServletRequest;
27import javax.servlet.ServletResponse;
28import javax.servlet.http.HttpServletResponse;
2930/**31 *32 * @author Alex O'Ree33 */34publicclassYesCacheFilterimplements Filter {
3536 @Override
37publicvoid init(FilterConfig fc) throws ServletException {
3839 }
4041 @Override
42publicvoid 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");
4849 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);
5253 }
5455 @Override
56publicvoid destroy() {
5758 }
5960 }