Eli*_*les 18 java xml spring cxf
我正在使用Spring,CXF和Hibernate构建一个WebService,它在我具有只读访问权限的外部数据库上执行搜索查询.
问题是数据库中的某些条目在文本字段中有奇怪的字符(0x2),并且它似乎用于处理/序列化从Hibernate会话返回的对象的CXF或库(Aegis?)无法处理它:
org.apache.cxf.aegis.DatabindingException: Error writing document.. Nested exception is com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x2) in text to output (in xml 1.1, could output as a character entity)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?理想情况下,我可以删除这些字符,因为它们对我的输出无关紧要...谢谢!
nDi*_*jax 16
/**
* From xml spec valid chars:<br>
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]<br>
* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.<br>
* @param text The String to clean
* @param replacement The string to be substituted for each match
* @return The resulting String
*/
public static String CleanInvalidXmlChars(String text, String replacement) {
String re = "[^\u0009\r\n\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF]";
return text.replaceAll(re, replacement);
}
Run Code Online (Sandbox Code Playgroud)
来源:http://www.theplancollection.com/house-plan-related-articles/hexadecimal-value-invalid-characterheplancollection.com/house-plan-related-articles/hexadecimal-value-invalid-character
我不确定这会回答你的问题,但这是我发现的.
以下是抛出异常的类:http: //svn.codehaus.org/woodstox/wstx/trunk/src/java/com/ctc/wstx/api/InvalidCharHandler.java
似乎这里有关于这个问题的讨论:http://comments.gmane.org/gmane.comp.apache.cxf.user/4373
也许这可能是你: 你也可以在端点/总线上设置一个"disable.outputstream.optimization"属性为true,让它禁止直接写入输出流并始终通过XMLStreamWriter.如果没有创建SAAJModel的开销,应该完成同样的事情.
希望这个对你有帮助.
| 归档时间: |
|
| 查看次数: |
24273 次 |
| 最近记录: |