mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-25 06:27:50 +08:00
强化消息发送失败的处理
This commit is contained in:
parent
d7ba1cab30
commit
9903f25cc1
@ -1,27 +1,16 @@
|
|||||||
package com.genersoft.iot.vmp.gb28181.bean;
|
package com.genersoft.iot.vmp.gb28181.bean;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.sip.Dialog;
|
import javax.sip.Dialog;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
|
||||||
public class DeviceNotFoundEvent extends EventObject {
|
@Data
|
||||||
|
public class DeviceNotFoundEvent {
|
||||||
|
|
||||||
private String callId;
|
private String callId;
|
||||||
|
|
||||||
/**
|
public DeviceNotFoundEvent(String callId) {
|
||||||
* Constructs a prototypical Event.
|
|
||||||
*
|
|
||||||
* @param dialog
|
|
||||||
* @throws IllegalArgumentException if source is null.
|
|
||||||
*/
|
|
||||||
public DeviceNotFoundEvent(Dialog dialog) {
|
|
||||||
super(dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCallId() {
|
|
||||||
return callId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallId(String callId) {
|
|
||||||
this.callId = callId;
|
this.callId = callId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.genersoft.iot.vmp.gb28181.bean;
|
||||||
|
|
||||||
|
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SipSendFailEvent extends SipSubscribe.EventResult<String> {
|
||||||
|
|
||||||
|
private String callId;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
public static SipSendFailEvent getInstance(String callId, String msg){
|
||||||
|
SipSendFailEvent sipSendFailEvent = new SipSendFailEvent();
|
||||||
|
sipSendFailEvent.setMsg(msg);
|
||||||
|
sipSendFailEvent.setCallId(callId);
|
||||||
|
return sipSendFailEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package com.genersoft.iot.vmp.gb28181.event;
|
package com.genersoft.iot.vmp.gb28181.event;
|
||||||
|
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent;
|
import com.genersoft.iot.vmp.gb28181.bean.DeviceNotFoundEvent;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.bean.SipSendFailEvent;
|
||||||
import com.genersoft.iot.vmp.gb28181.event.sip.SipEvent;
|
import com.genersoft.iot.vmp.gb28181.event.sip.SipEvent;
|
||||||
import gov.nist.javax.sip.message.SIPRequest;
|
import gov.nist.javax.sip.message.SIPRequest;
|
||||||
import gov.nist.javax.sip.message.SIPResponse;
|
import gov.nist.javax.sip.message.SIPResponse;
|
||||||
@ -83,17 +84,17 @@ public class SipSubscribe {
|
|||||||
failedResult
|
failedResult
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EventResult<EventObject>{
|
public static class EventResult<T>{
|
||||||
public int statusCode;
|
public int statusCode;
|
||||||
public EventResultType type;
|
public EventResultType type;
|
||||||
public String msg;
|
public String msg;
|
||||||
public String callId;
|
public String callId;
|
||||||
public EventObject event;
|
public T event;
|
||||||
|
|
||||||
public EventResult() {
|
public EventResult() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventResult(EventObject event) {
|
public EventResult(T event) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
if (event instanceof ResponseEvent) {
|
if (event instanceof ResponseEvent) {
|
||||||
ResponseEvent responseEvent = (ResponseEvent)event;
|
ResponseEvent responseEvent = (ResponseEvent)event;
|
||||||
@ -149,6 +150,12 @@ public class SipSubscribe {
|
|||||||
this.msg = "设备未找到";
|
this.msg = "设备未找到";
|
||||||
this.statusCode = -1024;
|
this.statusCode = -1024;
|
||||||
this.callId = ((DeviceNotFoundEvent) event).getCallId();
|
this.callId = ((DeviceNotFoundEvent) event).getCallId();
|
||||||
|
}else if (event instanceof SipSendFailEvent) {
|
||||||
|
SipSendFailEvent sipSendFailEvent = (SipSendFailEvent) event;
|
||||||
|
this.type = EventResultType.deviceNotFoundEvent;
|
||||||
|
this.msg = sipSendFailEvent.getMsg();
|
||||||
|
this.statusCode = -1024;
|
||||||
|
this.callId = ((SipSendFailEvent) event).getCallId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -293,7 +293,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
log.info("[移除移动位置订阅]失败,设备已经离线 : {}", device.getDeviceId());
|
log.info("[移除目录订阅订阅]失败,设备已经离线 : {}", device.getDeviceId());
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.run(false);
|
callback.run(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit;
|
|||||||
|
|
||||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||||
import com.genersoft.iot.vmp.gb28181.SipLayer;
|
import com.genersoft.iot.vmp.gb28181.SipLayer;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.bean.SipSendFailEvent;
|
||||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||||
import com.genersoft.iot.vmp.gb28181.event.sip.SipEvent;
|
import com.genersoft.iot.vmp.gb28181.event.sip.SipEvent;
|
||||||
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
|
||||||
@ -12,6 +13,7 @@ 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 javax.sip.ResponseEvent;
|
||||||
import javax.sip.SipException;
|
import javax.sip.SipException;
|
||||||
import javax.sip.header.CSeqHeader;
|
import javax.sip.header.CSeqHeader;
|
||||||
import javax.sip.header.CallIdHeader;
|
import javax.sip.header.CallIdHeader;
|
||||||
@ -70,10 +72,10 @@ public class SIPSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME);
|
||||||
|
CSeqHeader cSeqHeader = (CSeqHeader) message.getHeader(CSeqHeader.NAME);
|
||||||
|
String key = callIdHeader.getCallId() + cSeqHeader.getSeqNumber();
|
||||||
if (okEvent != null || errorEvent != null) {
|
if (okEvent != null || errorEvent != null) {
|
||||||
CallIdHeader callIdHeader = (CallIdHeader) message.getHeader(CallIdHeader.NAME);
|
|
||||||
CSeqHeader cSeqHeader = (CSeqHeader) message.getHeader(CSeqHeader.NAME);
|
|
||||||
String key = callIdHeader.getCallId() + cSeqHeader.getSeqNumber();
|
|
||||||
SipEvent sipEvent = SipEvent.getInstance(key, eventResult -> {
|
SipEvent sipEvent = SipEvent.getInstance(key, eventResult -> {
|
||||||
sipSubscribe.removeSubscribe(key);
|
sipSubscribe.removeSubscribe(key);
|
||||||
if(okEvent != null) {
|
if(okEvent != null) {
|
||||||
@ -87,31 +89,40 @@ public class SIPSender {
|
|||||||
}), timeout == null ? sipConfig.getTimeout() : timeout);
|
}), timeout == null ? sipConfig.getTimeout() : timeout);
|
||||||
sipSubscribe.addSubscribe(key, sipEvent);
|
sipSubscribe.addSubscribe(key, sipEvent);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if ("TCP".equals(transport)) {
|
||||||
|
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
|
||||||
|
if (tcpSipProvider == null) {
|
||||||
|
log.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message instanceof Request) {
|
||||||
|
tcpSipProvider.sendRequest((Request) message);
|
||||||
|
} else if (message instanceof Response) {
|
||||||
|
tcpSipProvider.sendResponse((Response) message);
|
||||||
|
}
|
||||||
|
|
||||||
if ("TCP".equals(transport)) {
|
} else if ("UDP".equals(transport)) {
|
||||||
SipProviderImpl tcpSipProvider = sipLayer.getTcpSipProvider(ip);
|
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip);
|
||||||
if (tcpSipProvider == null) {
|
if (sipProvider == null) {
|
||||||
log.error("[发送信息失败] 未找到tcp://{}的监听信息", ip);
|
log.error("[发送信息失败] 未找到udp://{}的监听信息", ip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message instanceof Request) {
|
if (message instanceof Request) {
|
||||||
tcpSipProvider.sendRequest((Request) message);
|
sipProvider.sendRequest((Request) message);
|
||||||
} else if (message instanceof Response) {
|
} else if (message instanceof Response) {
|
||||||
tcpSipProvider.sendResponse((Response) message);
|
sipProvider.sendResponse((Response) message);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("UDP".equals(transport)) {
|
|
||||||
SipProviderImpl sipProvider = sipLayer.getUdpSipProvider(ip);
|
|
||||||
if (sipProvider == null) {
|
|
||||||
log.error("[发送信息失败] 未找到udp://{}的监听信息", ip);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (message instanceof Request) {
|
|
||||||
sipProvider.sendRequest((Request) message);
|
|
||||||
} else if (message instanceof Response) {
|
|
||||||
sipProvider.sendResponse((Response) message);
|
|
||||||
}
|
}
|
||||||
|
}catch (SipException e) {
|
||||||
|
log.error("[发送信息失败] ", e);
|
||||||
|
SipSendFailEvent sipSendFailEvent = SipSendFailEvent.getInstance(callIdHeader.getCallId(), e.getMessage());
|
||||||
|
SipSubscribe.EventResult<SipSendFailEvent> eventResult = new SipSubscribe.EventResult<>(sipSendFailEvent);
|
||||||
|
SipEvent subscribe = sipSubscribe.getSubscribe(key);
|
||||||
|
subscribe.getErrorEvent().response(eventResult);
|
||||||
|
sipSubscribe.removeSubscribe(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallIdHeader getNewCallIdHeader(String ip, String transport) {
|
public CallIdHeader getNewCallIdHeader(String ip, String transport) {
|
||||||
|
|||||||
@ -98,8 +98,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
|||||||
log.warn("[设备未找到 ]deviceId: {}, callId: {}", deviceId, callIdHeader.getCallId());
|
log.warn("[设备未找到 ]deviceId: {}, callId: {}", deviceId, callIdHeader.getCallId());
|
||||||
SipEvent sipEvent = sipSubscribe.getSubscribe(callIdHeader.getCallId() + cSeqHeader.getSeqNumber());
|
SipEvent sipEvent = sipSubscribe.getSubscribe(callIdHeader.getCallId() + cSeqHeader.getSeqNumber());
|
||||||
if (sipEvent != null && sipEvent.getErrorEvent() != null){
|
if (sipEvent != null && sipEvent.getErrorEvent() != null){
|
||||||
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(evt.getDialog());
|
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(callIdHeader.getCallId());
|
||||||
deviceNotFoundEvent.setCallId(callIdHeader.getCallId());
|
|
||||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(deviceNotFoundEvent);
|
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(deviceNotFoundEvent);
|
||||||
sipEvent.getErrorEvent().response(eventResult);
|
sipEvent.getErrorEvent().response(eventResult);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user