Commits

Anonymous committed 80456b3

Adding 3 methods isCommitted, reset and resetBuffer
Issue number: CACHE-216 Review CacheFilter against Servlet 2.4 spec.
Submitted by: Lars Torunski

Comments (0)

Files changed (1)

src/java/com/opensymphony/oscache/web/filter/CacheHttpServletResponseWrapper.java

      * We cache the printWriter so we can maintain a single instance
      * of it no matter how many times it is requested.
      */
-    private PrintWriter cachedWriter;
+    private PrintWriter cachedWriter = null;
     private ResponseContent result = null;
     private SplitServletOutputStream cacheOut = null;
     private boolean fragment = false;
             cachedWriter.flush();
         }
     }
+
+    /**
+     * @see javax.servlet.ServletResponseWrapper#isCommitted()
+     */
+    public boolean isCommitted() {
+        return super.isCommitted() || (result.getOutputStream() == null);
+    }
+
+    /**
+     * @see javax.servlet.ServletResponseWrapper#reset()
+     */
+    public void reset() {
+        if (!isCommitted()) {
+            super.reset();
+            cachedWriter = null;
+            result = null;
+            cacheOut = null;
+            fragment = false;
+            status = SC_OK;
+            expires = CacheFilter.EXPIRES_ON;
+            lastModified = CacheFilter.LAST_MODIFIED_INITIAL;
+        } else {
+            throw new IllegalStateException("Can't reset CacheHttpServletResponseWrapper, because it's already committed!");
+        }
+    }
+
+    /**
+     * @see javax.servlet.ServletResponseWrapper#resetBuffer()
+     */
+    public void resetBuffer() {
+        if (!isCommitted()) {
+            super.resetBuffer();
+            cachedWriter = null;
+            result = null;
+            cacheOut = null;
+            fragment = false;
+            // The resetBuffer method clears content in the buffer if the
+            // response is not committed without clearing the headers and status code.
+        } else {
+            throw new IllegalStateException("Can't reset buffer CacheHttpServletResponseWrapper, because it's already committed!");
+        }
+    }
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.