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-4.0/webapps/examples/WEB-INF/classes/compressionFilters CompressionFilter.java CompressionResponseStream.java CompressionServletResponseWrapper.java
Date Thu, 06 Sep 2001 23:05:08 GMT
remm        01/09/06 16:05:08

  Modified:    webapps/examples/WEB-INF/classes/compressionFilters
                        CompressionFilter.java
                        CompressionResponseStream.java
                        CompressionServletResponseWrapper.java
  Log:
  - Fixes various issues with the compression filter, including:
    - don't set content length (fixes problems with static content)
    - close the writer retrieved with getWriter()
    - remove some unnecessary flushes
  - The filter could still be improved in a lot of ways, including:
    - being smarter with the content length (it could be set when not in
      compression mode)
    - only compress text data (I don't think that is implemented at the moment)
  
  Revision  Changes    Path
  1.5       +9 -5      jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java
  
  Index: CompressionFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CompressionFilter.java	2001/09/06 04:18:53	1.4
  +++ CompressionFilter.java	2001/09/06 23:05:08	1.5
  @@ -1,8 +1,8 @@
   /*
    * CompressionFilter.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
1.4 2001/09/06 04:18:53 amyroh Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/09/06 04:18:53 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionFilter.java,v
1.5 2001/09/06 23:05:08 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2001/09/06 23:05:08 $
    *
    * ====================================================================
    *
  @@ -80,7 +80,7 @@
    * the ServletResponse if it is bigger than a threshold.
    *
    * @author Amy Roh
  - * @version $Revision: 1.4 $, $Date: 2001/09/06 04:18:53 $
  + * @version $Revision: 1.5 $, $Date: 2001/09/06 23:05:08 $
    */
   
   public class CompressionFilter implements Filter{
  @@ -194,7 +194,11 @@
                   if (debug > 0) {
                       System.out.println("doFilter gets called with compression");
                   }
  -                chain.doFilter(request, wrappedResponse);
  +                try {
  +                    chain.doFilter(request, wrappedResponse);
  +                } finally {
  +                    wrappedResponse.finishResponse();
  +                }
                   return;
               }
           }
  
  
  
  1.4       +17 -20    jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java
  
  Index: CompressionResponseStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CompressionResponseStream.java	2001/09/06 04:18:54	1.3
  +++ CompressionResponseStream.java	2001/09/06 23:05:08	1.4
  @@ -1,8 +1,8 @@
   /*
    * CompressionResponseStream.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
1.3 2001/09/06 04:18:54 amyroh Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/06 04:18:54 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionResponseStream.java,v
1.4 2001/09/06 23:05:08 remm Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/09/06 23:05:08 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * the CompressionServletResponseWrapper implementation.
    *
    * @author Amy Roh
  - * @version $Revision: 1.3 $, $Date: 2001/09/06 04:18:54 $
  + * @version $Revision: 1.4 $, $Date: 2001/09/06 23:05:08 $
    */
   
   public class CompressionResponseStream
  @@ -177,17 +177,22 @@
        */
       public void close() throws IOException {
   
  +        //System.out.println("close() @ CompressionResponseStream");
           if (closed)
  -	        throw new IOException("This output stream has already been closed");
  +            throw new IOException("This output stream has already been closed");
   
  -        flush();
  -
  -        if (gzipstream!=null) {
  +        if (gzipstream != null) {
  +            flushToGZip();
               gzipstream.close();
  +        } else {
  +            if (bufferCount > 0) {
  +                output.write(buffer, 0, bufferCount);
  +                bufferCount = 0;
  +            }
           }
   
           output.close();
  -	    closed = true;
  +        closed = true;
   
       }
   
  @@ -203,12 +208,6 @@
               throw new IOException("Cannot flush a closed output stream");
           }
   
  -        if (bufferCount > 0) {
  -            //System.out.println("writing to original stream");
  -            output.write(buffer, 0, bufferCount);
  -            bufferCount = 0;
  -        }
  -
           if (gzipstream!=null) {
               gzipstream.flush();
           }
  @@ -247,8 +246,8 @@
           if (compressionThresholdReached) {
               writeToGZip(b);
           } else {
  -	        buffer[bufferCount++] = (byte) b;
  -	        count++;
  +            buffer[bufferCount++] = (byte) b;
  +            count++;
           }
   
       }
  @@ -267,7 +266,6 @@
           //System.out.println("writeToGZip (int b) compressing");
           if (gzipstream == null) {
               gzipstream = new GZIPOutputStream(output);
  -            flushToGZip();
               response.addHeader("Content-Encoding", "gzip");
           }
           gzipstream.write(b);
  @@ -312,7 +310,7 @@
               bufferCount += len;
               count += len;
               return;
  -	    }
  +        }
   
           // buffer full, start writing to gzipstream
   
  @@ -326,7 +324,6 @@
           //System.out.println("writeToGZip 2 compressing");
           if (gzipstream == null) {
               gzipstream = new GZIPOutputStream(output);
  -            flushToGZip();
               response.addHeader("Content-Encoding", "gzip");
           }
           gzipstream.write(b, off, len);
  
  
  
  1.4       +23 -4     jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java
  
  Index: CompressionServletResponseWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CompressionServletResponseWrapper.java	2001/09/06 04:18:54	1.3
  +++ CompressionServletResponseWrapper.java	2001/09/06 23:05:08	1.4
  @@ -1,8 +1,8 @@
   /*
    * CompressionServletResponseWrapper.java
  - * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
1.3 2001/09/06 04:18:54 amyroh Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/06 04:18:54 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/compressionFilters/CompressionServletResponseWrapper.java,v
1.4 2001/09/06 23:05:08 remm Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/09/06 23:05:08 $
    *
    * ====================================================================
    *
  @@ -83,7 +83,7 @@
    * the CompressionServletResponseStream implementation..
    *
    * @author Amy Roh
  - * @version $Revision: 1.3 $, $Date: 2001/09/06 04:18:54 $
  + * @version $Revision: 1.4 $, $Date: 2001/09/06 23:05:08 $
    */
   
   public class CompressionServletResponseWrapper extends HttpServletResponseWrapper {
  @@ -162,6 +162,21 @@
       }
   
   
  +    /**
  +     * Finish a response.
  +     */
  +    public void finishResponse() {
  +        try {
  +            if (writer != null) {
  +                writer.close();
  +            } else {
  +                if (stream != null)
  +                    stream.close();
  +            }
  +        } catch (IOException e) {
  +        }
  +    }
  +
   
       // ------------------------------------------------ ServletResponse Methods
   
  @@ -219,6 +234,10 @@
           writer = new PrintWriter(stream);
           return (writer);
   
  +    }
  +
  +
  +    public void setContentLength(int length) {
       }
   
   }
  
  
  

Mime
View raw message