You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/09/27 22:33:48 UTC

svn commit: rev 47330 - cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl

Author: vgritsenko
Date: Mon Sep 27 13:33:47 2004
New Revision: 47330

Modified:
   cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
   cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
   cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
Log:
Fix SAXException: XMLSerializer expects byte[], not CachedResponse


Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java	Mon Sep 27 13:33:47 2004
@@ -164,21 +164,23 @@
     throws ProcessingException {
         if (this.toCacheKey == null && this.cachedResponse == null) {
             return super.processXMLPipeline(environment);
+        }
 
-        } else if (this.cachedResponse != null
-                && this.completeResponseIsCached) {
+        if (this.cachedResponse != null && this.completeResponseIsCached) {
 
             // Allow for 304 (not modified) responses in dynamic content
-            if (super.checkIfModified(environment, this.cachedLastModified)) {
+            if (checkIfModified(environment, this.cachedLastModified)) {
                 return true;
             }
 
-            // set mime-type
-            if ( this.cachedResponse.getContentType() != null ) {
+            // Set mime-type
+            if (this.cachedResponse.getContentType() != null) {
                 environment.setContentType(this.cachedResponse.getContentType());
             } else {
-                this.setMimeTypeForSerializer(environment);
+                setMimeTypeForSerializer(environment);
             }
+
+            // Write response out
             try {
                 final OutputStream outputStream = environment.getOutputStream(0);
                 final byte[] content = this.cachedResponse.getResponse();
@@ -190,7 +192,7 @@
                 handleException(e);
             }
         } else {
-            this.setMimeTypeForSerializer(environment);
+            setMimeTypeForSerializer(environment);
             if (getLogger().isDebugEnabled() && this.toCacheKey != null) {
                 getLogger().debug("processXMLPipeline: caching content for further" +
                                   " requests of '" + environment.getURI() +
@@ -201,45 +203,51 @@
                 OutputStream os = null;
 
                 if (this.cacheCompleteResponse && this.toCacheKey != null) {
-                    os = new CachingOutputStream(
-                            environment.getOutputStream(this.outputBufferSize));
+                    os = new CachingOutputStream(environment.getOutputStream(this.outputBufferSize));
                 }
+
                 if (super.serializer != super.lastConsumer) {
                     if (os == null) {
                         os = environment.getOutputStream(this.outputBufferSize);
                     }
+
                     // internal processing
                     if (this.xmlDeserializer != null) {
-                        this.xmlDeserializer.deserialize(this.cachedResponse);
+                        this.xmlDeserializer.deserialize(this.cachedResponse.getResponse());
                     } else {
                         this.generator.generate();
                     }
+
                 } else {
                     if (this.serializer.shouldSetContentLength()) {
                         if (os == null) {
                             os = environment.getOutputStream(0);
                         }
-                        // set the output stream
+
+                        // Set the output stream
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
                         this.serializer.setOutputStream(baos);
 
-                        // execute the pipeline:
-                        if ( this.xmlDeserializer != null ) {
-                            this.xmlDeserializer.deserialize(this.cachedResponse);
+                        // Execute the pipeline
+                        if (this.xmlDeserializer != null) {
+                            this.xmlDeserializer.deserialize(this.cachedResponse.getResponse());
                         } else {
                             this.generator.generate();
                         }
+
                         environment.setContentLength(baos.size());
                         baos.writeTo(os);
                     } else {
                         if (os == null) {
                             os = environment.getOutputStream(this.outputBufferSize);
                         }
-                        // set the output stream
+
+                        // Set the output stream
                         this.serializer.setOutputStream(os);
-                        // execute the pipeline:
+
+                        // Execute the pipeline
                         if (this.xmlDeserializer != null) {
-                            this.xmlDeserializer.deserialize(this.cachedResponse);
+                            this.xmlDeserializer.deserialize(this.cachedResponse.getResponse());
                         } else {
                             this.generator.generate();
                         }
@@ -622,8 +630,8 @@
      */
     protected void connectPipeline(Environment   environment)
     throws ProcessingException {
-        if ( this.toCacheKey == null && this.cachedResponse == null) {
-            super.connectPipeline( environment );
+        if (this.toCacheKey == null && this.cachedResponse == null) {
+            super.connectPipeline(environment);
             return;
         } else if (this.completeResponseIsCached) {
             // do nothing

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java	Mon Sep 27 13:33:47 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -82,10 +82,10 @@
     /**
      * Set the generator.
      */
-    public void setGenerator (String role, String source, Parameters param, Parameters hintParam) 
+    public void setGenerator (String role, String source, Parameters param, Parameters hintParam)
     throws ProcessingException {
         super.setGenerator(role, source, param, hintParam);
-        
+
         // check the hint param for a "caching-point" hint
         String pipelinehint = null;
         try {
@@ -128,7 +128,7 @@
                 getLogger().warn("caching-point hint Exception, pipeline-hint ignored: " + ex);
             }
         }
-	
+
         // add caching point flag
         // default value is false
         this.isCachePoint.add(new Boolean(this.nextIsCachePoint));
@@ -156,7 +156,7 @@
         }
         if (!this.autoCachingPoint) {
             return;
-        }   
+        }
 
         this.nextIsCachePoint = true;
         if (this.getLogger().isDebugEnabled()) {
@@ -265,8 +265,8 @@
                 this.xmlSerializer = (XMLSerializer)this.manager.lookup( XMLSerializer.ROLE );
                 localXMLSerializer = this.xmlSerializer;
             }
-            if ( this.cachedResponse == null ) {
 
+            if (this.cachedResponse == null) {
                 XMLProducer prev = super.generator;
                 XMLConsumer next;
 
@@ -383,7 +383,7 @@
                 this.connect(environment, prev, next);
             }
 
-        } catch ( ServiceException e ) {
+        } catch (ServiceException e) {
             throw new ProcessingException("Could not connect pipeline.", e);
         }
     }
@@ -399,10 +399,10 @@
         while (itt.hasNext()) {
             this.manager.release(itt.next());
         }
+
         this.isCachePoint.clear();
         this.xmlSerializerArray.clear();
         this.nextIsCachePoint = false;
         this.autoCachingPointSwitch=null;
     }
-
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java	Mon Sep 27 13:33:47 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,7 +47,7 @@
     */
     protected void cacheResults(Environment environment, OutputStream os)  throws Exception {
         if (this.toCacheKey != null) {
-            // See if there is an expires object for this resource.                
+            // See if there is an expires object for this resource.
             Long expiresObj = (Long) environment.getObjectModel().get(ObjectModelHelper.EXPIRES_OBJECT);
             if ( this.cacheCompleteResponse ) {
                 CachedResponse response = new CachedResponse(this.toCacheSourceValidities,
@@ -85,7 +85,8 @@
                     this.xmlSerializer = (XMLSerializer)this.manager.lookup( XMLSerializer.ROLE );
                     localXMLSerializer = this.xmlSerializer;
                 }
-                if ( this.cachedResponse == null ) {
+
+                if (this.cachedResponse == null) {
                     XMLProducer prev = super.generator;
                     XMLConsumer next;