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/09 04:28:48 UTC

svn commit: rev 43561 - in cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components: . flow flow/util pipeline/impl source/impl

Author: vgritsenko
Date: Wed Sep  8 19:28:46 2004
New Revision: 43561

Modified:
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
   cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
Log:
pipelineutil: close input stream


Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/CocoonComponentManager.java	Wed Sep  8 19:28:46 2004
@@ -199,7 +199,7 @@
      * @return A unique key within this thread.
      */
     public static Object startProcessing(Environment env) {
-		if ( null == env) {
+		if (null == env) {
 			throw new RuntimeException("CocoonComponentManager.startProcessing: environment must be set.");
 		}
         final EnvironmentDescription desc = new EnvironmentDescription(env);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java	Wed Sep  8 19:28:46 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.
@@ -59,12 +59,12 @@
   implements Component, Serviceable, Contextualizable, Interpreter,
              SingleThreaded, Configurable, Disposable
 {
-    // The instance counters, used to produce unique IDs 
+    // The instance counters, used to produce unique IDs
     private static int instanceCounter = 0;
-    
+
     // The instance ID of this interpreter, used to identify user scopes
     private String instanceID;
-    
+
     protected org.apache.avalon.framework.context.Context avalonContext;
 
     /**
@@ -75,7 +75,7 @@
     protected org.apache.cocoon.environment.Context context;
     protected ServiceManager manager;
     protected ContinuationsManager continuationsMgr;
-    
+
     /**
      * Whether reloading of scripts should be done. Specified through
      * the "reload-scripts" attribute in <code>flow.xmap</code>.
@@ -94,11 +94,11 @@
             this.instanceID = String.valueOf(instanceCounter);
         }
     }
-    
+
     /**
      * Get the unique ID for this interpreter, which can be used to distinguish user value scopes
      * attached to the session.
-     * 
+     *
      * @return a unique ID for this interpreter
      */
     protected String getInterpreterID() {
@@ -179,8 +179,7 @@
      * @exception Exception If an error occurs.
      */
     public void process(String uri, Object biz, OutputStream out)
-        throws Exception 
-    {
+    throws Exception {
         // FIXME (SW): should we deprecate this method in favor of PipelineUtil?
         PipelineUtil pipeUtil = new PipelineUtil();
         try {
@@ -195,8 +194,7 @@
     public void forwardTo(String uri, Object bizData,
                           WebContinuation continuation,
                           Redirector redirector)
-        throws Exception
-    {
+    throws Exception {
         if (SourceUtil.indexOfSchemeColon(uri) == -1) {
             uri = "cocoon:/" + uri;
             Map objectModel = ContextHelper.getObjectModel(this.avalonContext);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java	Wed Sep  8 19:28:46 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.
@@ -42,12 +42,12 @@
  * Utility class to process a pipeline to various destinations.
  * This class must be setup from the flowscript before being used. This means that instances must
  * be created with <code>cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
- * 
+ *
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
- * @version CVS $Id: PipelineUtil.java,v 1.3 2004/05/04 11:54:35 cziegeler Exp $
+ * @version CVS $Id$
  */
 public class PipelineUtil implements Contextualizable, Serviceable, Disposable {
-    
+
     private Context context;
     private ServiceManager manager;
     private SourceResolver resolver;
@@ -56,23 +56,23 @@
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
-        if ( this.manager != null ) {
-            this.manager.release( this.resolver );
+        if (this.manager != null) {
+            this.manager.release(this.resolver);
             this.manager = null;
             this.resolver = null;
         }
     }
-    
+
     public void contextualize(Context context) throws ContextException {
         this.context = context;
-        
+
     }
 
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
         this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
     }
-    
+
     /**
      * Check that this object has been correctly set up.
      *
@@ -80,36 +80,42 @@
      */
     private void checkSetup() {
         if (this.manager == null) {
-            throw new IllegalStateException("Instances of " + this.getClass().getName() +
-                " must be setup using either cocoon.createObject() or cocoon.setupObject().");
+            throw new IllegalStateException("Instances of " + getClass().getName() +
+                                            " must be setup using either cocoon.createObject() or cocoon.setupObject().");
         }
     }
-    
+
     /**
      * Process a pipeline to a stream.
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @param output the stream where pipeline result is output. Note: this stream is not closed.
      * @throws IOException
      */
-    public void processToStream(String uri, Object viewData, OutputStream output) throws IOException {
+    public void processToStream(String uri, Object viewData, OutputStream output)
+    throws IOException {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
 
         // Keep the previous view data, if any (is it really necessary?), and set the new one
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
+        InputStream input = null;
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
-            InputStream input = src.getInputStream();
-            
+            input = src.getInputStream();
             IOUtil.copy(input, output);
         } finally {
+            if (input != null) {
+                try {
+                    input.close();
+                } catch (IOException ignored) {}
+            }
+
             // Restore the previous view data
             FlowHelper.setContextObject(objectModel, oldViewData);
 
@@ -118,23 +124,23 @@
             }
         }
     }
-    
+
     /**
      * Process a pipeline to a SAX <code>ContentHandler</code>
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @param handler where the pipeline should be streamed to.
      */
-    public void processToSAX(String uri, Object viewData, ContentHandler handler) throws SAXException, IOException, ProcessingException {
+    public void processToSAX(String uri, Object viewData, ContentHandler handler)
+    throws SAXException, IOException, ProcessingException {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
             SourceUtil.toSAX(src, handler);
@@ -145,23 +151,23 @@
             }
         }
     }
-    
+
     /**
      * Process a pipeline and gets is result as a DOM <code>Document</code>
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @return the document
      */
     public Document processToDOM(String uri, Object viewData) throws ProcessingException, SAXException, IOException  {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
+
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
             return SourceUtil.toDOM(src);

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java	Wed Sep  8 19:28:46 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,7 +82,7 @@
     protected PipelineCacheKey toCacheKey;
     /** The source validities used for caching */
     protected SourceValidity[] toCacheSourceValidities;
-    
+
     /** The index indicating to the first transformer which is not cacheable */
     protected int firstNotCacheableTransformerIndex;
     /** Cache complete response */
@@ -96,7 +96,7 @@
     protected boolean doSmartCaching;
     /** Default setting for smart caching */
     protected boolean configuredDoSmartCaching;
-    
+
     /**
      * Abstract methods defined in subclasses
      */
@@ -116,7 +116,7 @@
         this.configuredDoSmartCaching =
             params.getParameterAsBoolean("smart-caching", true);
     }
-    
+
     /**
      * Setup this component
      */
@@ -211,7 +211,7 @@
             }
             try {
                 OutputStream os = null;
-                
+
                 if (this.cacheCompleteResponse && this.toCacheKey != null) {
                     os = new CachingOutputStream(environment.getOutputStream(
                             this.outputBufferSize));
@@ -235,7 +235,7 @@
                         ByteArrayOutputStream baos =
                             new ByteArrayOutputStream();
                         this.serializer.setOutputStream(baos);
-    
+
                         // execute the pipeline:
                         if ( this.xmlDeserializer != null ) {
                             this.xmlDeserializer.deserialize(
@@ -332,7 +332,7 @@
 
             while (this.firstNotCacheableTransformerIndex < transformerSize
                     && continueTest) {
-                final Transformer trans = 
+                final Transformer trans =
                     (Transformer)super.transformers.get(
                             this.firstNotCacheableTransformerIndex);
                 key = null;
@@ -355,7 +355,7 @@
                     continueTest = false;
                 }
             }
-            // all transformers are cacheable => pipeline is cacheable 
+            // all transformers are cacheable => pipeline is cacheable
             // test serializer if this is not an internal request
             if (this.firstNotCacheableTransformerIndex == transformerSize
                 && super.serializer == this.lastConsumer) {
@@ -388,10 +388,10 @@
             // only update validity objects if we cannot use
             // a cached response or when the cached response does
             // cache less than now is cacheable
-            if (this.fromCacheKey == null 
+            if (this.fromCacheKey == null
                 || this.fromCacheKey.size() < this.toCacheKey.size()) {
 
-                this.toCacheSourceValidities = 
+                this.toCacheSourceValidities =
                     new SourceValidity[this.toCacheKey.size()];
                 int len = this.toCacheSourceValidities.length;
                 int i = 0;
@@ -400,7 +400,7 @@
                         this.getValidityForInternalPipeline(i);
 
                     if (validity == null) {
-                        if (i > 0 
+                        if (i > 0
                             && (this.fromCacheKey == null
                                     || i > this.fromCacheKey.size())) {
                             // shorten key
@@ -437,21 +437,21 @@
     }
 
     /**
-     * Calculate the key that can be used to get something from the cache, and 
+     * Calculate the key that can be used to get something from the cache, and
      * handle expires properly.
-     * 
+     *
      */
     protected void validatePipeline(Environment environment)
     throws ProcessingException {
         this.completeResponseIsCached = this.cacheCompleteResponse;
-        this.fromCacheKey = this.toCacheKey.copy();        
+        this.fromCacheKey = this.toCacheKey.copy();
         this.firstProcessedTransformerIndex = this.firstNotCacheableTransformerIndex;
         this.cachedLastModified = 0L;
 
         boolean finished = false;
-        
+
         while (this.fromCacheKey != null && !finished) {
-            
+
             finished = true;
             final CachedResponse response = this.cache.get( this.fromCacheKey );
 
@@ -459,7 +459,7 @@
             if (response != null) {
                 if (this.getLogger().isDebugEnabled()) {
                     this.getLogger().debug(
-                        "Found cached response for '" + environment.getURI() + 
+                        "Found cached response for '" + environment.getURI() +
                         "' using key: " + this.fromCacheKey
                     );
                 }
@@ -495,27 +495,27 @@
                                 environment.getURI() +
                                 " regenerating content.");
                         }
-                        
+
                         // If an expires parameter was provided, use it. If this parameter is not available
                         // it means that the sitemap was modified, and the old expires value is not valid
                         // anymore.
                         if (expires != 0) {
                             if (this.getLogger().isDebugEnabled())
                                 this.getLogger().debug("Refreshing expires informations");
-                            response.setExpires(new Long(expires + System.currentTimeMillis()));    
+                            response.setExpires(new Long(expires + System.currentTimeMillis()));
                         } else {
                             if (this.getLogger().isDebugEnabled())
                                 this.getLogger().debug("No expires defined anymore for this object, setting it to no expires");
                             response.setExpires(null);
-                        }                                   
+                        }
                     }
                 } else {
                     // The response had no expires informations. See if it needs to be set (i.e. because the configuration has changed)
                     if (expires != 0) {
                         if (this.getLogger().isDebugEnabled())
                             this.getLogger().debug("Setting a new expires object for this resource");
-                        response.setExpires(new Long(expires + System.currentTimeMillis()));                                
-                    }        
+                        response.setExpires(new Long(expires + System.currentTimeMillis()));
+                    }
                 }
 
                 SourceValidity[] fromCacheValidityObjects = response.getValidityObjects();
@@ -528,7 +528,7 @@
                     SourceValidity validity = fromCacheValidityObjects[i];
                     int valid = validity != null ? validity.isValid() : -1;
                     if ( valid == 0) { // don't know if valid, make second test
-                       
+
                         validity = this.getValidityForInternalPipeline(i);
 
                         if (validity != null) {
@@ -607,15 +607,15 @@
                     this.completeResponseIsCached = false;
                 }
             } else {
-                
+
                 // no cached response found
                 if (this.getLogger().isDebugEnabled()) {
                     this.getLogger().debug(
-                        "Cached response not found for '" + environment.getURI() + 
+                        "Cached response not found for '" + environment.getURI() +
                         "' using key: " +  this.fromCacheKey
                     );
                 }
-               
+
                 if (!this.doSmartCaching) {
                     // try a shorter key
                     if (this.fromCacheKey.size() > 1) {
@@ -653,7 +653,7 @@
         if (this.toCacheKey != null) {
             this.validatePipeline(environment);
         }
-        this.setupValidities();        
+        this.setupValidities();
     }
 
     /**
@@ -854,9 +854,9 @@
 
         } else {
             int vals = 0;
-            
+
             if ( null != this.toCacheKey
-                 && !this.cacheCompleteResponse 
+                 && !this.cacheCompleteResponse
                  && this.firstNotCacheableTransformerIndex == super.transformers.size()) {
                  vals = this.toCacheKey.size();
             } else if ( null != this.fromCacheKey
@@ -880,19 +880,19 @@
      * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#getKeyForEventPipeline()
      */
     public String getKeyForEventPipeline() {
-        if ( null != this.toCacheKey 
+        if ( null != this.toCacheKey
              && !this.cacheCompleteResponse
              && this.firstNotCacheableTransformerIndex == super.transformers.size()) {
              return String.valueOf(HashUtil.hash(this.toCacheKey.toString()));
         }
-        if ( null != this.fromCacheKey 
+        if ( null != this.fromCacheKey
              && !this.completeResponseIsCached
              && this.firstProcessedTransformerIndex == super.transformers.size()) {
             return String.valueOf(HashUtil.hash(this.fromCacheKey.toString()));
         }
         return null;
     }
-    
+
     SourceValidity getValidityForInternalPipeline(int index) {
         final SourceValidity validity;
 
@@ -937,12 +937,11 @@
         }
         return validity;
     }
-    
+
     /**
      * Recyclable Interface
      */
     public void recycle() {
-
         this.generatorRole = null;
         this.transformerRoles.clear();
         this.serializerRole = null;
@@ -950,7 +949,7 @@
 
         this.fromCacheKey = null;
         this.cachedResponse = null;
-        
+
         this.transformerIsCacheableProcessingComponent = null;
         this.toCacheKey = null;
         this.toCacheSourceValidities = null;
@@ -964,12 +963,12 @@
 
     private final AbstractCachingProcessingPipeline pipeline;
     private final int index;
-    
+
     public DeferredPipelineValidity(AbstractCachingProcessingPipeline pipeline, int index) {
         this.pipeline = pipeline;
         this.index = index;
     }
-    
+
     /**
      * @see org.apache.excalibur.source.impl.validity.DeferredValidity#getValidity()
      */

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java	Wed Sep  8 19:28:46 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.
@@ -67,7 +67,7 @@
 
     /** The system id used for caching */
     private String systemIdForCaching;
-    
+
     /** The current ComponentManager */
     private final ComponentManager manager;
 
@@ -97,15 +97,15 @@
 
     /** The unique key for this processing */
     private Object processKey;
-    
+
     /** The used protocol */
     private final String protocol;
 
     /** SourceResolver (for the redirect source) */
     private SourceResolver sourceResolver;
-    
+
     private String mimeType;
-    
+
     /**
      * Construct a new object
      */
@@ -161,16 +161,16 @@
         } else if (position > 0) {
             uri = uri.substring(position);
         }
-        
+
         // determine if the queryString specifies a cocoon-view
         String view = null;
         if (queryString != null) {
             int index = queryString.indexOf(Constants.VIEW_PARAM);
-            if (index != -1 
+            if (index != -1
                 && (index == 0 || queryString.charAt(index-1) == '&')
-                && queryString.length() > index + Constants.VIEW_PARAM.length() 
+                && queryString.length() > index + Constants.VIEW_PARAM.length()
                 && queryString.charAt(index+Constants.VIEW_PARAM.length()) == '=') {
-                
+
                 String tmp = queryString.substring(index+Constants.VIEW_PARAM.length()+1);
                 index = tmp.indexOf('&');
                 if (index != -1) {
@@ -194,10 +194,10 @@
             this.protocol + "://" + requestURI + "?" + queryString;
 
         // create environment...
-        EnvironmentWrapper wrapper = new EnvironmentWrapper(env, requestURI, 
+        EnvironmentWrapper wrapper = new EnvironmentWrapper(env, requestURI,
                                                    queryString, logger, manager, rawMode, view);
         wrapper.setURI(prefix, uri);
-        
+
         // The environment is a facade whose delegate can be changed in case of internal redirects
         this.environment = new MutableEnvironmentFacade(wrapper);
 
@@ -207,7 +207,7 @@
         } else {
             this.environment.getObjectModel().remove(ObjectModelHelper.PARENT_CONTEXT);
         }
-        
+
         // initialize
         this.init();
     }
@@ -286,13 +286,13 @@
     }
 
     /**
-     * 
+     *
      * @see org.apache.excalibur.source.Source#exists()
      */
     public boolean exists() {
         return true;
     }
-    
+
     /**
      *  Get the Validity object. This can either wrap the last modification
      *  date or the expires information or...
@@ -332,7 +332,7 @@
         try {
             this.processKey = CocoonComponentManager.startProcessing(this.environment);
             this.processingPipeline = this.processor.buildPipeline(this.environment);
-            this.pipelineProcessor = CocoonComponentManager.getLastProcessor(this.environment); 
+            this.pipelineProcessor = CocoonComponentManager.getLastProcessor(this.environment);
             this.environment.changeToLastContext();
 
             String redirectURL = this.environment.getRedirectURL();
@@ -345,7 +345,7 @@
                     this.processingPipeline.prepareInternal(this.environment);
                     this.sourceValidity = this.processingPipeline.getValidityForEventPipeline();
                     this.mimeType = this.environment.getContentType();
-                    
+
                     final String eventPipelineKey = this.processingPipeline.getKeyForEventPipeline();
                     if (eventPipelineKey != null) {
                         StringBuffer buffer = new StringBuffer(this.systemId);
@@ -358,7 +358,7 @@
                         buffer.append(eventPipelineKey);
                         this.systemIdForCaching = buffer.toString();
                     } else {
-                        this.systemIdForCaching = this.systemId; 
+                        this.systemIdForCaching = this.systemId;
                     }
                 } finally {
                     CocoonComponentManager.leaveEnvironment();
@@ -415,7 +415,7 @@
                                                         this.pipelineProcessor);
                 try {
                     this.processingPipeline.process(this.environment,
-                                       CocoonComponentManager.createEnvironmentAwareConsumer(consumer)); 
+                                       CocoonComponentManager.createEnvironmentAwareConsumer(consumer));
                 } finally {
                     CocoonComponentManager.leaveEnvironment();
                 }
@@ -437,19 +437,23 @@
     private void reset() {
         if (this.processingPipeline != null) {
             this.processingPipeline.release();
+            this.processingPipeline = null;
         }
+
         if (this.processKey != null) {
             CocoonComponentManager.endProcessing(this.environment, this.processKey);
             this.processKey = null;
         }
-        this.processingPipeline = null;
-        this.sourceValidity = null;
+
         if (this.redirectSource != null) {
             this.sourceResolver.release(this.redirectSource);
+            this.redirectSource = null;
         }
-        this.environment.reset();
-        this.redirectSource = null;
+
+        this.sourceValidity = null;
         this.redirectValidity = null;
+
+        this.environment.reset();
         this.exception = null;
         this.needsRefresh = true;
         this.pipelineProcessor = null;