Willem Jiang commented on CAMEL-2330:
I just committed your patch for this issue,
The highlight of Pavel's patch
* Marshalling uses custom XmlStreamWriter, while unmarshalling relies on the same, non-xml reader. I realized that wrapping XmlStreamReader does not solve the problem, as wrapper has no power to prevent underlying reader from reading bad chars and failing therefore.
* Filtering has changed slightly - it replaces bad chars with space chars. This a) allows to get rid of intemediate buffer and simplify the code and b) is consistent with the way e.g. Woodstox performs similar filtering.
* It is exchange property or data format property that turns filtering on/off.
* NonXmlCharFilterer performs logging of the replacement fact in case of char; and more readable message in case of String.
Here are the highlight of my changes
* Fixed the issue of patch that can't build with JDK 1.5.0, comment out the NonXmlCharFiltererTest.testFilter1ArgFiltered(), also add the stax implementation dependency in the camel-jaxb
* You just check the Exchange property in JaxbDataFormat marshal(), and check the filterNonXmlChars in JaxbDataFormat unmarshal method.
My change is let the exchange property override the configure of JaxbDataFormat that is same with other Camel components do.
* When unmarshaling the InputStream, you need to get the CharsetEncoding from Exchange like this
answer = unmarshaller.unmarshal(new NonXmlFilterReader(new InputStreamReader(stream, IOConvertor(getCharsetName(exchange))));
* Finish the filtering option for JAXB data format via spring DSL .