强化消息发送失败的处理
This commit is contained in:
@@ -1,27 +1,16 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.sip.Dialog;
|
||||
import java.util.EventObject;
|
||||
|
||||
public class DeviceNotFoundEvent extends EventObject {
|
||||
@Data
|
||||
public class DeviceNotFoundEvent {
|
||||
|
||||
private 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) {
|
||||
public DeviceNotFoundEvent(String 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;
|
||||
|
||||
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 gov.nist.javax.sip.message.SIPRequest;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
@@ -83,17 +84,17 @@ public class SipSubscribe {
|
||||
failedResult
|
||||
}
|
||||
|
||||
public static class EventResult<EventObject>{
|
||||
public static class EventResult<T>{
|
||||
public int statusCode;
|
||||
public EventResultType type;
|
||||
public String msg;
|
||||
public String callId;
|
||||
public EventObject event;
|
||||
public T event;
|
||||
|
||||
public EventResult() {
|
||||
}
|
||||
|
||||
public EventResult(EventObject event) {
|
||||
public EventResult(T event) {
|
||||
this.event = event;
|
||||
if (event instanceof ResponseEvent) {
|
||||
ResponseEvent responseEvent = (ResponseEvent)event;
|
||||
@@ -149,6 +150,12 @@ public class SipSubscribe {
|
||||
this.msg = "设备未找到";
|
||||
this.statusCode = -1024;
|
||||
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 {
|
||||
log.info("[移除移动位置订阅]失败,设备已经离线 : {}", device.getDeviceId());
|
||||
log.info("[移除目录订阅订阅]失败,设备已经离线 : {}", device.getDeviceId());
|
||||
if (callback != null) {
|
||||
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.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.sip.SipEvent;
|
||||
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.util.ObjectUtils;
|
||||
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.header.CSeqHeader;
|
||||
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) {
|
||||
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 -> {
|
||||
sipSubscribe.removeSubscribe(key);
|
||||
if(okEvent != null) {
|
||||
@@ -87,31 +89,40 @@ public class SIPSender {
|
||||
}), timeout == null ? sipConfig.getTimeout() : timeout);
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
|
||||
} 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);
|
||||
} 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) {
|
||||
|
||||
@@ -98,8 +98,7 @@ public class MessageRequestProcessor extends SIPRequestProcessorParent implement
|
||||
log.warn("[设备未找到 ]deviceId: {}, callId: {}", deviceId, callIdHeader.getCallId());
|
||||
SipEvent sipEvent = sipSubscribe.getSubscribe(callIdHeader.getCallId() + cSeqHeader.getSeqNumber());
|
||||
if (sipEvent != null && sipEvent.getErrorEvent() != null){
|
||||
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(evt.getDialog());
|
||||
deviceNotFoundEvent.setCallId(callIdHeader.getCallId());
|
||||
DeviceNotFoundEvent deviceNotFoundEvent = new DeviceNotFoundEvent(callIdHeader.getCallId());
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(deviceNotFoundEvent);
|
||||
sipEvent.getErrorEvent().response(eventResult);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user