Invalid white space character in text to output (in xml 1.1, could output as a character entity)
private String excuteRealTimeExchange(PadisPackageType reqPackage) {
String result;
try {
result
= rte.execute(JaxbUtils.convertPadisObjectToXml(reqPackage));
}
catch (Exception e) {
throw
new PadisException(
".....");
}
return result;
}
以前一直觉得是网络缘由,致使webserivce发不出去。今天调试,才发现是由于报文中有控制字符,因此才抛出错误。
XML支持的字符是有限的,详细请看:
特殊字符如控制字符是不被支持的
在发送XML的时候,把不合法的控制字符都去掉。
方法以下:
public
static String trimAllISOControl(String str) {
if (
!hasLength(str)) {
return str;
}
StringBuilder sb
=
new StringBuilder(str);
int index
=
0;
while (sb.length()
> index) {
if (
Character.isISOControl(sb.charAt(index))) {
sb.deleteCharAt(index);
}
else {
index
++;
}
}
return sb.toString();
}