使用阿里代码规范。规范代码写法

This commit is contained in:
648540858
2022-05-05 17:07:16 +08:00
parent 7f0ca85850
commit c286ecb455
51 changed files with 560 additions and 316 deletions

View File

@@ -129,7 +129,9 @@ public class DigestServerAuthenticationHelper {
*/
public boolean doAuthenticateHashedPassword(Request request, String hashedPassword) {
AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
if ( authHeader == null ) return false;
if ( authHeader == null ) {
return false;
}
String realm = authHeader.getRealm();
String username = authHeader.getUsername();
@@ -176,7 +178,9 @@ public class DigestServerAuthenticationHelper {
*/
public boolean doAuthenticatePlainTextPassword(Request request, String pass) {
AuthorizationHeader authHeader = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
if ( authHeader == null ) return false;
if ( authHeader == null ) {
return false;
}
String realm = authHeader.getRealm().trim();
String username = authHeader.getUsername().trim();

View File

@@ -25,6 +25,7 @@ public class GbStream extends PlatformGbStream{
return gbStreamId;
}
@Override
public void setGbStreamId(Integer gbStreamId) {
this.gbStreamId = gbStreamId;
}

View File

@@ -59,7 +59,9 @@ public class SubscribeHolder {
mobilePositionMap.put(platformId, subscribeInfo);
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + "MobilePosition_" + platformId;
// 添加任务处理GPS定时推送
dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform, storager, platformId, subscribeInfo.getSn(), key, this), subscribeInfo.getGpsInterval());
dynamicTask.startCron(key, new MobilePositionSubscribeHandlerTask(redisCatchStorage, sipCommanderForPlatform,
storager, platformId, subscribeInfo.getSn(), key, this, dynamicTask),
subscribeInfo.getGpsInterval());
String taskOverdueKey = taskOverduePrefix + "MobilePosition_" + platformId;
dynamicTask.stop(taskOverdueKey);
// 添加任务处理订阅过期

View File

@@ -62,7 +62,9 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
logger.info("设备上线事件触发deviceId" + event.getDevice().getDeviceId() + ",from:" + event.getFrom());
Device device = event.getDevice();
if (device == null) return;
if (device == null) {
return;
}
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDevice().getDeviceId();
Device deviceInStore = storager.queryVideoDevice(device.getDeviceId());
device.setOnline(1);

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
@@ -22,6 +23,8 @@ public class PlatformCycleRegisterEventLister implements ApplicationListener<Pla
private IVideoManagerStorage storager;
@Autowired
private ISIPCommanderForPlatform sipCommanderFroPlatform;
@Autowired
private DynamicTask dynamicTask;
@Override
public void onApplicationEvent(PlatformCycleRegisterEvent event) {
@@ -31,17 +34,13 @@ public class PlatformCycleRegisterEventLister implements ApplicationListener<Pla
logger.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID" + event.getPlatformGbID());
return;
}
Timer timer = new Timer();
String taskKey = "platform-cycle-register" + parentPlatform.getServerGBId();;
SipSubscribe.Event okEvent = (responseEvent)->{
timer.cancel();
dynamicTask.stop(taskKey);
};
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
timer.schedule(new TimerTask() {
@Override
public void run() {
logger.info("[平台注册]再次向平台注册平台国标ID" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
}
}, 15*1000 ,Long.parseLong(parentPlatform.getExpires())* 1000);
dynamicTask.startCron(taskKey, ()->{
logger.info("[平台注册]再次向平台注册平台国标ID" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
}, Integer.parseInt(parentPlatform.getExpires())* 1000);
}
}

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
@@ -46,6 +47,9 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
@Autowired
private SipConfig config;
@Autowired
private DynamicTask dynamicTask;
// @Autowired
// private RedisUtil redis;
@@ -75,19 +79,13 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
}
}
Timer timer = new Timer();
String taskKey = "platform-not-register-" + parentPlatform.getServerGBId();
SipSubscribe.Event okEvent = (responseEvent)->{
timer.cancel();
dynamicTask.stop(taskKey);
};
logger.info("[平台注册]平台国标ID" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
// 设置注册失败则每隔15秒发起一次注册
timer.schedule(new TimerTask() {
@Override
public void run() {
logger.info("[平台注册]再次向平台注册平台国标ID" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
}
}, config.getRegisterTimeInterval()* 1000, config.getRegisterTimeInterval()* 1000);//十五秒后再次发起注册
dynamicTask.startCron(taskKey, ()->{
logger.info("[平台注册]再次向平台注册平台国标ID" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
}, config.getRegisterTimeInterval()* 1000);
}
}

View File

@@ -60,7 +60,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>();
if (event.getPlatformId() != null) {
parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId());
if (parentPlatform != null && !parentPlatform.isStatus())return;
if (parentPlatform != null && !parentPlatform.isStatus()) {
return;
}
subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId());
if (subscribe == null) {
@@ -80,7 +82,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
}else if (event.getGbStreams() != null) {
if (platforms.size() > 0) {
for (GbStream gbStream : event.getGbStreams()) {
if (gbStream == null || StringUtils.isEmpty(gbStream.getGbId())) continue;
if (gbStream == null || StringUtils.isEmpty(gbStream.getGbId())) {
continue;
}
List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForStreamWithGBId(gbStream.getApp(),gbStream.getStream(), platforms);
parentPlatformMap.put(gbStream.getGbId(), parentPlatformsForGB);
}
@@ -113,7 +117,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
if (parentPlatforms != null && parentPlatforms.size() > 0) {
for (ParentPlatform platform : parentPlatforms) {
SubscribeInfo subscribeInfo = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (subscribeInfo == null) continue;
if (subscribeInfo == null) {
continue;
}
logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId);
List<DeviceChannel> deviceChannelList = new ArrayList<>();
DeviceChannel deviceChannel = new DeviceChannel();
@@ -155,7 +161,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
if (parentPlatforms != null && parentPlatforms.size() > 0) {
for (ParentPlatform platform : parentPlatforms) {
SubscribeInfo subscribeInfo = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (subscribeInfo == null) continue;
if (subscribeInfo == null) {
continue;
}
logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId);
List<DeviceChannel> deviceChannelList = new ArrayList<>();
DeviceChannel deviceChannel = storager.queryChannelInParentPlatform(platform.getServerGBId(), gbId);

View File

@@ -65,19 +65,25 @@ public class CatalogDataCatch {
public List<DeviceChannel> get(String deviceId) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return null;
if (catalogData == null) {
return null;
}
return catalogData.getChannelList();
}
public int getTotal(String deviceId) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return 0;
if (catalogData == null) {
return 0;
}
return catalogData.getTotal();
}
public SyncStatus getSyncStatus(String deviceId) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return null;
if (catalogData == null) {
return null;
}
SyncStatus syncStatus = new SyncStatus();
syncStatus.setCurrent(catalogData.getChannelList().size());
syncStatus.setTotal(catalogData.getTotal());
@@ -87,7 +93,9 @@ public class CatalogDataCatch {
public boolean isSyncRunning(String deviceId) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return false;
if (catalogData == null) {
return false;
}
return !catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end);
}
@@ -125,7 +133,9 @@ public class CatalogDataCatch {
public void setChannelSyncEnd(String deviceId, String errorMsg) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null)return;
if (catalogData == null) {
return;
}
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
catalogData.setErrorMsg(errorMsg);
}

View File

@@ -78,7 +78,9 @@ public class VideoStreamSessionManager {
public ClientTransaction getTransactionByStream(String deviceId, String channelId, String stream){
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
if (ssrcTransaction == null) return null;
if (ssrcTransaction == null) {
return null;
}
byte[] transactionByteArray = ssrcTransaction.getTransaction();
ClientTransaction clientTransaction = (ClientTransaction)SerializeUtils.deSerialize(transactionByteArray);
return clientTransaction;
@@ -86,39 +88,63 @@ public class VideoStreamSessionManager {
public SIPDialog getDialogByStream(String deviceId, String channelId, String stream){
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
if (ssrcTransaction == null) return null;
if (ssrcTransaction == null) {
return null;
}
byte[] dialogByteArray = ssrcTransaction.getDialog();
if (dialogByteArray == null) return null;
if (dialogByteArray == null) {
return null;
}
SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray);
return dialog;
}
public SIPDialog getDialogByCallId(String deviceId, String channelId, String callID){
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, callID, null);
if (ssrcTransaction == null) return null;
if (ssrcTransaction == null) {
return null;
}
byte[] dialogByteArray = ssrcTransaction.getDialog();
if (dialogByteArray == null) return null;
if (dialogByteArray == null) {
return null;
}
SIPDialog dialog = (SIPDialog)SerializeUtils.deSerialize(dialogByteArray);
return dialog;
}
public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){
if (StringUtils.isEmpty(callId)) callId ="*";
if (StringUtils.isEmpty(stream)) stream ="*";
if (StringUtils.isEmpty(callId)) {
callId ="*";
}
if (StringUtils.isEmpty(stream)) {
stream ="*";
}
String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
List<Object> scanResult = redisUtil.scan(key);
if (scanResult.size() == 0) return null;
if (scanResult.size() == 0) {
return null;
}
return (SsrcTransaction)redisUtil.get((String) scanResult.get(0));
}
public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){
if (StringUtils.isEmpty(deviceId)) deviceId ="*";
if (StringUtils.isEmpty(channelId)) channelId ="*";
if (StringUtils.isEmpty(callId)) callId ="*";
if (StringUtils.isEmpty(stream)) stream ="*";
if (StringUtils.isEmpty(deviceId)) {
deviceId ="*";
}
if (StringUtils.isEmpty(channelId)) {
channelId ="*";
}
if (StringUtils.isEmpty(callId)) {
callId ="*";
}
if (StringUtils.isEmpty(stream)) {
stream ="*";
}
String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
List<Object> scanResult = redisUtil.scan(key);
if (scanResult.size() == 0) return null;
if (scanResult.size() == 0) {
return null;
}
List<SsrcTransaction> result = new ArrayList<>();
for (Object keyObj : scanResult) {
result.add((SsrcTransaction)redisUtil.get((String) keyObj));
@@ -128,19 +154,25 @@ public class VideoStreamSessionManager {
public String getMediaServerId(String deviceId, String channelId, String stream){
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
if (ssrcTransaction == null) return null;
if (ssrcTransaction == null) {
return null;
}
return ssrcTransaction.getMediaServerId();
}
public String getSSRC(String deviceId, String channelId, String stream){
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
if (ssrcTransaction == null) return null;
if (ssrcTransaction == null) {
return null;
}
return ssrcTransaction.getSsrc();
}
public void remove(String deviceId, String channelId, String stream) {
SsrcTransaction ssrcTransaction = getSsrcTransaction(deviceId, channelId, null, stream);
if (ssrcTransaction == null) return;
if (ssrcTransaction == null) {
return;
}
redisUtil.del(VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_"
+ deviceId + "_" + channelId + "_" + ssrcTransaction.getCallId() + "_" + ssrcTransaction.getStream());
}

View File

@@ -2,6 +2,9 @@ package com.genersoft.iot.vmp.gb28181.task;
import javax.sip.DialogState;
/**
* @author lin
*/
public interface ISubscribeTask extends Runnable{
void stop();

View File

@@ -1,11 +1,13 @@
package com.genersoft.iot.vmp.gb28181.task.impl;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import javax.sip.Dialog;
import javax.sip.DialogState;
@@ -15,6 +17,7 @@ import java.util.TimerTask;
/**
* 目录订阅任务
* @author lin
*/
public class CatalogSubscribeTask implements ISubscribeTask {
private final Logger logger = LoggerFactory.getLogger(CatalogSubscribeTask.class);
@@ -22,18 +25,21 @@ public class CatalogSubscribeTask implements ISubscribeTask {
private final ISIPCommander sipCommander;
private Dialog dialog;
private Timer timer ;
private DynamicTask dynamicTask;
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander) {
private String taskKey = "catalog-subscribe-timeout";
public CatalogSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) {
this.device = device;
this.sipCommander = sipCommander;
this.dynamicTask = dynamicTask;
}
@Override
public void run() {
if (timer != null ) {
timer.cancel();
timer = null;
if (dynamicTask.get(taskKey) != null) {
dynamicTask.stop(taskKey);
}
sipCommander.catalogSubscribe(device, dialog, eventResult -> {
if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
@@ -51,13 +57,7 @@ public class CatalogSubscribeTask implements ISubscribeTask {
dialog = null;
// 失败
logger.warn("[目录订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
CatalogSubscribeTask.this.run();
}
}, 2000);
dynamicTask.startDelay(taskKey, CatalogSubscribeTask.this, 2000);
});
}
@@ -71,9 +71,8 @@ public class CatalogSubscribeTask implements ISubscribeTask {
* TERMINATED-> Terminated Dialog状态-终止
*/
logger.info("取消目录订阅时dialog状态为{}", DialogState.CONFIRMED);
if (timer != null ) {
timer.cancel();
timer = null;
if (dynamicTask.get(taskKey) != null) {
dynamicTask.stop(taskKey);
}
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
device.setSubscribeCycleForCatalog(0);
@@ -95,7 +94,9 @@ public class CatalogSubscribeTask implements ISubscribeTask {
@Override
public DialogState getDialogState() {
if (dialog == null) return null;
if (dialog == null) {
return null;
}
return dialog.getState();
}
}

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.task.impl;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
@@ -15,6 +16,7 @@ import java.util.List;
/**
* 向已经订阅(移动位置)的上级发送MobilePosition消息
* @author lin
*/
public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
@@ -25,10 +27,18 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
private ISIPCommanderForPlatform sipCommanderForPlatform;
private SubscribeHolder subscribeHolder;
private ParentPlatform platform;
private String sn;
private String key;
public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage, ISIPCommanderForPlatform sipCommanderForPlatform, IVideoManagerStorage storager, String platformId, String sn, String key, SubscribeHolder subscribeInfo) {
public MobilePositionSubscribeHandlerTask(IRedisCatchStorage redisCatchStorage,
ISIPCommanderForPlatform sipCommanderForPlatform,
IVideoManagerStorage storager,
String platformId,
String sn,
String key,
SubscribeHolder subscribeInfo,
DynamicTask dynamicTask) {
this.redisCatchStorage = redisCatchStorage;
this.storager = storager;
this.platform = storager.queryParentPlatByServerGBId(platformId);
@@ -41,7 +51,9 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
@Override
public void run() {
if (platform == null) return;
if (platform == null) {
return;
}
SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
if (subscribe != null) {

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.task.impl;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
@@ -16,25 +17,26 @@ import java.util.TimerTask;
/**
* 移动位置订阅的定时更新
* @author lin
*/
public class MobilePositionSubscribeTask implements ISubscribeTask {
private final Logger logger = LoggerFactory.getLogger(MobilePositionSubscribeTask.class);
private Device device;
private ISIPCommander sipCommander;
private Dialog dialog;
private DynamicTask dynamicTask;
private String taskKey = "mobile-position-subscribe-timeout";
private Timer timer ;
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) {
public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander, DynamicTask dynamicTask) {
this.device = device;
this.sipCommander = sipCommander;
this.dynamicTask = dynamicTask;
}
@Override
public void run() {
if (timer != null ) {
timer.cancel();
timer = null;
if (dynamicTask.get(taskKey) != null) {
dynamicTask.stop(taskKey);
}
sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> {
// if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) {
@@ -52,13 +54,7 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
dialog = null;
// 失败
logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
MobilePositionSubscribeTask.this.run();
}
}, 2000);
dynamicTask.startDelay(taskKey, MobilePositionSubscribeTask.this, 2000);
});
}
@@ -72,9 +68,8 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
* COMPLETED-> Completed Dialog状态-已完成
* TERMINATED-> Terminated Dialog状态-终止
*/
if (timer != null ) {
timer.cancel();
timer = null;
if (dynamicTask.get(taskKey) != null) {
dynamicTask.stop(taskKey);
}
if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) {
logger.info("取消移动订阅时dialog状态为{}", dialog.getState());
@@ -96,7 +91,9 @@ public class MobilePositionSubscribeTask implements ISubscribeTask {
}
@Override
public DialogState getDialogState() {
if (dialog == null) return null;
if (dialog == null) {
return null;
}
return dialog.getState();
}
}

View File

@@ -62,7 +62,7 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
* @param processor 处理程序
*/
public void addTimeoutProcessor(ITimeoutProcessor processor) {
this.timeoutProcessor = processor;
timeoutProcessor = processor;
}
/**

View File

@@ -29,6 +29,7 @@ public class CheckForAllRecordsThread extends Thread {
this.recordInfo = recordInfo;
}
@Override
public void run() {
String cacheKey = this.key;

View File

@@ -65,12 +65,16 @@ public class DeferredResultHolder {
public DeferredResult get(String key, String id) {
Map<String, DeferredResult> deferredResultMap = map.get(key);
if (deferredResultMap == null) return null;
if (deferredResultMap == null) {
return null;
}
return deferredResultMap.get(id);
}
public boolean exist(String key, String id){
if (key == null) return false;
if (key == null) {
return false;
}
Map<String, DeferredResult> deferredResultMap = map.get(key);
if (id == null) {
return deferredResultMap != null;

View File

@@ -228,9 +228,13 @@ public class SIPRequestHeaderProvider {
public Request createInfoRequest(Device device, StreamInfo streamInfo, String content)
throws PeerUnavailableException, ParseException, InvalidArgumentException {
Request request = null;
if (streamInfo == null) return null;
if (streamInfo == null) {
return null;
}
Dialog dialog = streamSession.getDialogByStream(streamInfo.getDeviceID(), streamInfo.getChannelId(), streamInfo.getStream());
if (dialog == null) return null;
if (dialog == null) {
return null;
}
SipURI requestLine = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(),
device.getHostAddress());

View File

@@ -346,7 +346,9 @@ public class SIPCommander implements ISIPCommander {
ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
String streamId = ssrcInfo.getStream();
try {
if (device == null) return;
if (device == null) {
return;
}
String streamMode = device.getStreamMode().toUpperCase();
logger.info("{} 分配的ZLM为: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
@@ -694,7 +696,9 @@ public class SIPCommander implements ISIPCommander {
if (callId != null) {
dialog = streamSession.getDialogByCallId(deviceId, channelId, callId);
}else {
if (stream == null) return;
if (stream == null) {
return;
}
dialog = streamSession.getDialogByStream(deviceId, channelId, stream);
}
if (ssrcTransaction != null) {
@@ -1454,6 +1458,7 @@ public class SIPCommander implements ISIPCommander {
* @param device 视频设备
* @return true = 命令发送成功
*/
@Override
public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
try {
StringBuffer subscribePostitionXml = new StringBuffer(200);
@@ -1505,6 +1510,7 @@ public class SIPCommander implements ISIPCommander {
* @param endTime 报警发生终止时间(可选)
* @return true = 命令发送成功
*/
@Override
public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
try {
StringBuffer cmdXml = new StringBuffer(200);
@@ -1701,7 +1707,9 @@ public class SIPCommander implements ISIPCommander {
content.append("CSeq: " + cseq + "\r\n");
content.append("Range: npt=now-\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
if (request == null) return;
if (request == null) {
return;
}
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1730,7 +1738,9 @@ public class SIPCommander implements ISIPCommander {
content.append("Range: npt=" + Math.abs(seekTime) + "-\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
if (request == null) return;
if (request == null) {
return;
}
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1758,7 +1768,9 @@ public class SIPCommander implements ISIPCommander {
content.append("CSeq: " + cseq + "\r\n");
content.append("Scale: " + String.format("%.1f",speed) + "\r\n");
Request request = headerProvider.createInfoRequest(device, streamInfo, content.toString());
if (request == null) return;
if (request == null) {
return;
}
logger.info(request.toString());
ClientTransaction clientTransaction = null;
if ("TCP".equals(device.getTransport())) {
@@ -1824,7 +1836,9 @@ public class SIPCommander implements ISIPCommander {
// 设置编码, 防止中文乱码
messageFactory.setDefaultContentEncodingCharset(characterSet);
Dialog dialog = subscribeInfo.getDialog();
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return;
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) {
return;
}
SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
notifyRequest.setContent(catalogXmlContent, contentTypeHeader);

View File

@@ -529,7 +529,9 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
// 设置编码, 防止中文乱码
messageFactory.setDefaultContentEncodingCharset(characterSet);
Dialog dialog = subscribeInfo.getDialog();
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return;
if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) {
return;
}
SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
notifyRequest.setContent(catalogXmlContent, contentTypeHeader);

View File

@@ -139,7 +139,9 @@ public abstract class SIPRequestProcessorParent {
serverTransaction.sendResponse(response);
if (statusCode >= 200 && !"NOTIFY".equals(evt.getRequest().getMethod())) {
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
}
}
@@ -149,7 +151,9 @@ public abstract class SIPRequestProcessorParent {
ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (statusCode >= 200 && !"NOTIFY".equals(evt.getRequest().getMethod())) {
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
}
}
@@ -215,7 +219,9 @@ public abstract class SIPRequestProcessorParent {
return getRootElement(evt, "gb2312");
}
public Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
if (charset == null) charset = "gb2312";
if (charset == null) {
charset = "gb2312";
}
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
reader.setEncoding(charset);

View File

@@ -72,7 +72,9 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
public void process(RequestEvent evt) {
Dialog dialog = evt.getDialog();
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
if (dialog == null) return;
if (dialog == null) {
return;
}
if (dialog.getState()== DialogState.CONFIRMED) {
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
logger.info("ACK请求 platformGbId->{}", platformGbId);

View File

@@ -81,7 +81,9 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
responseAck(evt, Response.OK);
Dialog dialog = evt.getDialog();
CallIdHeader callIdHeader = (CallIdHeader)evt.getRequest().getHeader(CallIdHeader.NAME);
if (dialog == null) return;
if (dialog == null) {
return;
}
if (dialog.getState().equals(DialogState.TERMINATED)) {
String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();

View File

@@ -321,7 +321,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
} catch (ParseException | SipException | InvalidArgumentException e) {
e.printStackTrace();
}

View File

@@ -130,7 +130,9 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
response = getMessageFactory().createResponse(Response.BAD_REQUEST, request);
ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
return;
}
// 添加Contact头
@@ -195,7 +197,9 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
return;
}
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
}
}

View File

@@ -35,22 +35,17 @@ import java.text.ParseException;
/**
* SIP命令类型 SUBSCRIBE请求
* @author lin
*/
@Component
public class SubscribeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor {
private Logger logger = LoggerFactory.getLogger(SubscribeRequestProcessor.class);
private String method = "SUBSCRIBE";
private final Logger logger = LoggerFactory.getLogger(SubscribeRequestProcessor.class);
private final String method = "SUBSCRIBE";
@Autowired
private SIPProcessorObserver sipProcessorObserver;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private ISIPCommanderForPlatform sipCommanderForPlatform;
@Autowired
private IVideoManagerStorage storager;
@@ -82,7 +77,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
/**
* 处理SUBSCRIBE请求
*
* @param evt
* @param evt 事件
*/
@Override
public void process(RequestEvent evt) {
@@ -101,13 +96,12 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
} else {
logger.info("接收到消息:" + cmd);
Response response = null;
response = getMessageFactory().createResponse(200, request);
Response response = getMessageFactory().createResponse(200, request);
if (response != null) {
ExpiresHeader expireHeader = getHeaderFactory().createExpiresHeader(30);
response.setExpires(expireHeader);
}
logger.info("response : " + response.toString());
logger.info("response : " + response);
ServerTransaction transaction = getServerTransaction(evt);
if (transaction != null) {
transaction.sendResponse(response);
@@ -117,13 +111,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
logger.info("processRequest serverTransactionId is null.");
}
}
} catch (ParseException e) {
e.printStackTrace();
} catch (SipException e) {
e.printStackTrace();
} catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (DocumentException e) {
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
e.printStackTrace();
}
@@ -134,14 +122,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
*/
private void processNotifyMobilePosition(RequestEvent evt, Element rootElement) throws SipException {
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
String deviceID = XmlUtil.getText(rootElement, "DeviceID");
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
if (platform == null) {
return;
}
if (evt.getServerTransaction() == null) {
ServerTransaction serverTransaction = platform.getTransport().equals("TCP") ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
ServerTransaction serverTransaction = "TCP".equals(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
: udpSipProvider.getNewServerTransaction(evt.getRequest());
subscribeInfo.setTransaction(serverTransaction);
Dialog dialog = serverTransaction.getDialog();
@@ -154,13 +142,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
resultXml.append("<?xml version=\"1.0\" ?>\r\n")
.append("<Response>\r\n")
.append("<CmdType>MobilePosition</CmdType>\r\n")
.append("<SN>" + sn + "</SN>\r\n")
.append("<DeviceID>" + deviceID + "</DeviceID>\r\n")
.append("<SN>").append(sn).append("</SN>\r\n")
.append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n")
.append("<Result>OK</Result>\r\n")
.append("</Response>\r\n");
if (subscribeInfo.getExpires() > 0) {
String interval = XmlUtil.getText(rootElement, "Interval"); // GPS上报时间间隔
// GPS上报时间间隔
String interval = XmlUtil.getText(rootElement, "Interval");
if (interval == null) {
subscribeInfo.setGpsInterval(5);
}else {
@@ -169,15 +158,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
subscribeInfo.setSn(sn);
subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
// if (subscribeHolder.getMobilePositionSubscribe(platformId) == null ) {
// subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
// }else {
// if (subscribeHolder.getMobilePositionSubscribe(platformId).getDialog() != null
// && subscribeHolder.getMobilePositionSubscribe(platformId).getDialog().getState() != null
// && !subscribeHolder.getMobilePositionSubscribe(platformId).getDialog().getState().equals(DialogState.CONFIRMED)) {
// subscribeHolder.putMobilePositionSubscribe(platformId, subscribeInfo);
// }
// }
}else if (subscribeInfo.getExpires() == 0) {
subscribeHolder.removeMobilePositionSubscribe(platformId);
}
@@ -185,11 +166,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
try {
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
responseXmlAck(evt, resultXml.toString(), parentPlatform);
} catch (SipException e) {
e.printStackTrace();
} catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (ParseException e) {
} catch (SipException | InvalidArgumentException | ParseException e) {
e.printStackTrace();
}
}
@@ -200,12 +177,14 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
private void processNotifyCatalogList(RequestEvent evt, Element rootElement) throws SipException {
String platformId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
String deviceID = XmlUtil.getText(rootElement, "DeviceID");
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
if (platform == null)return;
if (platform == null){
return;
}
SubscribeInfo subscribeInfo = new SubscribeInfo(evt, platformId);
if (evt.getServerTransaction() == null) {
ServerTransaction serverTransaction = platform.getTransport().equals("TCP") ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
ServerTransaction serverTransaction = "TCP".equals(platform.getTransport()) ? tcpSipProvider.getNewServerTransaction(evt.getRequest())
: udpSipProvider.getNewServerTransaction(evt.getRequest());
subscribeInfo.setTransaction(serverTransaction);
Dialog dialog = serverTransaction.getDialog();
@@ -213,13 +192,13 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
subscribeInfo.setDialog(dialog);
}
String sn = XmlUtil.getText(rootElement, "SN");
logger.info("[回复 目录订阅]: {}/{}", platformId, deviceID);
logger.info("[回复 目录订阅]: {}/{}", platformId, deviceId);
StringBuilder resultXml = new StringBuilder(200);
resultXml.append("<?xml version=\"1.0\" ?>\r\n")
.append("<Response>\r\n")
.append("<CmdType>Catalog</CmdType>\r\n")
.append("<SN>" + sn + "</SN>\r\n")
.append("<DeviceID>" + deviceID + "</DeviceID>\r\n")
.append("<SN>").append(sn).append("</SN>\r\n")
.append("<DeviceID>").append(deviceId).append("</DeviceID>\r\n")
.append("<Result>OK</Result>\r\n")
.append("</Response>\r\n");
@@ -232,11 +211,7 @@ public class SubscribeRequestProcessor extends SIPRequestProcessorParent impleme
try {
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
responseXmlAck(evt, resultXml.toString(), parentPlatform);
} catch (SipException e) {
e.printStackTrace();
} catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (ParseException e) {
} catch (SipException | InvalidArgumentException | ParseException e) {
e.printStackTrace();
}
}

View File

@@ -25,7 +25,9 @@ public class SipUtils {
* */
public static String getChannelIdFromHeader(Request request) {
Header subject = request.getHeader("subject");
if (subject == null) return null;
if (subject == null) {
return null;
}
return ((Subject) subject).getSubject().split(":")[0];
}