修复WVP作为下级平台接受deviceControl指令的问题-修复指令响应

pull/741/head
gaofw189 2023-02-06 10:35:32 +08:00
parent 40ece192fe
commit 25fca14e62
5 changed files with 82 additions and 73 deletions

View File

@ -47,61 +47,65 @@ public class SIPSender {
} }
public void transmitRequest(String ip, Message message, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws SipException, ParseException { public void transmitRequest(String ip, Message message, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws SipException, ParseException {
ViaHeader viaHeader = (ViaHeader)message.getHeader(ViaHeader.NAME); try {
String transport = "UDP"; ViaHeader viaHeader = (ViaHeader)message.getHeader(ViaHeader.NAME);
if (viaHeader == null) { String transport = "UDP";
logger.warn("[消息头缺失] ViaHeader 使用默认的UDP方式处理数据"); if (viaHeader == null) {
}else { logger.warn("[消息头缺失] ViaHeader 使用默认的UDP方式处理数据");
transport = viaHeader.getTransport(); }else {
} transport = viaHeader.getTransport();
if (message.getHeader(UserAgentHeader.NAME) == null) {
try {
message.addHeader(SipUtils.createUserAgentHeader(sipLayer.getSipFactory(), gitUtil));
} catch (ParseException e) {
logger.error("添加UserAgentHeader失败", e);
} }
} if (message.getHeader(UserAgentHeader.NAME) == null) {
try {
CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME); message.addHeader(SipUtils.createUserAgentHeader(sipLayer.getSipFactory(), gitUtil));
// 添加错误订阅 } catch (ParseException e) {
if (errorEvent != null) { logger.error("添加UserAgentHeader失败", e);
sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> { }
errorEvent.response(eventResult);
sipSubscribe.removeErrorSubscribe(eventResult.callId);
sipSubscribe.removeOkSubscribe(eventResult.callId);
}));
}
// 添加订阅
if (okEvent != null) {
sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult -> {
okEvent.response(eventResult);
sipSubscribe.removeOkSubscribe(eventResult.callId);
sipSubscribe.removeErrorSubscribe(eventResult.callId);
});
}
if ("TCP".equals(transport)) {
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
if (tcpSipProvider == null) {
logger.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
tcpSipProvider.sendRequest((Request)message);
}else if (message instanceof Response) {
tcpSipProvider.sendResponse((Response)message);
} }
} else if ("UDP".equals(transport)) { CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME);
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip); // 添加错误订阅
if (sipProvider == null) { if (errorEvent != null) {
logger.error("[发送信息失败] 未找到udp://{}的监听信息", ip); sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> {
return; errorEvent.response(eventResult);
sipSubscribe.removeErrorSubscribe(eventResult.callId);
sipSubscribe.removeOkSubscribe(eventResult.callId);
}));
} }
if (message instanceof Request) { // 添加订阅
sipProvider.sendRequest((Request)message); if (okEvent != null) {
}else if (message instanceof Response) { sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult -> {
sipProvider.sendResponse((Response)message); okEvent.response(eventResult);
sipSubscribe.removeOkSubscribe(eventResult.callId);
sipSubscribe.removeErrorSubscribe(eventResult.callId);
});
} }
if ("TCP".equals(transport)) {
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
if (tcpSipProvider == null) {
logger.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
tcpSipProvider.sendRequest((Request)message);
}else if (message instanceof Response) {
tcpSipProvider.sendResponse((Response)message);
}
} else if ("UDP".equals(transport)) {
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip);
if (sipProvider == null) {
logger.error("[发送信息失败] 未找到udp://{}的监听信息", ip);
return;
}
if (message instanceof Request) {
sipProvider.sendRequest((Request)message);
}else if (message instanceof Response) {
sipProvider.sendResponse((Response)message);
}
}
} finally {
logger.info("[SEND]:SUCCESS:{}", message);
} }
} }

View File

@ -183,7 +183,7 @@ public interface ISIPCommander {
* @param channelId * @param channelId
* @param recordCmdStr Record / StopRecord * @param recordCmdStr Record / StopRecord
*/ */
void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
/** /**
* *
@ -197,7 +197,7 @@ public interface ISIPCommander {
* *
* @param device * @param device
*/ */
void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
/** /**
* *
@ -206,7 +206,7 @@ public interface ISIPCommander {
* @param alarmMethod * @param alarmMethod
* @param alarmType * @param alarmType
*/ */
void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException; void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException;
/** /**
* ,IDR * ,IDR

View File

@ -664,7 +664,7 @@ public class SIPCommander implements ISIPCommander {
* @param recordCmdStr Record / StopRecord * @param recordCmdStr Record / StopRecord
*/ */
@Override @Override
public void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { public void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
StringBuffer cmdXml = new StringBuffer(200); StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset(); String charset = device.getCharset();
cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n"); cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
@ -682,7 +682,7 @@ public class SIPCommander implements ISIPCommander {
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport())); 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, errorEvent,okEvent);
} }
/** /**
@ -716,7 +716,7 @@ public class SIPCommander implements ISIPCommander {
* @param guardCmdStr "SetGuard"/"ResetGuard" * @param guardCmdStr "SetGuard"/"ResetGuard"
*/ */
@Override @Override
public void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { public void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
StringBuffer cmdXml = new StringBuffer(200); StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset(); String charset = device.getCharset();
@ -729,7 +729,7 @@ public class SIPCommander implements ISIPCommander {
cmdXml.append("</Control>\r\n"); cmdXml.append("</Control>\r\n");
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport())); 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, errorEvent,okEvent);
} }
/** /**
@ -738,7 +738,7 @@ public class SIPCommander implements ISIPCommander {
* @param device * @param device
*/ */
@Override @Override
public void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException { public void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
StringBuffer cmdXml = new StringBuffer(200); StringBuffer cmdXml = new StringBuffer(200);
String charset = device.getCharset(); String charset = device.getCharset();
@ -765,7 +765,7 @@ public class SIPCommander implements ISIPCommander {
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport())); 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, errorEvent,okEvent);
} }
/** /**

View File

@ -131,16 +131,16 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
handleRecordCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.RECORD); handleRecordCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.RECORD);
break; break;
case I_FRAME: case I_FRAME:
handleIFameCmd(deviceForPlatform,channelId); handleIFameCmd(deviceForPlatform,request,channelId);
break; break;
case TELE_BOOT: case TELE_BOOT:
handleTeleBootCmd(deviceForPlatform); handleTeleBootCmd(deviceForPlatform,request);
break; break;
case DRAG_ZOOM_IN: case DRAG_ZOOM_IN:
handleDragZoom(deviceForPlatform,channelId,rootElement,DeviceControlType.DRAG_ZOOM_IN); handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_IN);
break; break;
case DRAG_ZOOM_OUT: case DRAG_ZOOM_OUT:
handleDragZoom(deviceForPlatform,channelId,rootElement,DeviceControlType.DRAG_ZOOM_OUT); handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_OUT);
break; break;
case HOME_POSITION: case HOME_POSITION:
handleHomePositionCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.HOME_POSITION); handleHomePositionCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.HOME_POSITION);
@ -167,7 +167,6 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 云台/前端: {}", e.getMessage()); logger.error("[命令发送失败] 云台/前端: {}", e.getMessage());
} }
} }
/** /**
@ -175,9 +174,10 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
* @param device * @param device
* @param channelId id * @param channelId id
*/ */
private void handleIFameCmd(Device device,String channelId){ private void handleIFameCmd(Device device,SIPRequest request,String channelId){
try { try {
cmder.iFrameCmd(device,channelId); cmder.iFrameCmd(device,channelId);
responseAck(request, Response.OK);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 强制关键帧: {}", e.getMessage()); logger.error("[命令发送失败] 强制关键帧: {}", e.getMessage());
} }
@ -187,9 +187,10 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
* *
* @param device * @param device
*/ */
private void handleTeleBootCmd(Device device){ private void handleTeleBootCmd(Device device,SIPRequest request){
try { try {
cmder.teleBootCmd(device); cmder.teleBootCmd(device);
responseAck(request, Response.OK);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 重启: {}", e.getMessage()); logger.error("[命令发送失败] 重启: {}", e.getMessage());
} }
@ -203,7 +204,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
* @param rootElement * @param rootElement
* @param type * @param type
*/ */
private void handleDragZoom(Device device,String channelId,Element rootElement,DeviceControlType type){ private void handleDragZoom(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement,type.getVal());
StringBuffer cmdXml = new StringBuffer(200); StringBuffer cmdXml = new StringBuffer(200);
cmdXml.append("<" + type.getVal() + ">\r\n"); cmdXml.append("<" + type.getVal() + ">\r\n");
@ -211,6 +212,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
cmdXml.append("</" + type.getVal() + ">\r\n"); cmdXml.append("</" + type.getVal() + ">\r\n");
try { try {
cmder.dragZoomCmd(device,channelId,cmdXml.toString()); cmder.dragZoomCmd(device,channelId,cmdXml.toString());
responseAck(request, Response.OK);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 拉框控制: {}", e.getMessage()); logger.error("[命令发送失败] 拉框控制: {}", e.getMessage());
} }
@ -255,7 +257,8 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
} }
try { try {
cmder.alarmCmd(device, alarmMethod,alarmType, cmder.alarmCmd(device, alarmMethod,alarmType,
errorResult -> onError(request,errorResult)); errorResult -> onError(request,errorResult),
okResult -> onOk(request,okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 告警消息: {}", e.getMessage()); logger.error("[命令发送失败] 告警消息: {}", e.getMessage());
} }
@ -274,7 +277,8 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement,type.getVal());
try { try {
cmder.recordCmd(device, channelId,cmdString, cmder.recordCmd(device, channelId,cmdString,
errorResult -> onError(request,errorResult)); errorResult -> onError(request,errorResult),
okResult -> onOk(request,okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 录像控制: {}", e.getMessage()); logger.error("[命令发送失败] 录像控制: {}", e.getMessage());
} }
@ -292,7 +296,8 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
String cmdString = getText(rootElement,type.getVal()); String cmdString = getText(rootElement,type.getVal());
try { try {
cmder.guardCmd(device, cmdString, cmder.guardCmd(device, cmdString,
errorResult -> onError(request,errorResult)); errorResult -> onError(request,errorResult),
okResult -> onOk(request,okResult));
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 布防/撤防命令: {}", e.getMessage()); logger.error("[命令发送失败] 布防/撤防命令: {}", e.getMessage());
} }

View File

@ -110,7 +110,7 @@ public class DeviceControl {
msg.setKey(key); msg.setKey(key);
msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg)); msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg));
resultHolder.invokeAllResult(msg); resultHolder.invokeAllResult(msg);
}); },null);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 开始/停止录像: {}", e.getMessage()); logger.error("[命令发送失败] 开始/停止录像: {}", e.getMessage());
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
@ -143,7 +143,7 @@ public class DeviceControl {
msg.setKey(key); msg.setKey(key);
msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg)); msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg));
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
}); },null);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 布防/撤防操作: {}", e.getMessage()); logger.error("[命令发送失败] 布防/撤防操作: {}", e.getMessage());
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage());
@ -192,7 +192,7 @@ public class DeviceControl {
msg.setKey(key); msg.setKey(key);
msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg)); msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg));
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
}); },null);
} catch (InvalidArgumentException | SipException | ParseException e) { } catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[命令发送失败] 报警复位: {}", e.getMessage()); logger.error("[命令发送失败] 报警复位: {}", e.getMessage());
throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());