mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 00:45:55 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -12,6 +12,7 @@ import org.dom4j.Element;
|
|||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.sip.*;
|
import javax.sip.*;
|
||||||
import javax.sip.header.FromHeader;
|
import javax.sip.header.FromHeader;
|
||||||
@@ -105,15 +106,18 @@ public abstract class ReqAbstractHandler {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element getRootElement(RequestEvent evt) throws DocumentException {
|
public Element getRootElement(RequestEvent evt) throws DocumentException, SAXException {
|
||||||
return getRootElement(evt, "gb2312");
|
return getRootElement(evt, "gb2312");
|
||||||
}
|
}
|
||||||
public Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
|
public Element getRootElement(RequestEvent evt, String charset) throws DocumentException, SAXException {
|
||||||
if (charset == null) {
|
if (charset == null) {
|
||||||
charset = "gb2312";
|
charset = "gb2312";
|
||||||
}
|
}
|
||||||
Request request = evt.getRequest();
|
Request request = evt.getRequest();
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
|
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
|
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
|
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
reader.setEncoding(charset);
|
reader.setEncoding(charset);
|
||||||
// 对海康出现的未转义字符做处理。
|
// 对海康出现的未转义字符做处理。
|
||||||
String[] destStrArray = new String[]{"<",">","&","'","""};
|
String[] destStrArray = new String[]{"<",">","&","'","""};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.fastbee.sip.server.IGBListener;
|
|||||||
import com.fastbee.sip.service.ISipDeviceService;
|
import com.fastbee.sip.service.ISipDeviceService;
|
||||||
import com.fastbee.sip.util.SipUtil;
|
import com.fastbee.sip.util.SipUtil;
|
||||||
import gov.nist.javax.sip.message.SIPRequest;
|
import gov.nist.javax.sip.message.SIPRequest;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
@@ -85,7 +86,7 @@ public class MessageRequestProcessor extends ReqAbstractHandler implements Initi
|
|||||||
log.warn("SIP 回复错误", e);
|
log.warn("SIP 回复错误", e);
|
||||||
} catch (InvalidArgumentException e) {
|
} catch (InvalidArgumentException e) {
|
||||||
log.warn("参数无效", e);
|
log.warn("参数无效", e);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException | SAXException e) {
|
||||||
log.warn("SIP回复时解析异常", e);
|
log.warn("SIP回复时解析异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.sip.InvalidArgumentException;
|
import javax.sip.InvalidArgumentException;
|
||||||
import javax.sip.RequestEvent;
|
import javax.sip.RequestEvent;
|
||||||
@@ -68,7 +69,7 @@ public class KeepaliveHandler extends ReqAbstractHandler implements Initializing
|
|||||||
responseAck(evt);
|
responseAck(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
} catch (ParseException | SipException | InvalidArgumentException | DocumentException | SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.sip.InvalidArgumentException;
|
import javax.sip.InvalidArgumentException;
|
||||||
import javax.sip.RequestEvent;
|
import javax.sip.RequestEvent;
|
||||||
@@ -199,7 +200,7 @@ public class CatalogHandler extends ReqAbstractHandler implements InitializingBe
|
|||||||
responseAck(evt);
|
responseAck(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
} catch (ParseException | SipException | InvalidArgumentException | DocumentException | SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.sip.InvalidArgumentException;
|
import javax.sip.InvalidArgumentException;
|
||||||
import javax.sip.RequestEvent;
|
import javax.sip.RequestEvent;
|
||||||
@@ -48,7 +49,7 @@ public class DeviceInfoHandler extends ReqAbstractHandler implements Initializin
|
|||||||
// 回复200 OK
|
// 回复200 OK
|
||||||
responseAck(evt);
|
responseAck(evt);
|
||||||
|
|
||||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
} catch (DocumentException | SipException | InvalidArgumentException | ParseException | SAXException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.dom4j.Document;
|
|||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.sip.RequestEvent;
|
import javax.sip.RequestEvent;
|
||||||
import javax.sip.message.Request;
|
import javax.sip.message.Request;
|
||||||
@@ -19,22 +20,20 @@ public class XmlUtil {
|
|||||||
/**
|
/**
|
||||||
* 解析XML为Document对象
|
* 解析XML为Document对象
|
||||||
*
|
*
|
||||||
* @param xml
|
* @param xml 被解析的XMl
|
||||||
* 被解析的XMl
|
|
||||||
* @return Document
|
* @return Document
|
||||||
*/
|
*/
|
||||||
public static Element parseXml(String xml)
|
public static Element parseXml(String xml) {
|
||||||
{
|
|
||||||
Document document = null;
|
Document document = null;
|
||||||
//
|
//
|
||||||
StringReader sr = new StringReader(xml);
|
StringReader sr = new StringReader(xml);
|
||||||
SAXReader saxReader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
try
|
try {
|
||||||
{
|
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
document = saxReader.read(sr);
|
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
}
|
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
catch (DocumentException e)
|
document = reader.read(sr);
|
||||||
{
|
} catch (DocumentException | SAXException e) {
|
||||||
log.error("解析失败", e);
|
log.error("解析失败", e);
|
||||||
}
|
}
|
||||||
return null == document ? null : document.getRootElement();
|
return null == document ? null : document.getRootElement();
|
||||||
@@ -43,16 +42,12 @@ public class XmlUtil {
|
|||||||
/**
|
/**
|
||||||
* 获取element对象的text的值
|
* 获取element对象的text的值
|
||||||
*
|
*
|
||||||
* @param em
|
* @param em 节点的对象
|
||||||
* 节点的对象
|
* @param tag 节点的tag
|
||||||
* @param tag
|
|
||||||
* 节点的tag
|
|
||||||
* @return 节点
|
* @return 节点
|
||||||
*/
|
*/
|
||||||
public static String getText(Element em, String tag)
|
public static String getText(Element em, String tag) {
|
||||||
{
|
if (null == em) {
|
||||||
if (null == em)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Element e = em.element(tag);
|
Element e = em.element(tag);
|
||||||
@@ -63,16 +58,12 @@ public class XmlUtil {
|
|||||||
/**
|
/**
|
||||||
* 递归解析xml节点,适用于 多节点数据
|
* 递归解析xml节点,适用于 多节点数据
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node node
|
||||||
* node
|
* @param nodeName nodeName
|
||||||
* @param nodeName
|
* @return List<Map < String, Object>>
|
||||||
* nodeName
|
|
||||||
* @return List<Map<String, Object>>
|
|
||||||
*/
|
*/
|
||||||
public static List<Map<String, Object>> listNodes(Element node, String nodeName)
|
public static List<Map<String, Object>> listNodes(Element node, String nodeName) {
|
||||||
{
|
if (null == node) {
|
||||||
if (null == node)
|
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 初始化返回
|
// 初始化返回
|
||||||
@@ -82,12 +73,9 @@ public class XmlUtil {
|
|||||||
|
|
||||||
Map<String, Object> map = null;
|
Map<String, Object> map = null;
|
||||||
// 遍历属性节点
|
// 遍历属性节点
|
||||||
for (Attribute attribute : list)
|
for (Attribute attribute : list) {
|
||||||
{
|
if (nodeName.equals(node.getName())) {
|
||||||
if (nodeName.equals(node.getName()))
|
if (null == map) {
|
||||||
{
|
|
||||||
if (null == map)
|
|
||||||
{
|
|
||||||
map = new HashMap<String, Object>();
|
map = new HashMap<String, Object>();
|
||||||
listMap.add(map);
|
listMap.add(map);
|
||||||
}
|
}
|
||||||
@@ -99,17 +87,19 @@ public class XmlUtil {
|
|||||||
// 遍历当前节点下的所有节点 ,nodeName 要解析的节点名称
|
// 遍历当前节点下的所有节点 ,nodeName 要解析的节点名称
|
||||||
// 使用递归
|
// 使用递归
|
||||||
Iterator<Element> iterator = node.elementIterator();
|
Iterator<Element> iterator = node.elementIterator();
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext()) {
|
||||||
{
|
|
||||||
Element e = iterator.next();
|
Element e = iterator.next();
|
||||||
listMap.addAll(listNodes(e, nodeName));
|
listMap.addAll(listNodes(e, nodeName));
|
||||||
}
|
}
|
||||||
return listMap;
|
return listMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Element getRootElement(RequestEvent evt) throws DocumentException {
|
public static Element getRootElement(RequestEvent evt) throws DocumentException, SAXException {
|
||||||
Request request = evt.getRequest();
|
Request request = evt.getRequest();
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
|
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
|
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
|
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
reader.setEncoding("gbk");
|
reader.setEncoding("gbk");
|
||||||
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
|
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
|
||||||
return xml.getRootElement();
|
return xml.getRootElement();
|
||||||
|
|||||||
Reference in New Issue
Block a user