cziegeler    01/07/12 03:23:46

  Modified:    src/org/apache/cocoon/components/pipeline
                        AbstractStreamPipeline.java
                        CachingStreamPipeline.java
               src/org/apache/cocoon/reading AbstractReader.java
                        DatabaseReader.java Reader.java ResourceReader.java
               src/org/apache/cocoon/serialization AbstractSerializer.java
                        FOPSerializer.java LinkSerializer.java
                        SVGSerializer.java
               src/org/apache/cocoon/sitemap SitemapOutputComponent.java
  Log:
  Fixed content length problem:
  The SitemapOutputComponent is asked if the content length should be set.
  If it returns true, the stream pipeline records the response into
  an byte array, sets the proper content length and writes the array
  to the output.
  Currently the FOPSerializer and the ResourceReader return true.
  
  Revision  Changes    Path
  1.7       +28 -6     
xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractStreamPipeline.java
  
  Index: AbstractStreamPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractStreamPipeline.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractStreamPipeline.java       2001/07/07 11:43:23     1.6
  +++ AbstractStreamPipeline.java       2001/07/12 10:23:04     1.7
  @@ -7,6 +7,7 @@
    *****************************************************************************/
   package org.apache.cocoon.components.pipeline;
   
  +import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.OutputStream;
   import org.apache.avalon.framework.activity.Disposable;
  @@ -33,7 +34,8 @@
    * resource
    * </UL>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2001/07/07 11:43:23 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.7 $ $Date: 2001/07/12 10:23:04 $
    */
   public abstract class AbstractStreamPipeline extends AbstractLoggable implements 
StreamPipeline, Disposable {
       protected EventPipeline eventPipeline;
  @@ -125,9 +127,23 @@
               setupPipeline(environment);
               connectPipeline();
   
  -            // execute the pipeline:
               try {
  -                this.eventPipeline.process(environment);
  +                if (this.serializer.shouldSetContentLength() == true) {
  +                    // set the output stream
  +                    ByteArrayOutputStream os = new ByteArrayOutputStream();
  +                    this.serializer.setOutputStream(os);
  +
  +                    // execute the pipeline:
  +                    this.eventPipeline.process(environment);
  +                    byte[] data = os.toByteArray();
  +                    environment.setContentLength(data.length);
  +                    environment.getOutputStream().write(data);
  +                } else {
  +                    // set the output stream
  +                    this.serializer.setOutputStream(environment.getOutputStream());
  +                    // execute the pipeline:
  +                    this.eventPipeline.process(environment);
  +                }
               } catch ( ProcessingException e ) {
                   throw e;
               } catch ( Exception e ) {
  @@ -167,10 +183,16 @@
                   return true;
               }
   
  +            if (this.reader.shouldSetContentLength() == true) {
  +                ByteArrayOutputStream os = new ByteArrayOutputStream();
  +                this.reader.setOutputStream(os);
  +                this.reader.generate();
  +                byte[] data = os.toByteArray();
  +                environment.setContentLength(data.length);
  +                environment.getOutputStream().write(data);
  +            } else {
               this.reader.setOutputStream(environment.getOutputStream());
  -            int length = this.reader.generate();
  -            if (length != 0) {
  -                environment.setContentLength(length);
  +                this.reader.generate();
               }
           } catch ( Exception e ) {
               throw new ProcessingException("Error reading resource",e);
  
  
  
  1.8       +28 -9     
xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingStreamPipeline.java
  
  Index: CachingStreamPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingStreamPipeline.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CachingStreamPipeline.java        2001/07/07 11:43:23     1.7
  +++ CachingStreamPipeline.java        2001/07/12 10:23:06     1.8
  @@ -7,6 +7,7 @@
    *****************************************************************************/
   package org.apache.cocoon.components.pipeline;
   
  +import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.OutputStream;
   import java.net.SocketException;
  @@ -44,7 +45,7 @@
    *  </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/07/07 11:43:23 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/07/12 10:23:06 $
    */
   public class CachingStreamPipeline extends AbstractStreamPipeline {
   
  @@ -200,10 +201,16 @@
   
               if (usedCache == false) {
   
  -                this.reader.setOutputStream(outputStream);
  -                int length = this.reader.generate();
  -                if (length != 0) {
  -                    environment.setContentLength(length);
  +                if (this.reader.shouldSetContentLength() == true) {
  +                    ByteArrayOutputStream os = new ByteArrayOutputStream();
  +                    this.reader.setOutputStream(os);
  +                    this.reader.generate();
  +                    byte[] data = os.toByteArray();
  +                    environment.setContentLength(data.length);
  +                    outputStream.write(data);
  +                } else {
  +                    this.reader.setOutputStream(outputStream);
  +                    this.reader.generate();
                   }
   
                   // store the response
  @@ -336,11 +343,23 @@
   
                   if (usedCache == false) {
   
  -                    // set the output stream
  -                    this.serializer.setOutputStream(outputStream);
  +                    if (this.serializer.shouldSetContentLength() == true) {
  +                        // set the output stream
  +                        ByteArrayOutputStream os = new ByteArrayOutputStream();
  +                        this.serializer.setOutputStream(os);
  +
  +                        // execute the pipeline:
  +                        this.eventPipeline.process(environment);
  +                        byte[] data = os.toByteArray();
  +                        environment.setContentLength(data.length);
  +                        outputStream.write(data);
  +                   } else {
  +                        // set the output stream
  +                        this.serializer.setOutputStream(outputStream);
   
  -                    // execute the pipeline:
  -                    this.eventPipeline.process(environment);
  +                        // execute the pipeline:
  +                        this.eventPipeline.process(environment);
  +                    }
   
                       // store the response
                       if (pcKey != null) {
  
  
  
  1.3       +9 -1      xml-cocoon2/src/org/apache/cocoon/reading/AbstractReader.java
  
  Index: AbstractReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/reading/AbstractReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractReader.java       2001/05/22 14:43:33     1.2
  +++ AbstractReader.java       2001/07/12 10:23:13     1.3
  @@ -21,7 +21,7 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/05/22 14:43:33 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/07/12 10:23:13 $
    */
   public abstract class AbstractReader extends AbstractLoggable implements Reader, 
Recyclable {
       /** The current <code>SourceResolver</code>. */
  @@ -81,4 +81,12 @@
           this.parameters = null;
           this.objectModel = null;
       }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return false;
  +    }
  +
   }
  
  
  
  1.4       +3 -10     xml-cocoon2/src/org/apache/cocoon/reading/DatabaseReader.java
  
  Index: DatabaseReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/reading/DatabaseReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatabaseReader.java       2001/07/07 11:43:33     1.3
  +++ DatabaseReader.java       2001/07/12 10:23:15     1.4
  @@ -149,12 +149,10 @@
        * Lastly, the <code>key</code> value is derived from the value of
        * the <code>source</code> string.
        */
  -    public int generate() throws ProcessingException, SAXException, IOException {
  -        int contentLength = 0;
  -
  +    public void generate() throws ProcessingException, SAXException, IOException {
           try {
               Response response = (Response) 
objectModel.get(Constants.RESPONSE_OBJECT);
  -            return this.serialize(response);
  +            this.serialize(response);
           } catch (IOException ioe) {
               getLogger().debug("Assuming client reset stream");
   
  @@ -166,8 +164,6 @@
   
               throw new ResourceNotFoundException("DatabaseReader error:", e);
           }
  -
  -        return contentLength; // length is unknown
       }
   
       /**
  @@ -232,7 +228,7 @@
       /**
        * This method actually performs the serialization.
        */
  -    public int serialize(Response response)
  +    public void serialize(Response response)
       throws IOException, SQLException {
           if (this.resource == null) {
               throw new SQLException("The Blob is empty!");
  @@ -240,7 +236,6 @@
   
           InputStream is = new BufferedInputStream(this.resource.getBinaryStream());
   
  -        int contentLength = (int) this.resource.length();
           long expires = parameters.getParameterAsInteger("expires", -1);
   
           if (expires > 0) {
  @@ -257,8 +252,6 @@
           }
           is.close();
           out.flush();
  -
  -        return contentLength;
       }
   
       /**
  
  
  
  1.3       +3 -2      xml-cocoon2/src/org/apache/cocoon/reading/Reader.java
  
  Index: Reader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/reading/Reader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Reader.java       2001/07/07 11:43:33     1.2
  +++ Reader.java       2001/07/12 10:23:16     1.3
  @@ -16,17 +16,18 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/07/07 11:43:33 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/07/12 10:23:16 $
    */
   public interface Reader extends SitemapModelComponent, SitemapOutputComponent {
   
       String ROLE = "org.apache.cocoon.reading.Reader";
  +
       /**
        * Generate the response.
        * @return The length of the response or <code>0</code> if the length
        * is unknown.
        */
  -    int generate()
  +    void generate()
       throws IOException, SAXException, ProcessingException;
   
       /**
  
  
  
  1.5       +10 -5     xml-cocoon2/src/org/apache/cocoon/reading/ResourceReader.java
  
  Index: ResourceReader.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/reading/ResourceReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ResourceReader.java       2001/07/07 11:43:33     1.4
  +++ ResourceReader.java       2001/07/12 10:23:17     1.5
  @@ -42,7 +42,7 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/07/07 11:43:33 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/07/12 10:23:17 $
    *
    * The <code>ResourceReader</code> component is used to serve binary data
    * in a sitemap pipeline. It makes use of HTTP Headers to determine if
  @@ -118,11 +118,9 @@
       /**
        * Generates the requested resource.
        */
  -    public int generate() throws IOException, ProcessingException {
  +    public void generate() throws IOException, ProcessingException {
           Response response = (Response) objectModel.get(Constants.RESPONSE_OBJECT);
   
  -        long contentLength = this.inputSource.getContentLength();
  -
           try {
               long expires = parameters.getParameterAsInteger("expires", -1);
   
  @@ -145,7 +143,6 @@
           } catch (IOException ioe) {
               getLogger().debug("Received an IOException, assuming client severed 
connection on purpose");
           }
  -        return (int)contentLength;
       }
   
       /**
  @@ -160,4 +157,12 @@
              return null;
           }
       }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return (this.inputSource.getContentLength() != -1);
  +    }
  +
   }
  
  
  
  1.3       +9 -1      
xml-cocoon2/src/org/apache/cocoon/serialization/AbstractSerializer.java
  
  Index: AbstractSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/serialization/AbstractSerializer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractSerializer.java   2001/05/22 14:44:41     1.2
  +++ AbstractSerializer.java   2001/07/12 10:23:26     1.3
  @@ -22,7 +22,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/05/22 14:44:41 $
  + * @version CVS $Revision: 1.3 $ $Date: 2001/07/12 10:23:26 $
    */
   
   public abstract class AbstractSerializer extends AbstractXMLPipe implements 
Serializer, Recyclable {
  @@ -55,4 +55,12 @@
           super.recycle();
           this.output = null;
       }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return false;
  +    }
  +
   }
  
  
  
  1.2       +8 -1      
xml-cocoon2/src/org/apache/cocoon/serialization/FOPSerializer.java
  
  Index: FOPSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/serialization/FOPSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FOPSerializer.java        2001/05/09 20:49:38     1.1
  +++ FOPSerializer.java        2001/07/12 10:23:29     1.2
  @@ -37,7 +37,7 @@
    *         (PWR Organisation &amp; Entwicklung)
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/07/12 10:23:29 $
    *
    * The use of a config file for FOP is enabled by adding a configuration
    * element to the serializer in the sitemap.
  @@ -180,6 +180,13 @@
           MessageHandler.removeListener(this);
           this.options = null;
           this.driver = null;
  +    }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return true;
       }
   
   }
  
  
  
  1.2       +9 -1      
xml-cocoon2/src/org/apache/cocoon/serialization/LinkSerializer.java
  
  Index: LinkSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/serialization/LinkSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LinkSerializer.java       2001/05/09 20:49:38     1.1
  +++ LinkSerializer.java       2001/07/12 10:23:30     1.2
  @@ -23,7 +23,7 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/07/12 10:23:30 $
    */
   
   public class LinkSerializer extends ExtendedXLinkPipe implements Serializer, 
Poolable {
  @@ -60,4 +60,12 @@
           if (href.indexOf("://") != -1) return false;
           return true;
       }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return false;
  +    }
  +
   }
  
  
  
  1.2       +9 -1      
xml-cocoon2/src/org/apache/cocoon/serialization/SVGSerializer.java
  
  Index: SVGSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/serialization/SVGSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVGSerializer.java        2001/05/09 20:49:38     1.1
  +++ SVGSerializer.java        2001/07/12 10:23:31     1.2
  @@ -42,7 +42,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Davanum Srinivas</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ross Burton</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/07/12 10:23:31 $
    */
   public class SVGSerializer extends SVGBuilder
           implements Composable, Serializer, Configurable, Poolable, Cacheable {
  @@ -245,4 +245,12 @@
       public CacheValidity generateValidity() {
           return new NOPCacheValidity();
       }
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    public boolean shouldSetContentLength() {
  +        return false;
  +    }
  +
   }
  
  
  
  1.3       +7 -1      
xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapOutputComponent.java
  
  Index: SitemapOutputComponent.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/sitemap/SitemapOutputComponent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SitemapOutputComponent.java       2001/06/08 20:28:27     1.2
  +++ SitemapOutputComponent.java       2001/07/12 10:23:40     1.3
  @@ -15,7 +15,8 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.2 $ $Date: 2001/06/08 20:28:27 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.3 $ $Date: 2001/07/12 10:23:40 $
    */
   public interface SitemapOutputComponent extends Component {
       /**
  @@ -28,4 +29,9 @@
        * Get the mime-type of the output of this <code>Component</code>.
        */
       String getMimeType();
  +
  +    /**
  +     * Test if the component wants to set the content length
  +     */
  +    boolean shouldSetContentLength();
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to