XModuleSource getInputStream() throws NPE
-----------------------------------------
Key: COCOON-2077
URL: https://issues.apache.org/jira/browse/COCOON-2077
Project: Cocoon
Issue Type: Bug
Components: * Cocoon Core
Affects Versions: 2.1.10, 2.1.9, 2.1.11-dev (Current SVN), 2.2-dev (Current
SVN)
Reporter: Ellis Pritchard
Priority: Minor
I'm getting:
java.lang.NullPointerException
at
org.apache.cocoon.serialization.AbstractTextSerializer.getTransformerHandler(AbstractTextSerializer.java:138)
at
org.apache.cocoon.serialization.XMLSerializer.setOutputStream(XMLSerializer.java:53)
at
org.apache.cocoon.components.source.impl.XModuleSource.getInputStream(XModuleSource.java:196)
at
com.researchresearch.cocoon.generation.RESTfulServiceGenerator.doPOSTBody(RESTfulServiceGenerator.java:323)
at
com.researchresearch.cocoon.generation.RESTfulServiceGenerator.generate(RESTfulServiceGenerator.java:276)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:579)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:780)
at
org.apache.cocoon.components.source.impl.SitemapSource.toSAX(SitemapSource.java:414)
at
org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:101)
at
org.apache.cocoon.components.source.SourceUtil.parse(SourceUtil.java:321)
at
org.apache.cocoon.sitemap.ContentAggregator.generate(ContentAggregator.java:125)
...
When trying to use an xmodule: as the source for a custom generator.
[Cocoon BRANCH_2_1_X.]
Now admittedly, I'm not using it in a pure sitemap way, which would end up
using the XMLizable interface method, but I'm calling the (equally valid)
Source method getInputStream() instead.
The offending code in org.apache.cocoon.components.source.impl.XModuleSource
seems to be:
/**
* Return an <code>InputStream</code> object to read from the source.
*
* @throws IOException if I/O error occured.
*/
// Stolen from QDoxSource
public InputStream getInputStream() throws IOException, SourceException {
if ( this.logger.isDebugEnabled() ) {
this.logger.debug( "Getting InputStream for " + getURI() );
}
// Serialize the SAX events to the XMLSerializer:
XMLSerializer serializer = new XMLSerializer(); <!--- HERE: creates
XMLSerializer, but doesn't configure() it !! -->
ByteArrayInputStream inputStream = null;
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(
2048 );
serializer.setOutputStream( outputStream );
toSAX( serializer );
inputStream = new ByteArrayInputStream( outputStream.toByteArray()
);
} catch ( SAXException se ) {
logger.error( "SAX exception!", se );
throw new SourceException( "Serializing SAX to a ByteArray
failed!", se );
}
return inputStream;
}
The serializer is created, but not configure()d, and it is only the
configuration that sets the TransformerFactory in AbstractTextSerializer.java,
hence the NPE.
The causal change seems to have been made to AbstractTextSerializer yonks ago:
23784 3/19/03 5:37PM sylvain Allow the TransformerFactory class to
be specified in the configuration
Before that revision the TransformerFactory was set in the constructor of
AbstractTextSerializer, thus it worked with the xmodule getInputStream() method
before that change.
No compensating change is in XModuleSource (433543), so this has been broken
since 2003.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.