Commit e163cf4d202e7fe8fb35e29999eeb53e4f525a71
1 parent
61e52261
兼容海康平台在address字段使用错误的<或>破坏xml结构的情况, #903
Showing
1 changed file
with
18 additions
and
1 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/SIPRequestProcessorParent.java
| @@ -199,7 +199,24 @@ public abstract class SIPRequestProcessorParent { | @@ -199,7 +199,24 @@ public abstract class SIPRequestProcessorParent { | ||
| 199 | Byte[] bytes = new Byte[0]; | 199 | Byte[] bytes = new Byte[0]; |
| 200 | byte[] bytesResult = ArrayUtils.toPrimitive(result.toArray(bytes)); | 200 | byte[] bytesResult = ArrayUtils.toPrimitive(result.toArray(bytes)); |
| 201 | 201 | ||
| 202 | - Document xml = reader.read(new ByteArrayInputStream(bytesResult)); | 202 | + Document xml; |
| 203 | + try { | ||
| 204 | + xml = reader.read(new ByteArrayInputStream(bytesResult)); | ||
| 205 | + }catch (DocumentException e) { | ||
| 206 | + logger.warn("[xml解析异常]: 愿文如下: \r\n{}", new String(bytesResult)); | ||
| 207 | + logger.warn("[xml解析异常]: 愿文如下: 尝试兼容性处理"); | ||
| 208 | + String[] xmlLineArray = new String(bytesResult).split("\\r?\\n"); | ||
| 209 | + | ||
| 210 | + // 兼容海康的address字段带有<破换xml结构导致无法解析xml的问题 | ||
| 211 | + StringBuilder stringBuilder = new StringBuilder(); | ||
| 212 | + for (String s : xmlLineArray) { | ||
| 213 | + if (s.startsWith("<Address")) { | ||
| 214 | + continue; | ||
| 215 | + } | ||
| 216 | + stringBuilder.append(s); | ||
| 217 | + } | ||
| 218 | + xml = reader.read(new ByteArrayInputStream(stringBuilder.toString().getBytes())); | ||
| 219 | + } | ||
| 203 | return xml.getRootElement(); | 220 | return xml.getRootElement(); |
| 204 | } | 221 | } |
| 205 | 222 |