cziegeler 02/05/27 03:06:40 Modified: src/java/org/apache/cocoon/components/pipeline/impl CachingProcessingPipeline.java Log: Minor update of the caching algorithm Revision Changes Path 1.11 +25 -12 xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java Index: CachingProcessingPipeline.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- CachingProcessingPipeline.java 27 May 2002 09:57:19 -0000 1.10 +++ CachingProcessingPipeline.java 27 May 2002 10:06:40 -0000 1.11 @@ -89,7 +89,7 @@ * * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CachingProcessingPipeline.java,v 1.10 2002/05/27 09:57:19 cziegeler Exp $ + * @version CVS $Id: CachingProcessingPipeline.java,v 1.11 2002/05/27 10:06:40 cziegeler Exp $ */ public class CachingProcessingPipeline extends AbstractProcessingPipeline @@ -178,7 +178,7 @@ throws ProcessingException { if (this.pipelineCacheKey == null) { return super.processXMLPipeline( environment ); - } else if (this.completeResponseIsCached) { + } else if (this.cachedResponse != null && this.completeResponseIsCached) { try { final OutputStream outputStream = environment.getOutputStream(); byte[] response = this.cachedResponse.getResponse(); @@ -197,11 +197,16 @@ throw new ProcessingException("Error executing reader pipeline.",e); } } else { + try { + OutputStream os = environment.getOutputStream(); + if ( this.completeResponseIsCached ) { + os = new CachingOutputStream( os ); + } if (this.serializer.shouldSetContentLength()) { // set the output stream - ByteArrayOutputStream os = new ByteArrayOutputStream(); - this.serializer.setOutputStream(os); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + this.serializer.setOutputStream(baos); // execute the pipeline: if ( this.xmlDeserializer != null ) { @@ -209,12 +214,12 @@ } else { this.generator.generate(); } - byte[] data = os.toByteArray(); + byte[] data = baos.toByteArray(); environment.setContentLength(data.length); - environment.getOutputStream().write(data); + os.write(data); } else { // set the output stream - this.serializer.setOutputStream(environment.getOutputStream()); + this.serializer.setOutputStream( os ); // execute the pipeline: if ( this.xmlDeserializer != null ) { this.xmlDeserializer.deserialize(this.cachedResponse.getResponse()); @@ -223,11 +228,19 @@ } } if (this.xmlSerializer != null) { - CachedResponse response = new CachedResponse(this.validityObjects, - (byte[])this.xmlSerializer.getSAXFragment()); - this.cache.store(environment.getObjectModel(), - this.pipelineCacheKey, - response); + if ( this.completeResponseIsCached ) { + CachedResponse response = new CachedResponse(this.validityObjects, + ((CachingOutputStream)os).getContent()); + this.cache.store(environment.getObjectModel(), + this.pipelineCacheKey, + response); + } else { + CachedResponse response = new CachedResponse(this.validityObjects, + (byte[])this.xmlSerializer.getSAXFragment()); + this.cache.store(environment.getObjectModel(), + this.pipelineCacheKey, + response); + } } } catch ( SocketException se ) { if (se.getMessage().indexOf("reset") > 0
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]