For performance reasons, Servicemix uses a StreamSource wherever possible. The default implementation has one big drawback however: the stream can only be read once, a second attempt to read will result in this IOException.

In order to avoid this exception when writing Java classes that interact with the ESB, you should use a StringSource or BytesSource whenever you are sending a message that will be read multiple times. Both Source implementations extend StreamSource, but are built for ServiceMix to allow re-readability by recreating the InputStream again every time the getInputStream() method is called.

All standard JBI components that are shipped with ServiceMix should convert to a re-readable Source type automatically whenever it is necessary. If you encounter this exception using standard JBI components, please send the complete stacktrace to the user mailing list so we can look into the problem. As a temporary workaround, changing the logging level to DEBUG will make all MessageExchanges re-readable when printing them to the console.

If you encounter this issue in your own code (e.g. in a servicemix-bean POJO), you can use the org.apache.servicemix.jbi.helper.MessageUtil class' enableContentRereadability() method to convert the NormalizedMessage content into a rereadable format before you start processing it.

  • No labels