cziegeler    01/07/12 03:30:07

  Modified:    src/org/apache/cocoon/components/pipeline Tag:
                        cocoon_20_branch AbstractStreamPipeline.java
                        CachingStreamPipeline.java
               src/org/apache/cocoon/reading Tag: cocoon_20_branch
                        AbstractReader.java DatabaseReader.java Reader.java
                        ResourceReader.java
               src/org/apache/cocoon/serialization Tag: cocoon_20_branch
                        AbstractSerializer.java FOPSerializer.java
                        LinkSerializer.java SVGSerializer.java
               src/org/apache/cocoon/sitemap Tag: cocoon_20_branch
                        SitemapOutputComponent.java
  Log:
  Fixed the content length problem.
  The SitemapOutputComponent is asked if the content length must be set.
  If it returns true the StreamPipeline records the response to a
  byte array, sets the content length and writes then the byte array
  to the output.
  Currently the ResourceReader and the FOPSerializer return true.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.6   +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.3.2.5
  retrieving revision 1.3.2.6
  diff -u -r1.3.2.5 -r1.3.2.6
  --- AbstractStreamPipeline.java       2001/07/07 19:08:01     1.3.2.5
  +++ AbstractStreamPipeline.java       2001/07/12 10:29:37     1.3.2.6
  @@ -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.3.2.5 $ $Date: 2001/07/07 19:08:01 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.3.2.6 $ $Date: 2001/07/12 10:29:37 $
    */
   public abstract class AbstractStreamPipeline extends AbstractLoggable implements 
StreamPipeline, Disposable {
       protected EventPipeline eventPipeline;
  @@ -125,9 +127,23 @@
               setupPipeline(environment);
               connectPipeline();
   
  -            // execute the pipeline:
               try {
  +                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;
               }
   
  -            this.reader.setOutputStream(environment.getOutputStream());
  -            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);
  +                environment.getOutputStream().write(data);
  +            } else {
  +                this.reader.setOutputStream(environment.getOutputStream());
  +                this.reader.generate();
               }
           } catch ( Exception e ) {
               throw new ProcessingException("Error reading resource",e);
  
  
  
  1.3.2.7   +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.3.2.6
  retrieving revision 1.3.2.7
  diff -u -r1.3.2.6 -r1.3.2.7
  --- CachingStreamPipeline.java        2001/07/07 19:08:02     1.3.2.6
  +++ CachingStreamPipeline.java        2001/07/12 10:29:38     1.3.2.7
  @@ -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.3.2.6 $ $Date: 2001/07/07 19:08:02 $
  + * @version CVS $Revision: 1.3.2.7 $ $Date: 2001/07/12 10:29:38 $
    */
   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) {
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +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.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- AbstractReader.java       2001/05/22 14:43:33     1.2
  +++ AbstractReader.java       2001/07/12 10:29:43     1.2.2.1
  @@ -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.2.2.1 $ $Date: 2001/07/12 10:29:43 $
    */
   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.2.2.2   +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.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- DatabaseReader.java       2001/07/07 19:08:23     1.2.2.1
  +++ DatabaseReader.java       2001/07/12 10:29:45     1.2.2.2
  @@ -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.1.1.1.2.2 +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.1.1.1.2.1
  retrieving revision 1.1.1.1.2.2
  diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
  --- Reader.java       2001/07/07 19:08:23     1.1.1.1.2.1
  +++ Reader.java       2001/07/12 10:29:45     1.1.1.1.2.2
  @@ -16,17 +16,18 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.1.1.2.1 $ $Date: 2001/07/07 19:08:23 $
  + * @version CVS $Revision: 1.1.1.1.2.2 $ $Date: 2001/07/12 10:29:45 $
    */
   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.3.2.2   +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.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- ResourceReader.java       2001/07/07 19:08:23     1.3.2.1
  +++ ResourceReader.java       2001/07/12 10:29:46     1.3.2.2
  @@ -42,7 +42,7 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.3.2.1 $ $Date: 2001/07/07 19:08:23 $
  + * @version CVS $Revision: 1.3.2.2 $ $Date: 2001/07/12 10:29:46 $
    *
    * 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);
  +    }
  +
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +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.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- AbstractSerializer.java   2001/05/22 14:44:41     1.2
  +++ AbstractSerializer.java   2001/07/12 10:29:54     1.2.2.1
  @@ -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.2.2.1 $ $Date: 2001/07/12 10:29:54 $
    */
   
   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.1.1.1.2.1 +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.1.1
  retrieving revision 1.1.1.1.2.1
  diff -u -r1.1.1.1 -r1.1.1.1.2.1
  --- FOPSerializer.java        2001/05/09 20:49:38     1.1.1.1
  +++ FOPSerializer.java        2001/07/12 10:29:55     1.1.1.1.2.1
  @@ -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.1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.1.1.1.2.1 $ $Date: 2001/07/12 10:29:55 $
    *
    * 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.1.1.1.2.1 +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.1.1
  retrieving revision 1.1.1.1.2.1
  diff -u -r1.1.1.1 -r1.1.1.1.2.1
  --- LinkSerializer.java       2001/05/09 20:49:38     1.1.1.1
  +++ LinkSerializer.java       2001/07/12 10:29:56     1.1.1.1.2.1
  @@ -23,7 +23,7 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.1.1.1.2.1 $ $Date: 2001/07/12 10:29:56 $
    */
   
   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.1.1.1.2.1 +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.1.1
  retrieving revision 1.1.1.1.2.1
  diff -u -r1.1.1.1 -r1.1.1.1.2.1
  --- SVGSerializer.java        2001/05/09 20:49:38     1.1.1.1
  +++ SVGSerializer.java        2001/07/12 10:29:57     1.1.1.1.2.1
  @@ -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.1.1 $ $Date: 2001/05/09 20:49:38 $
  + * @version CVS $Revision: 1.1.1.1.2.1 $ $Date: 2001/07/12 10:29:57 $
    */
   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;
  +    }
  +
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.1.1.2.2 +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.1.1.1.2.1
  retrieving revision 1.1.1.1.2.2
  diff -u -r1.1.1.1.2.1 -r1.1.1.1.2.2
  --- SitemapOutputComponent.java       2001/06/08 14:42:10     1.1.1.1.2.1
  +++ SitemapOutputComponent.java       2001/07/12 10:30:04     1.1.1.1.2.2
  @@ -15,7 +15,8 @@
   /**
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Revision: 1.1.1.1.2.1 $ $Date: 2001/06/08 14:42:10 $
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  + * @version CVS $Revision: 1.1.1.1.2.2 $ $Date: 2001/07/12 10:30:04 $
    */
   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