1 /**
2 * Copyright 2003-2007 Greg Luck
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
17 package net.sf.ehcache.constructs.web.filter;
18
19 import net.sf.ehcache.constructs.web.PageInfo;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import javax.servlet.FilterChain;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 /**
28 * This implementation only writes the response when it is not committed. This is half
29 * right. In the wild it can cause the dreaded blank page problem.
30 <p/>
31 * Another half right solution is to write the response. The problem then is,
32 * if the response is gzipped, the body might be gzipped but the headers won't show it.
33 * The result will be yet another blank page in Internet Explorer.
34 * <p/>
35 * The correct thing to do is to throw an exception.
36 * @see SimplePageCachingFilter
37 * @author Greg Luck
38 * @version $Id: SimplePageCachingFilterWithBlankPageProblem.java 512 2007-07-10 09:18:45Z gregluck $
39 */
40 public class SimplePageCachingFilterWithBlankPageProblem extends SimplePageCachingFilter {
41 /**
42 * The name of the filter. This should match a cache name in ehcache.xml
43 */
44 public static final String NAME = "SimplePageCachingFilterWithBlankPageProblem";
45
46 private static final Log LOG = LogFactory.getLog(SimplePageCachingFilterWithBlankPageProblem.class.getName());
47
48 /**
49 * {@inheritDoc}
50 */
51 protected void doFilter(final HttpServletRequest request, final HttpServletResponse response,
52 final FilterChain chain) throws Exception {
53 PageInfo pageInfo = buildPageInfo(request, response, chain);
54 if (response.isCommitted()) {
55 if (LOG.isWarnEnabled()) {
56 LOG.warn("Response cannot be written as it was already committed for "
57 + request.getRequestURL());
58 }
59 } else {
60 writeResponse(request, response, pageInfo);
61 }
62 }
63 }
64