-
1. Re: Problem implementing MessageExchangeListener
surajit_surajit.choudhury Feb 6, 2009 6:42 AM (in response to pdisabit)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);
message.setContent(outMsg);
exchange.setMessage(message, "out");
channel.send(exchange);
-
-
2. Re: Problem implementing MessageExchangeListener
gertv Feb 6, 2009 7:15 AM (in response to surajit_surajit.choudhury)L.S.,
When I run the example on my machine with DEBUG logging enabled, I get this in the ouput:
exchange: InOut[
id: ID:127.0.0.1-11f4afca333-21:505
status: Active
role: consumer
service: beanService
endpoint: beanEndpoint
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.
Regards,
Gert
Edited by: gertv on Feb 6, 2009 1:15 PM
-
MessageDoublerBean.java 2.0 KB
-
3. Re: Problem implementing MessageExchangeListener
gertv Feb 10, 2009 7:01 AM (in response to gertv)Paul,
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.
Regards,
Gert