cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r637585 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice: HttpServletResponseBufferingWrapper.java ServletServiceContext.java
Date Sun, 16 Mar 2008 13:14:13 GMT
Author: gkossakowski
Date: Sun Mar 16 06:14:12 2008
New Revision: 637585

URL: http://svn.apache.org/viewvc?rev=637585&view=rev
Log:
Added some Javadocs and comments.

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java?rev=637585&r1=637584&r2=637585&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java
Sun Mar 16 06:14:12 2008
@@ -27,10 +27,35 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
+import org.apache.log4j.Logger;
+
+/**
+ * <p>THIS IS INTERNAL CLASS OF SERVLET SERVICE FRAMEWORK AND SHOULDN'T BE USED ELSEWHERE!</p>
+ * 
+ * <p>This class works in two modes:</p>
+ * <ol>
+ * <li>If status code has been set to value different than <code>404</code>
(<code>SC_NOT_FOUND</code>) then this class 
+ *     acts completely transparently by forwarding all method calls to wrapped response object.</li>
+ * <li>If status code has been set to <code>404</code> then this class
acts like a buffer. It buffers all method calls 
+ *     that would commit wrapped response. Buffering of such calls is being performed in
order to assure that wrapped 
+ *     response can be always reseted if needed. It's worth mentioning the fact that buffer
for {@link OutputStream}
+ *     returned by {@link #getOutputStream()} is limited to the size specified in
+ *     {@link #BUFFER_LIMIT} field.</li>
+ *
+ *  <p>Additionally, this class lets the access to statusCode code that has been set
through the 
+ *     {@link #getStatusCode()} method.</p> 
+ */
 class HttpServletResponseBufferingWrapper extends HttpServletResponseWrapper {
 
-    static private int BUFFER_LIMIT = 1024 * 1024;
+    /**
+     * Limit for a buffer for output stream returned by {@link #getOutputStream()} method.
+     * This is a hard limit, if exceeded an exception is thrown.
+     */
+    static private int BUFFER_LIMIT = 1024 * 1024; //= 1MB
     static private String ALREADY_COMMITTED_EXCEPTION = "The response has been already committed.";
+    
+    public Logger log = Logger.getLogger(getClass());
+    
     private boolean bufferResponse;
     private boolean committed;
     private String message;
@@ -237,6 +262,10 @@
         return statusCode;
     }
 
+    /**
+     * Simple class acting like a {@link ServletOutputStream} but limiting number of bytes
that can be written to the 
+     * stream.
+     */
     private class LimitingServletOutputStream extends ServletOutputStream {
 
         private int writeLimit;
@@ -250,11 +279,14 @@
         public void write(int b) throws IOException {
             if (this.outputStream.size() < this.writeLimit)
                 this.outputStream.write(b);
-            else
-                throw new RuntimeException(
+            else {
+                RuntimeException e = new RuntimeException(
                         "The buffering limit (" + writeLimit+ ") has been reached. If you
encounter this exception it means that you to "
-                                + "write a big response body for response that has error
code set as status code. This is always a bad "
-                                + "idea and in such case you should reconsider your design.");
+                        + "write a big response body for response that has error code set
as status code. This is always a bad "
+                        + "idea and in such case you should reconsider your design.");
+                HttpServletResponseBufferingWrapper.this.log.fatal("Fatal error occured in
writing to response", e);
+                throw e;
+            }
         }
 
         public void reset() {

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java?rev=637585&r1=637584&r2=637585&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
Sun Mar 16 06:14:12 2008
@@ -471,7 +471,11 @@
                 NamedDispatcher _super = (NamedDispatcher) ServletServiceContext.this.getNamedDispatcher(SUPER);
                 if (status == HttpServletResponse.SC_NOT_FOUND && _super != null)
{
                     //if servlet returned NOT_FOUND (404) and has super servlet declared
let's reset everything and ask the super servlet
+                    
+                    //wrapping object resets underlying response as well 
                     wrappedResponse.resetBufferedResponse();
+                    //here we don't need to pass wrappedResponse object because it's not
our concern to buffer response anymore
+                    //this avoids many overlapping buffers
                     _super.forward(request, response);
                 } else {
                     wrappedResponse.flushBufferedResponse();



Mime
View raw message