XmlRpcProxy fails and throws an Exception if the XML contains invalid XML characters:
Caused by: redstone.xmlrpc.XmlRpcException: A problem occured during parsing
at redstone.xmlrpc.XmlRpcParser.parse(Unknown Source)
… 29 more
Caused by: org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xb) was found in the element content of the document.
… 30 more
Unfortunately, I don't have any influence on the source so I cannot fix the XML. However, is there a way to persuade the parser to just keep going? There is not much point in totally failing just because of an invalid character.
Alternatively, is there a way to pre-parse the incoming XML to remove the invalid characters?
According to the XML 1.0 spec, an invalid character is considered fatal so I don't think there is any way to configure the SAX parser to ignore them. Short of replacing the XmlRpcProxy with your own version, which uses a modified XmlRpcClient, I don't think this is easily solved.
In your situation, I would take the source code for the library and modify the XmlRpcClient.handleResponse() method, modifying the call to "parse( new BufferedInputStream( connection.getInputStream() ) )" by wrapping the BufferedInputStream in yet another InputStream that you implement yourself to clean the contents of the stream. That way, the SAX parser would ask your stream for data to parse, which in turn asks the BufferedInputStream, and the connection input stream.
It's messy, but as you mention, the error is really with the server responding with invalid characters. It's not really as much code required as it sounds, but you will need to patch the source and implement a new InputStream class, and rebuild the XML-RPC Jar.
Log in to post a comment.