I ran into what seems to be the infamous "failed to execute pipeline" problem 
with Cocoon 2.1.2 in trying to execute a simple XSLT transform.  Doing some 
googling led me to believe that I'm not the only one that has been puzzled by 
this bug.  

Eliminating the transform from the pipeline and serializing directly to XML 
showed well formed XML going into the transform step, which was very 
frustrating, so I put in a logging transform. Lo and behold, the logger 
showed that the startDocument and endDocument SAX events were doubled up!  

What caused this problem is that I had set a session attribute (in a custom Action) to 
hold the XML document I wanted 
transformed, but I had set that attribute to be the DOM Document object, then used 
SessionAttributeGenerator to create the SAX event stream for the transformation.  This 
should be 
perfectly acceptable!

Problem is that the generate() method in SessionAttributeGenerator looks as follows:

public void generate() throws IOException, SAXException, ProcessingException {
        xmlConsumer.startDocument();

        if (this.elementName != null) {
                xmlConsumer.startElement("", this.elementName, this.elementName, new 
AttributesImpl());
                XMLUtils.valueOf(xmlConsumer, this.attrObject);
                xmlConsumer.endElement("", this.elementName, this.elementName);
        } else {
                XMLUtils.valueOf(xmlConsumer, this.attrObject);
        }
                
        xmlConsumer.endDocument();
}

The bug is evident because if the this.attrObject is set to a Document object (rather 
than the 
document root Element), the method generates a start/end document....but so does the 
interior code! 
So you get duplicate start/endDocument events generated and downstream XSLT transforms 
barf on the 
input (funny that the XML serializer doesn't much care about this duplication).

Anyway, rewriting the generate() method of SessionAttributeGenerator will correct this 
insidious 
bug:

public void generate() throws IOException, SAXException, ProcessingException {
        if( !( attrObject instanceof Document ) {
                xmlConsumer.startDocument();
        }

        ...same interior code as before
                
        if( !( attrObject instanceof Document ) {
                xmlConsumer.endDocument();
        }       
}

I've posted this bug fix to the Cocoon dev list, and hopefully one of the 
developers will incorporate it into 2.1.3, thereby saving some else some 
serious headaches in tracking down this bug.

In the meantime, the quick workaround (if you don't want to change the Cocoon 
source and rebuild it) is to just set your session attribute to be the root 
element of the document rather than the document itself.  For example, if 
you're code has a Document object called doc, then do something like this:

        session.setAttribute("my-attribute", doc.getDocumentElement() );

instead of:

        session.setAttribute("my-attribute", doc ); 

which will cause the bug to manifest.

Just thought I would pass on the info....



Andrzej Jan Taramina
Chaeron Corporation: Enterprise System Solutions
http://www.chaeron.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to