Search code examples
xmljaxbcontrol-charactersapache-wink

Can Apache Wink ignore unprintable xml characters?


My application supports REST API using Wink and a JAXB provider built in to the JDK (1.6). Sometimes I receive PUT requests that contain control characters.

As far as my application is concerned, the control characters constitute a valid and meaningful input. However, the application throws the notorious exception saying that it cannot digest these characters:

Message: An invalid XML character (Unicode: 0x13) was found in the element content of the document.]
at org.apache.wink.common.internal.providers.entity.xml.JAXBXmlProvider.readFrom(JAXBXmlProvider.java:107)
at org.apache.wink.server.internal.registry.ServerInjectableFactory$EntityParam.getValue(ServerInjectableFactory.java:190)
at org.apache.wink.common.internal.registry.InjectableFactory.instantiate(InjectableFactory.java:67)
at org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest

There is probably no way to tell the JAXB provider to ignore these characters (since at some point I will have to parse the Xml, and illegal is illegal..). How can I make this work? Is there a way to instruct the Rest client to escape these characters before sending them?


Solution

  • Control characters are not allowed in XML so your data is not XML. The trouble with it is like X except for Y is that it would be difficult to define an API where Y can be whatever the individual thinks it should be. It is unlikely JAXB will accommodate you. You could use a filter to strip the illegal characters if that is acceptable; otherwise you will have to encode or escape the data in legal character data (e.g. with Base64.)