remm 01/09/17 14:27:32 Modified: http11/src/java/org/apache/coyote/http11 InputFilter.java OutputFilter.java Added: http11/src/java/org/apache/coyote/http11/filters IdentityInputFilter.java IdentityOutputFilter.java Log: - Some modifications to the filters. - Add I/O filters for the "identity" transfer encoding. Revision Changes Path 1.2 +12 -12 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InputFilter.java 2001/09/17 06:04:00 1.1 +++ InputFilter.java 2001/09/17 21:27:31 1.2 @@ -67,11 +67,11 @@ import org.apache.coyote.Request; /** - * Identity input filter. + * Input filter interface. * * @author Remy Maucherat */ -public class InputFilter implements InputBuffer { +public interface InputFilter extends InputBuffer { /** @@ -84,9 +84,7 @@ * control, the returned value should be -1. */ public int doRead(ByteChunk chunk) - throws IOException { - return chunk.getLength(); - } + throws IOException; /** @@ -94,17 +92,19 @@ * necessary reading can occur in that method, as this method is called * after the request header processing is complete. */ - public void setRequest(Request request) { - } + public void setRequest(Request request); - public void recycle() { - } + /** + * Make the filter ready to process the next request. + */ + public void recycle(); - public String getEncodingName() { - return "identity"; - } + /** + * Get the name of the encoding handled by this filter. + */ + public ByteChunk getEncodingName(); } 1.2 +25 -18 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- OutputFilter.java 2001/09/17 06:04:00 1.1 +++ OutputFilter.java 2001/09/17 21:27:31 1.2 @@ -67,17 +67,20 @@ import org.apache.coyote.Response; /** - * Identity output filter. + * Output filter. * * @author Remy Maucherat */ -public class OutputFilter implements OutputBuffer { +public interface OutputFilter extends OutputBuffer { + /** + * Write some bytes. + * + * @return number of bytes written by the filter + */ public int doWrite(ByteChunk chunk) - throws IOException { - return chunk.getLength(); - } + throws IOException; /** @@ -85,29 +88,33 @@ * necessary reading can occur in that method, as this method is called * after the response header processing is complete. */ - public void setResponse(Response response) { - } + public void setResponse(Response response); + /** + * Flush the internal buffer of the filter (if any). + */ public int flush(ByteChunk chunk) - throws IOException { - return 0; - } + throws IOException; + /** + * Called when ending the request. + */ public int close(ByteChunk chunk) - throws IOException { - return 0; - } + throws IOException; - public void recycle() { - } + /** + * Make the filter ready to process the next request. + */ + public void recycle(); - public String getEncodingName() { - return "identity"; - } + /** + * Get the name of the encoding handled by this filter. + */ + public ByteChunk getEncodingName(); } 1.1 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityInputFilter.java Index: IdentityInputFilter.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.coyote.http11.filters; import java.io.IOException; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.coyote.InputBuffer; import org.apache.coyote.Request; import org.apache.coyote.http11.InputFilter; /** * Identity input filter. * * @author Remy Maucherat */ public class IdentityInputFilter implements InputBuffer { // -------------------------------------------------------------- Constants protected static final String ENCODING_NAME = "identity"; protected static final ByteChunk ENCODING = new ByteChunk(); // ----------------------------------------------------- Static Initializer static { ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length()); } // ----------------------------------------------------- Instance Variables /** * Content length. */ protected long contentLength = -1; /** * Remaining bytes. */ protected long remaining = -1; // ------------------------------------------------------------- Properties /** * Get content length. */ public long getContentLength() { return contentLength; } /** * Get remaining bytes. */ public long getRemaining() { return remaining; } // ---------------------------------------------------- InputBuffer Methods /** * Read bytes. * * @return If the filter does request length control, this value is * significant; it should be the number of bytes consumed from the buffer, * up until the end of the current request body, or the buffer length, * whichever is greater. If the filter does not do request body length * control, the returned value should be -1. */ public int doRead(ByteChunk chunk) throws IOException { int result = chunk.getLength(); if (result <= 0) { return -1; } if (contentLength > 0) { if (remaining > 0) { if (chunk.getLength() > remaining) { // The chunk is longer than the number of bytes remaining // in the body; changing the chunk length to the number // of bytes remaining chunk.setBytes(chunk.getBytes(), chunk.getStart(), (int) remaining); result = (int) remaining; remaining = -1; } else { remaining = remaining - result; } } else { // No more bytes left to be read : return -1 and clear the // buffer chunk.recycle(); result = -1; } } else { result = -1; } return result; } // ---------------------------------------------------- InputFilter Methods /** * Read the content length from the request. */ public void setRequest(Request request) { contentLength = request.getContentLength(); remaining = contentLength; } /** * Make the filter ready to process the next request. */ public void recycle() { contentLength = -1; remaining = -1; } /** * Return the name of the associated encoding; Here, the value is * "identity". */ public ByteChunk getEncodingName() { return ENCODING; } } 1.1 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/filters/IdentityOutputFilter.java Index: IdentityOutputFilter.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.coyote.http11.filters; import java.io.IOException; import org.apache.tomcat.util.buf.ByteChunk; import org.apache.coyote.OutputBuffer; import org.apache.coyote.Response; import org.apache.coyote.http11.OutputFilter; /** * Identity output filter. * * @author Remy Maucherat */ public class IdentityOutputFilter implements OutputFilter { // -------------------------------------------------------------- Constants protected static final String ENCODING_NAME = "identity"; protected static final ByteChunk ENCODING = new ByteChunk(); // ----------------------------------------------------- Static Initializer static { ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length()); } // ----------------------------------------------------- Instance Variables /** * Content length. */ protected long contentLength = -1; /** * Remaining bytes. */ protected long remaining = -1; // ------------------------------------------------------------- Properties /** * Get content length. */ public long getContentLength() { return contentLength; } /** * Get remaining bytes. */ public long getRemaining() { return remaining; } // --------------------------------------------------- OutputBuffer Methods /** * Write some bytes. * * @return number of bytes written by the filter */ public int doWrite(ByteChunk chunk) throws IOException { int result = chunk.getLength(); if (result <= 0) { return -1; } if (contentLength > 0) { if (remaining > 0) { if (chunk.getLength() > remaining) { // The chunk is longer than the number of bytes remaining // in the body; changing the chunk length to the number // of bytes remaining chunk.setBytes(chunk.getBytes(), chunk.getStart(), (int) remaining); result = (int) remaining; remaining = -1; } else { remaining = remaining - result; } } else { // No more bytes left to be written : return -1 and clear the // buffer chunk.recycle(); result = -1; } } return result; } // --------------------------------------------------- OutputFilter Methods /** * Some filters need additional parameters from the response. All the * necessary reading can occur in that method, as this method is called * after the response header processing is complete. */ public void setResponse(Response response) { contentLength = response.getContentLength(); } /** * 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 { int n = doWrite(chunk); if (remaining > 0) { // FIXME: Throw an exception if the number of bytes written is less // than the advertised content length. throw new IOException(); } return n; } /** * Make the filter ready to process the next request. */ public void recycle() { contentLength = -1; remaining = -1; } /** * Return the name of the associated encoding; Here, the value is * "identity". */ public ByteChunk getEncodingName() { return ENCODING; } }