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/10/23 06:41:34 UTC
svn commit: rev 55353 - cocoon/trunk/src/java/org/apache/cocoon/components/pipeline
Author: vgritsenko
Date: Fri Oct 22 21:41:33 2004
New Revision: 55353
Modified:
cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
Log:
Re-fix bug #26186: Pipeline was prepared twice;
as a result, readers were setup()ed twice, and
sources were not released.
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java Fri Oct 22 21:41:33 2004
@@ -92,15 +92,21 @@
protected String readerMimeType;
protected ServiceSelector readerSelector;
- /** This is the last component in the pipeline, either the serializer
- * or a custom xmlconsumer for the cocoon: protocol etc.
+ /**
+ * True when pipeline has been prepared.
+ */
+ private boolean prepared;
+
+ /**
+ * This is the last component in the pipeline, either the serializer
+ * or a custom xmlconsumer for the cocoon: protocol etc.
*/
protected XMLConsumer lastConsumer;
- /** the component manager set with compose() */
+ /** The component manager set with compose() */
protected ServiceManager manager;
- /** the component manager set with compose() and recompose() */
+ /** The component manager set with compose() and recompose() */
protected ServiceManager newManager;
/** The configuration */
@@ -332,11 +338,11 @@
* @return true if the pipeline is 'sane', false otherwise.
*/
protected boolean checkPipeline() {
- if ( this.generator == null && this.reader == null) {
+ if (this.generator == null && this.reader == null) {
return false;
}
- if ( this.generator != null && this.serializer == null ) {
+ if (this.generator != null && this.serializer == null) {
return false;
}
@@ -380,15 +386,9 @@
}
} catch (SAXException e) {
- throw new ProcessingException(
- "Could not setup pipeline.",
- e
- );
+ throw new ProcessingException("Could not setup pipeline.", e);
} catch (IOException e) {
- throw new ProcessingException(
- "Could not setup pipeline.",
- e
- );
+ throw new ProcessingException("Could not setup pipeline.", e);
}
}
@@ -399,9 +399,8 @@
XMLProducer producer,
XMLConsumer consumer)
throws ProcessingException {
- XMLProducer next = producer;
// Connect next component.
- next.setConsumer(consumer);
+ producer.setConsumer(consumer);
}
/**
@@ -427,14 +426,8 @@
*/
public boolean process(Environment environment)
throws ProcessingException {
- // If this is an internal request, lastConsumer was reset!
- if (null == this.lastConsumer) {
- this.lastConsumer = this.serializer;
- } else {
- this.preparePipeline(environment);
- }
- if ( this.reader != null ) {
- this.preparePipeline(environment);
+ if (!this.prepared) {
+ preparePipeline(environment);
}
// See if we need to set an "Expires:" header
@@ -454,10 +447,16 @@
return true;
}
- return this.processReader(environment);
+ return processReader(environment);
+ } else {
+ // If this is an internal request, lastConsumer was reset!
+ if (this.lastConsumer == null) {
+ this.lastConsumer = this.serializer;
+ }
+
+ connectPipeline(environment);
+ return processXMLPipeline(environment);
}
- this.connectPipeline(environment);
- return this.processXMLPipeline(environment);
}
/**
@@ -467,15 +466,20 @@
throws ProcessingException {
// TODO (CZ) Get the processor set via IoC
this.processor = EnvironmentHelper.getCurrentProcessor();
- if ( !checkPipeline() ) {
+ if (!checkPipeline()) {
throw new ProcessingException("Attempted to process incomplete pipeline.");
}
- if ( this.reader != null ) {
- this.setupReader( environment );
+ if (this.prepared) {
+ throw new ProcessingException("Duplicate preparePipeline call caught.");
+ }
+
+ if (this.reader != null) {
+ setupReader(environment);
} else {
- this.setupPipeline(environment);
+ setupPipeline(environment);
}
+ this.prepared = true;
}
/**
@@ -486,7 +490,7 @@
public void prepareInternal(Environment environment)
throws ProcessingException {
this.lastConsumer = null;
- this.preparePipeline(environment);
+ preparePipeline(environment);
}
/**
@@ -495,10 +499,10 @@
protected boolean processXMLPipeline(Environment environment)
throws ProcessingException {
- this.setMimeTypeForSerializer(environment);
-
+ setMimeTypeForSerializer(environment);
+
try {
- if (this.serializer != this.lastConsumer) {
+ if (this.lastConsumer == null) {
// internal processing
this.generator.generate();
} else {
@@ -518,9 +522,9 @@
this.generator.generate();
}
}
- } catch ( ProcessingException e ) {
+ } catch (ProcessingException e) {
throw e;
- } catch ( Exception e ) {
+ } catch (Exception e) {
// TODO: Unwrap SAXException ?
throw new ProcessingException("Failed to execute pipeline.", e);
}
@@ -569,14 +573,14 @@
if (mimeType != null) {
environment.setContentType(mimeType);
}
- }
+ }
}
-
+
/**
* Set the mime-type for a serializer
* @param environment The current environment
*/
- protected void setMimeTypeForSerializer(Environment environment)
+ protected void setMimeTypeForSerializer(Environment environment)
throws ProcessingException {
if (this.lastConsumer == null) {
// internal processing: text/xml
@@ -640,19 +644,21 @@
}
public void recycle() {
- // release reader.
- if ( this.readerSelector != null) {
+ this.prepared = false;
+
+ // Release reader.
+ if (this.readerSelector != null) {
this.readerSelector.release(this.reader);
- this.newManager.release( this.readerSelector );
+ this.newManager.release(this.readerSelector);
this.readerSelector = null;
this.reader = null;
this.readerParam = null;
}
// Release generator.
- if ( this.generatorSelector != null) {
- this.generatorSelector.release( this.generator );
- this.newManager.release( this.generatorSelector );
+ if (this.generatorSelector != null) {
+ this.generatorSelector.release(this.generator);
+ this.newManager.release(this.generatorSelector);
this.generatorSelector = null;
this.generator = null;
this.generatorParam = null;
@@ -662,19 +668,19 @@
int size = this.transformerSelectors.size();
for (int i = 0; i < size; i++) {
final ServiceSelector selector =
- (ServiceSelector)this.transformerSelectors.get(i);
+ (ServiceSelector) this.transformerSelectors.get(i);
selector.release(this.transformers.get(i));
- this.newManager.release( selector );
+ this.newManager.release(selector);
}
this.transformerSelectors.clear();
this.transformers.clear();
this.transformerParams.clear();
this.transformerSources.clear();
- // release serializer
- if ( this.serializerSelector != null ) {
+ // Release serializer
+ if (this.serializerSelector != null) {
this.serializerSelector.release(this.serializer);
- this.newManager.release( this.serializerSelector );
+ this.newManager.release(this.serializerSelector);
this.serializerSelector = null;
this.serializerParam = null;
}
@@ -691,11 +697,11 @@
public boolean process(Environment environment, XMLConsumer consumer)
throws ProcessingException {
this.lastConsumer = consumer;
- if ( this.reader != null ) {
+ if (this.reader != null) {
throw new ProcessingException("Streaming of an internal pipeline is not possible with a reader.");
}
- this.connectPipeline(environment);
- return this.processXMLPipeline(environment);
+ connectPipeline(environment);
+ return processXMLPipeline(environment);
}
/**