修复message和sip消息超时未回复的判断机制
This commit is contained in:
@@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
|
||||
@@ -230,7 +231,7 @@ public interface ISIPCommander {
|
||||
/**
|
||||
* 设备配置命令:basicParam
|
||||
*/
|
||||
void deviceBasicConfigCmd(Device device, BasicParam basicParam, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
|
||||
void deviceBasicConfigCmd(Device device, BasicParam basicParam, ErrorCallback<String> callback) throws InvalidArgumentException, SipException, ParseException;
|
||||
|
||||
/**
|
||||
* 查询设备状态
|
||||
@@ -286,7 +287,7 @@ public interface ISIPCommander {
|
||||
* @param channelId 通道编码(可选)
|
||||
* @param configType 配置类型:
|
||||
*/
|
||||
void deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException;
|
||||
void deviceConfigQuery(Device device, String channelId, String configType, ErrorCallback<Object> callback) throws InvalidArgumentException, SipException, ParseException;
|
||||
|
||||
/**
|
||||
* 查询设备预置位置
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.InviteSessionType;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
@@ -871,7 +870,7 @@ public class SIPCommander implements ISIPCommander {
|
||||
* 设备配置命令:basicParam
|
||||
*/
|
||||
@Override
|
||||
public void deviceBasicConfigCmd(Device device, BasicParam basicParam, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
||||
public void deviceBasicConfigCmd(Device device, BasicParam basicParam, ErrorCallback<String> callback) throws InvalidArgumentException, SipException, ParseException {
|
||||
|
||||
int sn = (int) ((Math.random() * 9 + 1) * 100000);
|
||||
String cmdType = "DeviceConfig";
|
||||
@@ -904,21 +903,14 @@ public class SIPCommander implements ISIPCommander {
|
||||
cmdXml.append("</BasicParam>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
ErrorCallback<String> errorCallback = (code, msg, data) -> {
|
||||
if (code != ErrorCode.SUCCESS.getCode()) {
|
||||
SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>();
|
||||
eventResult.type = SipSubscribe.EventResultType.failedResult;
|
||||
eventResult.msg = msg;
|
||||
eventResult.statusCode = code;
|
||||
errorEvent.response(eventResult);
|
||||
}
|
||||
};
|
||||
|
||||
MessageEvent<String> messageEvent = MessageEvent.getInstance(cmdType, sn + "", channelId, 1000L, errorCallback);
|
||||
MessageEvent<String> messageEvent = MessageEvent.getInstance(cmdType, sn + "", channelId, 1000L, callback);
|
||||
messageSubscribe.addSubscribe(messageEvent);
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, eventResult -> {
|
||||
callback.run(ErrorCode.ERROR100.getCode(), "消息发送失败", null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1095,14 +1087,16 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param configType 配置类型:
|
||||
*/
|
||||
@Override
|
||||
public void deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
||||
public void deviceConfigQuery(Device device, String channelId, String configType, ErrorCallback<Object> callback) throws InvalidArgumentException, SipException, ParseException {
|
||||
|
||||
String cmdType = "ConfigDownload";
|
||||
int sn = (int) ((Math.random() * 9 + 1) * 100000);
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
String charset = device.getCharset();
|
||||
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
||||
cmdXml.append("<Query>\r\n");
|
||||
cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
||||
cmdXml.append("<CmdType>" + cmdType + "</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + sn + "</SN>\r\n");
|
||||
if (ObjectUtils.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
@@ -1111,10 +1105,13 @@ public class SIPCommander implements ISIPCommander {
|
||||
cmdXml.append("<ConfigType>" + configType + "</ConfigType>\r\n");
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
|
||||
MessageEvent<Object> messageEvent = MessageEvent.getInstance(cmdType, sn + "", channelId, 1000L, callback);
|
||||
messageSubscribe.addSubscribe(messageEvent);
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
||||
sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, eventResult -> {
|
||||
callback.run(ErrorCode.ERROR100.getCode(), "消息发送失败", null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.respon
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.event.MessageSubscribe;
|
||||
import com.genersoft.iot.vmp.gb28181.event.sip.MessageEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageRequestProcessor;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
@@ -44,18 +43,16 @@ public class ResponseMessageHandler extends MessageHandlerAbstract implements In
|
||||
|
||||
public void handMessageEvent(Element element, Object data) {
|
||||
String cmd = getText(element, "CmdType");
|
||||
IMessageHandler messageHandler = messageHandlerMap.get(cmd);
|
||||
if (messageHandler == null) {
|
||||
String sn = getText(element, "SN");
|
||||
MessageEvent<Object> subscribe = (MessageEvent<Object>)messageSubscribe.getSubscribe(cmd + sn);
|
||||
if (subscribe != null) {
|
||||
String result = getText(element, "Result");
|
||||
if ("OK".equalsIgnoreCase(result)) {
|
||||
subscribe.getCallback().run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), data);
|
||||
}else {
|
||||
subscribe.getCallback().run(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg(), result);
|
||||
}
|
||||
String sn = getText(element, "SN");
|
||||
MessageEvent<Object> subscribe = (MessageEvent<Object>)messageSubscribe.getSubscribe(cmd + sn);
|
||||
if (subscribe != null) {
|
||||
String result = getText(element, "Result");
|
||||
if (result == null || "OK".equalsIgnoreCase(result) || data != null) {
|
||||
subscribe.getCallback().run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), data);
|
||||
}else {
|
||||
subscribe.getCallback().run(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg(), result);
|
||||
}
|
||||
messageSubscribe.removeSubscribe(cmd + sn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,10 @@ import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Platform;
|
||||
import com.genersoft.iot.vmp.gb28181.service.IDeviceService;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dom4j.Element;
|
||||
@@ -24,8 +22,6 @@ import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
import java.text.ParseException;
|
||||
|
||||
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ConfigDownloadResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {
|
||||
@@ -49,8 +45,6 @@ public class ConfigDownloadResponseMessageHandler extends SIPRequestProcessorPar
|
||||
|
||||
@Override
|
||||
public void handForDevice(RequestEvent evt, Device device, Element element) {
|
||||
String channelId = getText(element, "DeviceID");
|
||||
|
||||
try {
|
||||
// 回复200 OK
|
||||
responseAck((SIPRequest) evt.getRequest(), Response.OK);
|
||||
@@ -63,17 +57,33 @@ public class ConfigDownloadResponseMessageHandler extends SIPRequestProcessorPar
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(json.toJSONString());
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (json.get("BasicParam") != null) {
|
||||
jsonObject.put("BasicParam", json.getJSONObject("BasicParam"));
|
||||
}
|
||||
if (json.get("VideoParamOpt") != null) {
|
||||
jsonObject.put("VideoParamOpt", json.getJSONObject("VideoParamOpt"));
|
||||
}
|
||||
if (json.get("SVACEncodeConfig") != null) {
|
||||
jsonObject.put("SVACEncodeConfig", json.getJSONObject("SVACEncodeConfig"));
|
||||
}
|
||||
if (json.get("SVACDecodeConfig") != null) {
|
||||
jsonObject.put("SVACDecodeConfig", json.getJSONObject("SVACDecodeConfig"));
|
||||
}
|
||||
|
||||
responseMessageHandler.handMessageEvent(element, jsonObject);
|
||||
|
||||
JSONObject basicParam = json.getJSONObject("BasicParam");
|
||||
Integer heartBeatInterval = basicParam.getInteger("HeartBeatInterval");
|
||||
Integer heartBeatCount = basicParam.getInteger("HeartBeatCount");
|
||||
Integer positionCapability = basicParam.getInteger("PositionCapability");
|
||||
device.setHeartBeatInterval(heartBeatInterval);
|
||||
device.setHeartBeatCount(heartBeatCount);
|
||||
device.setPositionCapability(positionCapability);
|
||||
|
||||
deviceService.updateDeviceHeartInfo(device);
|
||||
responseMessageHandler.handMessageEvent(element, basicParam);
|
||||
if (basicParam != null) {
|
||||
Integer heartBeatInterval = basicParam.getInteger("HeartBeatInterval");
|
||||
Integer heartBeatCount = basicParam.getInteger("HeartBeatCount");
|
||||
Integer positionCapability = basicParam.getInteger("PositionCapability");
|
||||
device.setHeartBeatInterval(heartBeatInterval);
|
||||
device.setHeartBeatCount(heartBeatCount);
|
||||
device.setPositionCapability(positionCapability);
|
||||
|
||||
deviceService.updateDeviceHeartInfo(device);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,19 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
import gov.nist.javax.sip.message.SIPRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Response;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText;
|
||||
|
||||
@@ -39,6 +45,12 @@ public class DeviceConfigResponseMessageHandler extends SIPRequestProcessorParen
|
||||
@Override
|
||||
public void handForDevice(RequestEvent evt, Device device, Element element) {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
// 回复200 OK
|
||||
responseAck((SIPRequest) evt.getRequest(), Response.OK);
|
||||
} catch (SipException | InvalidArgumentException | ParseException e) {
|
||||
log.error("[命令发送失败] 设备配置查询: {}", e.getMessage());
|
||||
}
|
||||
XmlUtil.node2Json(element, json);
|
||||
String channelId = getText(element, "DeviceID");
|
||||
if (log.isDebugEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user