This is not a solution, but ..
I had the same problem with this example where it complains of the stream being closed. The way I got around is not to use the toString() on the SourceTransformer, but parse the result, and create a new Source. All this taken from the deprecated JdbcComponent.java in the ServiceMix source tree. Please see below for code snippet:
NormalizedMessage message = exchange.getMessage("in");
SourceTransformer domTransform = new SourceTransformer();
Node domNode = domTransform.toDOMNode(message);
String query = getQuery(domNode);
// Execute query
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
// Convert result to an XML doc and send it off
Source outMsg = toXmlSource(result);
When I run the example on my machine with DEBUG logging enabled, I get this in the ouput:
in: Unable to display: org.xml.sax.SAXParseException: Element type "eipEnvelope" must be followed by either attribute specifications, ">" or "/>".
out: Unable to display: java.io.IOException: Stream closed
This shows the two problems: a StreamSource not being handled properly and invalid XML content being generated. In order to fix those issues:
add a call to MessageUtil.enableContentRereadability at the beginning of the bean method to ensure caching the content's stream
correct the opening tag (should be <eipEnvelope> instead of <eipEnvelope/>
make a new NormalizedMessage for the out instead of copying the old one to avoid reusing the old stream
Attaching the java source file with all the fixes in it.
Edited by: gertv on Feb 6, 2009 1:15 PM
MessageDoublerBean.java 2.0 K
There still was a problem when running this with DEBUG logging disabled. It appears the content enricher wasn't handling StreamSources correctly. I raised and fixed https://issues.apache.org/activemq/browse/SM-1796 for this, so a new local build of the component will make this work.