You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/06/21 13:25:08 UTC

svn commit: r956531 - /tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java

Author: markt
Date: Mon Jun 21 11:25:08 2010
New Revision: 956531

URL: http://svn.apache.org/viewvc?rev=956531&view=rev
Log:
Reduce code duplication in connectors: Use AbstractInputBuffer with APR/native connector

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=956531&r1=956530&r2=956531&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java Mon Jun 21 11:25:08 2010
@@ -27,8 +27,6 @@ import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.jni.Status;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.res.StringManager;
 
 import org.apache.coyote.InputBuffer;
 import org.apache.coyote.Request;
@@ -39,7 +37,7 @@ import org.apache.coyote.Request;
  *
  * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  */
-public class InternalAprInputBuffer implements InputBuffer {
+public class InternalAprInputBuffer extends AbstractInputBuffer {
 
 
     // -------------------------------------------------------------- Constants
@@ -75,69 +73,10 @@ public class InternalAprInputBuffer impl
     }
 
 
-    // -------------------------------------------------------------- Variables
-
-
-    /**
-     * The string manager for this package.
-     */
-    protected static final StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
     // ----------------------------------------------------- Instance Variables
 
 
     /**
-     * Associated Coyote request.
-     */
-    protected Request request;
-
-
-    /**
-     * Headers of the associated request.
-     */
-    protected MimeHeaders headers;
-
-
-    /**
-     * State.
-     */
-    protected boolean parsingHeader;
-
-
-    /**
-     * Swallow input ? (in the case of an expectation)
-     */
-    protected boolean swallowInput;
-
-
-    /**
-     * Pointer to the current read buffer.
-     */
-    protected byte[] buf;
-
-
-    /**
-     * Last valid byte.
-     */
-    protected int lastValid;
-
-
-    /**
-     * Position in the buffer.
-     */
-    protected int pos;
-
-
-    /**
-     * Pos of the end of the header in the buffer, which is also the
-     * start of the body.
-     */
-    protected int end;
-
-
-    /**
      * Direct byte buffer used to perform actual reading.
      */
     protected ByteBuffer bbuf;
@@ -149,31 +88,6 @@ public class InternalAprInputBuffer impl
     protected long socket;
 
 
-    /**
-     * Underlying input buffer.
-     */
-    protected InputBuffer inputStreamInputBuffer;
-
-
-    /**
-     * Filter library.
-     * Note: Filter[0] is always the "chunked" filter.
-     */
-    protected InputFilter[] filterLibrary;
-
-
-    /**
-     * Active filters (in order).
-     */
-    protected InputFilter[] activeFilters;
-
-
-    /**
-     * Index of the last active filter.
-     */
-    protected int lastActiveFilter;
-
-
     // ------------------------------------------------------------- Properties
 
 
@@ -194,75 +108,6 @@ public class InternalAprInputBuffer impl
     }
 
 
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addFilter(InputFilter filter) {
-
-        InputFilter[] newFilterLibrary = 
-            new InputFilter[filterLibrary.length + 1];
-        for (int i = 0; i < filterLibrary.length; i++) {
-            newFilterLibrary[i] = filterLibrary[i];
-        }
-        newFilterLibrary[filterLibrary.length] = filter;
-        filterLibrary = newFilterLibrary;
-
-        activeFilters = new InputFilter[filterLibrary.length];
-
-    }
-
-
-    /**
-     * Get filters.
-     */
-    public InputFilter[] getFilters() {
-
-        return filterLibrary;
-
-    }
-
-
-    /**
-     * Clear filters.
-     */
-    public void clearFilters() {
-
-        filterLibrary = new InputFilter[0];
-        lastActiveFilter = -1;
-
-    }
-
-
-    /**
-     * Add an input filter to the filter library.
-     */
-    public void addActiveFilter(InputFilter filter) {
-
-        if (lastActiveFilter == -1) {
-            filter.setBuffer(inputStreamInputBuffer);
-        } else {
-            for (int i = 0; i <= lastActiveFilter; i++) {
-                if (activeFilters[i] == filter)
-                    return;
-            }
-            filter.setBuffer(activeFilters[lastActiveFilter]);
-        }
-
-        activeFilters[++lastActiveFilter] = filter;
-
-        filter.setRequest(request);
-
-    }
-
-
-    /**
-     * Set the swallow input flag.
-     */
-    public void setSwallowInput(boolean swallowInput) {
-        this.swallowInput = swallowInput;
-    }
-
-
     // --------------------------------------------------------- Public Methods
 
 
@@ -270,72 +115,10 @@ public class InternalAprInputBuffer impl
      * Recycle the input buffer. This should be called when closing the 
      * connection.
      */
+    @Override
     public void recycle() {
-
-        // Recycle Request object
-        request.recycle();
-
         socket = 0;
-        lastValid = 0;
-        pos = 0;
-        lastActiveFilter = -1;
-        parsingHeader = true;
-        swallowInput = true;
-
-    }
-
-
-    /**
-     * End processing of current HTTP request.
-     * Note: All bytes of the current request should have been already 
-     * consumed. This method only resets all the pointers so that we are ready
-     * to parse the next HTTP request.
-     */
-    public void nextRequest() {
-
-        // Recycle Request object
-        request.recycle();
-
-        // Copy leftover bytes to the beginning of the buffer
-        if (lastValid - pos > 0) {
-            int npos = 0;
-            int opos = pos;
-            while (lastValid - opos > opos - npos) {
-                System.arraycopy(buf, opos, buf, npos, opos - npos);
-                npos += pos;
-                opos += pos;
-            }
-            System.arraycopy(buf, opos, buf, npos, lastValid - opos);
-        }
-        
-        // Recycle filters
-        for (int i = 0; i <= lastActiveFilter; i++) {
-            activeFilters[i].recycle();
-        }
-
-        // Reset pointers
-        lastValid = lastValid - pos;
-        pos = 0;
-        lastActiveFilter = -1;
-        parsingHeader = true;
-        swallowInput = true;
-
-    }
-
-
-    /**
-     * End request (consumes leftover bytes).
-     * 
-     * @throws IOException an underlying I/O error occurred
-     */
-    public void endRequest()
-        throws IOException {
-
-        if (swallowInput && (lastActiveFilter != -1)) {
-            int extraBytes = (int) activeFilters[lastActiveFilter].end();
-            pos = pos - extraBytes;
-        }
-
+        super.recycle();
     }
 
 
@@ -350,6 +133,7 @@ public class InternalAprInputBuffer impl
      * @return true if data is properly fed; false if no data is available 
      * immediately and thread should be freed
      */
+    @Override
     public boolean parseRequestLine(boolean useAvailableData)
         throws IOException {
 
@@ -537,7 +321,8 @@ public class InternalAprInputBuffer impl
     /**
      * Parse the HTTP headers.
      */
-    public void parseHeaders()
+    @Override
+    public boolean parseHeaders()
         throws IOException {
 
         while (parseHeader()) {
@@ -545,7 +330,7 @@ public class InternalAprInputBuffer impl
 
         parsingHeader = false;
         end = pos;
-
+        return true;
     }
 
 
@@ -729,6 +514,7 @@ public class InternalAprInputBuffer impl
     /**
      * Read some bytes.
      */
+    @Override
     public int doRead(ByteChunk chunk, Request req) 
         throws IOException {
 
@@ -743,6 +529,13 @@ public class InternalAprInputBuffer impl
     // ------------------------------------------------------ Protected Methods
 
 
+    @Override
+    protected boolean fill(boolean block) throws IOException {
+        // Ignore the block parameter and just call fill
+        return fill();
+    }
+    
+    
     /**
      * Fill the internal buffer using data from the underlying input stream.
      * 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org