tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters IdentityInputFilter.java IdentityOutputFilter.java
Date Mon, 03 Dec 2001 06:09:30 GMT
remm        01/12/02 22:09:30

  Modified:    http11/src/java/org/apache/coyote/http11
                        Http11Connector.java InputFilter.java
                        InternalInputBuffer.java InternalOutputBuffer.java
                        OutputFilter.java
               http11/src/java/org/apache/coyote/http11/filters
                        IdentityInputFilter.java IdentityOutputFilter.java
  Log:
  - Continuing development.
  - Change the pattern used by the filters to use a more conventional chain. The
    old machanism was too constraining.
  
  Revision  Changes    Path
  1.3       +48 -7     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Connector.java
  
  Index: Http11Connector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Connector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Http11Connector.java	2001/10/01 01:20:42	1.2
  +++ Http11Connector.java	2001/12/03 06:09:30	1.3
  @@ -59,6 +59,8 @@
   
   package org.apache.coyote.http11;
   
  +import java.io.EOFException;
  +import java.io.InterruptedIOException;
   import java.io.InputStream;
   import java.io.IOException;
   import java.io.OutputStream;
  @@ -156,17 +158,56 @@
           inputBuffer.setInputStream(input);
           outputBuffer.setOutputStream(output);
   
  +        // Ok flag
  +        boolean ok = true;
  +        // TEMP
  +        boolean stopped = false;
  +
  +        while (!stopped && ok) {
  +
  +            try {
  +                inputBuffer.parseRequestLine();
  +                // Check for HTTP/0.9
  +                
  +                inputBuffer.parseHeaders();
  +            } catch (EOFException e) {
  +                ok = false;
  +            } catch (InterruptedIOException e) {
  +                //HttpServletResponse.SC_BAD_REQUEST
  +                ok = false;
  +            } catch (Exception e) {
  +                //SC_BAD_REQUEST
  +                ok = false;
  +            }
  +
  +            // Setting up filters, and parse some request headers
  +            prepareRequest();
  +
  +            // Process the request in the adapter
  +            try {
  +                adapter.service(request, response);
  +            } catch (InterruptedIOException e) {
  +                ok = false;
  +            } catch (Throwable t) {
  +                // ISE
  +                ok = false;
  +            }
  +
  +            // Finish the handling of the request
  +            try {
  +                outputBuffer.endRequest();
  +            } catch (IOException e) {
  +                ok = false;
  +            } catch (Throwable t) {
  +                // Problem ...
  +                ok = false;
  +            }
   
  +            // FIXME: Next request
   
  -
  -        try {
  -            adapter.service(request, response);
  -        } catch (Exception e) {
  -            ;
           }
  -
  -
   
  +        // FIXME: Recycle
   
       }
   
  
  
  
  1.3       +6 -0      jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InputFilter.java
  
  Index: InputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InputFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InputFilter.java	2001/09/17 21:27:31	1.2
  +++ InputFilter.java	2001/12/03 06:09:30	1.3
  @@ -107,4 +107,10 @@
       public ByteChunk getEncodingName();
   
   
  +    /**
  +     * Set the next buffer in the filter pipeline.
  +     */
  +    public void setBuffer(InputBuffer buffer);
  +
  +
   }
  
  
  
  1.2       +51 -26    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java
  
  Index: InternalInputBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InternalInputBuffer.java	2001/09/17 06:04:00	1.1
  +++ InternalInputBuffer.java	2001/12/03 06:09:30	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
1.1 2001/09/17 06:04:00 remm Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/09/17 06:04:00 $
  + * $Header: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
1.2 2001/12/03 06:09:30 remm Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/12/03 06:09:30 $
    *
    * ====================================================================
    *
  @@ -111,6 +111,8 @@
           headerBuffer2 = new byte[headerBufferSize];
           bodyBuffer = new byte[headerBufferSize];
   
  +        inputStreamInputBuffer = new InputStreamInputBuffer();
  +
           filterLibrary = new InputFilter[0];
           activeFilters = new InputFilter[0];
   
  @@ -193,6 +195,12 @@
   
   
       /**
  +     * Underlying input buffer.
  +     */
  +    protected InputBuffer inputStreamInputBuffer;
  +
  +
  +    /**
        * Filter library.
        * Note: Filter[0] is always the "chunked" filter.
        */
  @@ -285,7 +293,13 @@
           // FIXME: Check for null ?
           // FIXME: Check index ?
   
  -        activeFilters[lastActiveFilter++] = filter;
  +        if (lastActiveFilter == 0) {
  +            filter.setBuffer(inputStreamInputBuffer);
  +        } else {
  +            filter.setBuffer(activeFilters[lastActiveFilter]);
  +        }
  +
  +        activeFilters[++lastActiveFilter] = filter;
   
       }
   
  @@ -655,29 +669,8 @@
        */
       public int doRead(ByteChunk chunk) 
           throws IOException {
  -
  -        if (pos >= lastValid) {
  -            if (!fill())
  -                return -1;
  -        }
  -
  -        chunk.setBytes(buf, pos, lastValid - pos);
  -
  -        int n = -1;
  -
  -        if (lastActiveFilter > 0) {
  -            // Parsing through the filter list
  -            for (int i = 0; i < lastActiveFilter; i++) {
  -                int nRead = activeFilters[i].doRead(chunk);
  -                if ((n < 0) && (nRead >= 0)) {
  -                    n = nRead;
  -                }
  -            }
  -        }
  -
  -        pos = pos + n;
   
  -        return n;
  +        return activeFilters[lastActiveFilter].doRead(chunk);
   
       }
   
  @@ -720,6 +713,38 @@
           }
   
           return (nRead >= 0);
  +
  +    }
  +
  +
  +    // ------------------------------------- InputStreamInputBuffer Inner Class
  +
  +
  +    /**
  +     * This class is an input buffer which will read its data from an input
  +     * stream.
  +     */
  +    protected class InputStreamInputBuffer 
  +        implements InputBuffer {
  +
  +
  +        /**
  +         * Read bytes into the specified chunk.
  +         */
  +        public int doRead(ByteChunk chunk) 
  +            throws IOException {
  +
  +            if (pos >= lastValid) {
  +                if (!fill())
  +                    return -1;
  +            }
  +
  +            chunk.setBytes(buf, pos, lastValid - pos);
  +
  +            return (lastValid - pos);
  +
  +        }
  +
   
       }
   
  
  
  
  1.3       +44 -36    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
  
  Index: InternalOutputBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InternalOutputBuffer.java	2001/10/01 01:20:42	1.2
  +++ InternalOutputBuffer.java	2001/12/03 06:09:30	1.3
  @@ -105,6 +105,8 @@
           headerBuffer = new byte[headerBufferSize];
           buf = headerBuffer;
   
  +        outputStreamOutputBuffer = new OutputStreamOutputBuffer();
  +
           filterLibrary = new OutputFilter[0];
           activeFilters = new OutputFilter[0];
   
  @@ -169,6 +171,12 @@
   
   
       /**
  +     * Underlying output buffer.
  +     */
  +    protected OutputBuffer outputStreamOutputBuffer;
  +
  +
  +    /**
        * Filter library.
        * Note: Filter[0] is always the "chunked" filter.
        */
  @@ -176,7 +184,7 @@
   
   
       /**
  -     * Active filters (in order).
  +     * Active filter (which is actually the top of the pipeline).
        */
       protected OutputFilter[] activeFilters;
   
  @@ -187,12 +195,6 @@
       protected int lastActiveFilter;
   
   
  -    /**
  -     * Chunk used when closing the response.
  -     */
  -    protected ByteChunk closeChunk = new ByteChunk(4096);
  -
  -
       // ------------------------------------------------------------- Properties
   
   
  @@ -266,8 +268,14 @@
   
           // FIXME: Check for null ?
           // FIXME: Check index ?
  +
  +        if (lastActiveFilter == 0) {
  +            filter.setBuffer(outputStreamOutputBuffer);
  +        } else {
  +            filter.setBuffer(activeFilters[lastActiveFilter]);
  +        }
   
  -        activeFilters[lastActiveFilter++] = filter;
  +        activeFilters[++lastActiveFilter] = filter;
   
       }
   
  @@ -288,7 +296,6 @@
           pos = 0;
           lastActiveFilter = 0;
           committed = false;
  -        closeChunk.recycle();
   
       }
   
  @@ -317,7 +324,6 @@
           pos = 0;
           lastActiveFilter = 0;
           committed = false;
  -        closeChunk.recycle();
   
       }
   
  @@ -341,19 +347,6 @@
   
           }
   
  -        if (lastActiveFilter > 0) {
  -            // Parsing through the filter list
  -            for (int i = 0; i < lastActiveFilter; i++) {
  -                activeFilters[i].close(closeChunk);
  -            }
  -        }
  -
  -        if (closeChunk.getLength() > 0) {
  -            outputStream.write(closeChunk.getBytes(), closeChunk.getStart(), 
  -                               closeChunk.getLength());
  -            outputStream.flush();
  -        }
  -
       }
   
   
  @@ -474,21 +467,9 @@
               commit();
   
           }
  -
  -        int n = -1;
  -
  -        if (lastActiveFilter > 0) {
  -            // Parsing through the filter list
  -            for (int i = 0; i < lastActiveFilter; i++) {
  -                n = activeFilters[i].doWrite(chunk);
  -            }
  -        }
   
  -        outputStream.write(chunk.getBytes(), chunk.getStart(), 
  -                           chunk.getLength());
  +        return activeFilters[lastActiveFilter].doWrite(chunk);
   
  -        return n;
  -
       }
   
   
  @@ -593,6 +574,33 @@
       protected void write(int i) {
   
           write(String.valueOf(i));
  +
  +    }
  +
  +
  +    // ----------------------------------- OutputStreamOutputBuffer Inner Class
  +
  +
  +    /**
  +     * This class is an output buffer which will write data to an output
  +     * stream.
  +     */
  +    protected class OutputStreamOutputBuffer 
  +        implements OutputBuffer {
  +
  +
  +        /**
  +         * Write chunk.
  +         */
  +        public int doWrite(ByteChunk chunk) 
  +            throws IOException {
  +
  +            outputStream.write(chunk.getBuffer(), chunk.getStart(), 
  +                               chunk.getLength());
  +            return chunk.getLength();
  +
  +        }
  +
   
       }
   
  
  
  
  1.3       +14 -4     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/OutputFilter.java
  
  Index: OutputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/OutputFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OutputFilter.java	2001/09/17 21:27:31	1.2
  +++ OutputFilter.java	2001/12/03 06:09:30	1.3
  @@ -94,15 +94,19 @@
       /**
        * Flush the internal buffer of the filter (if any).
        */
  -    public int flush(ByteChunk chunk)
  -        throws IOException;
  +    /*
  +      public int flush(ByteChunk chunk)
  +      throws IOException;
  +    */
   
   
       /**
        * Called when ending the request.
        */
  -    public int close(ByteChunk chunk)
  -        throws IOException;
  +    /*
  +      public int close(ByteChunk chunk)
  +      throws IOException;
  +    */
   
   
       /**
  @@ -115,6 +119,12 @@
        * Get the name of the encoding handled by this filter.
        */
       public ByteChunk getEncodingName();
  +
  +
  +    /**
  +     * Set the next buffer in the filter pipeline.
  +     */
  +    public void setBuffer(OutputBuffer buffer);
   
   
   }
  
  
  
  1.2       +16 -0     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
  
  Index: IdentityInputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IdentityInputFilter.java	2001/09/17 21:27:32	1.1
  +++ IdentityInputFilter.java	2001/12/03 06:09:30	1.2
  @@ -105,6 +105,12 @@
       protected long remaining = -1;
   
   
  +    /**
  +     * Next buffer in the pipeline.
  +     */
  +    protected InputBuffer buffer;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -139,6 +145,8 @@
       public int doRead(ByteChunk chunk)
           throws IOException {
   
  +        buffer.doRead(chunk);
  +
           int result = chunk.getLength();
   
           if (result <= 0) {
  @@ -182,6 +190,14 @@
       public void setRequest(Request request) {
           contentLength = request.getContentLength();
           remaining = contentLength;
  +    }
  +
  +
  +    /**
  +     * Set the next buffer in the filter pipeline.
  +     */
  +    public void setBuffer(InputBuffer buffer) {
  +        this.buffer = buffer;
       }
   
   
  
  
  
  1.2       +20 -0     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java
  
  Index: IdentityOutputFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IdentityOutputFilter.java	2001/09/17 21:27:32	1.1
  +++ IdentityOutputFilter.java	2001/12/03 06:09:30	1.2
  @@ -105,6 +105,12 @@
       protected long remaining = -1;
   
   
  +    /**
  +     * Next buffer in the pipeline.
  +     */
  +    protected OutputBuffer buffer;
  +
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -162,6 +168,8 @@
               }
           }
   
  +        buffer.doWrite(chunk);
  +
           return result;
   
       }
  @@ -181,18 +189,29 @@
   
   
       /**
  +     * Set the next buffer in the filter pipeline.
  +     */
  +    public void setBuffer(OutputBuffer buffer) {
  +        this.buffer = buffer;
  +    }
  +
  +
  +    /**
        * Don't do anything in particular when flushing.
        */
  +    /*
       public int flush(ByteChunk chunk)
           throws IOException {
           return doWrite(chunk);
       }
  +    */
   
   
       /**
        * Write the remaining bytes, and check that the number of bytes written
        * is correct.
        */
  +    /*
       public int close(ByteChunk chunk)
           throws IOException {
   
  @@ -207,6 +226,7 @@
           return n;
   
       }
  +    */
   
   
       /**
  
  
  

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


Mime
View raw message