old mode 100644
new mode 100755
 |  |  | 
 |  |  | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | 
 |  |  | import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; | 
 |  |  | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; | 
 |  |  | import com.google.common.primitives.Bytes; | 
 |  |  | import gov.nist.javax.sip.message.SIPRequest; | 
 |  |  | import gov.nist.javax.sip.message.SIPResponse; | 
 |  |  | import org.apache.commons.lang3.ArrayUtils; | 
 |  |  | 
 |  |  |       try { | 
 |  |  |          return SipFactory.getInstance().createHeaderFactory(); | 
 |  |  |       } catch (PeerUnavailableException e) { | 
 |  |  |          e.printStackTrace(); | 
 |  |  |          logger.error("未处理的异常 ", e); | 
 |  |  |       } | 
 |  |  |       return null; | 
 |  |  |    } | 
 |  |  | 
 |  |  |       try { | 
 |  |  |          return SipFactory.getInstance().createMessageFactory(); | 
 |  |  |       } catch (PeerUnavailableException e) { | 
 |  |  |          e.printStackTrace(); | 
 |  |  |          logger.error("未处理的异常 ", e); | 
 |  |  |       } | 
 |  |  |       return null; | 
 |  |  |    } | 
 |  |  | 
 |  |  |             result.add(rawContent[i]); | 
 |  |  |          } | 
 |  |  |       } | 
 |  |  |       Byte[] bytes = new Byte[0]; | 
 |  |  |       byte[] bytesResult = ArrayUtils.toPrimitive(result.toArray(bytes)); | 
 |  |  |       byte[] bytesResult = Bytes.toArray(result); | 
 |  |  |  | 
 |  |  |       Document xml = reader.read(new ByteArrayInputStream(bytesResult)); | 
 |  |  |       Document xml; | 
 |  |  |       try { | 
 |  |  |          xml = reader.read(new ByteArrayInputStream(bytesResult)); | 
 |  |  |       }catch (DocumentException e) { | 
 |  |  |          logger.warn("[xml解析异常]: 原文如下: \r\n{}", new String(bytesResult)); | 
 |  |  |          logger.warn("[xml解析异常]: 原文如下: 尝试兼容性处理"); | 
 |  |  |          String[] xmlLineArray = new String(bytesResult).split("\\r?\\n"); | 
 |  |  |  | 
 |  |  |          // 兼容海康的address字段带有<破换xml结构导致无法解析xml的问题 | 
 |  |  |          StringBuilder stringBuilder = new StringBuilder(); | 
 |  |  |          for (String s : xmlLineArray) { | 
 |  |  |             if (s.startsWith("<Address")) { | 
 |  |  |                continue; | 
 |  |  |             } | 
 |  |  |             stringBuilder.append(s); | 
 |  |  |          } | 
 |  |  |          xml = reader.read(new ByteArrayInputStream(stringBuilder.toString().getBytes())); | 
 |  |  |       } | 
 |  |  |       return xml.getRootElement(); | 
 |  |  |    } | 
 |  |  |  |