去除冗余代码,修正编译报警项

This commit is contained in:
lawrencehj
2021-02-05 15:15:39 +08:00
parent 6868577e32
commit a8603075d4
42 changed files with 114 additions and 217 deletions

View File

@@ -149,8 +149,6 @@ public class SipLayer implements SipListener {
}
}
}
// } else if (status == Response.TRYING) {
// trying不会回复
} else if ((status >= 100) && (status < 200)) {
// 增加其它无需回复的响应如101、180等
} else {

View File

@@ -91,8 +91,10 @@ public class DigestServerAuthenticationHelper {
long time = date.getTime();
Random rand = new Random();
long pad = rand.nextLong();
String nonceString = (new Long(time)).toString()
+ (new Long(pad)).toString();
// String nonceString = (new Long(time)).toString()
// + (new Long(pad)).toString();
String nonceString = Long.valueOf(time).toString()
+ Long.valueOf(pad).toString();
byte mdbytes[] = messageDigest.digest(nonceString.getBytes());
// Convert the mdbytes array into a hex string.
return toHexString(mdbytes);
@@ -191,7 +193,7 @@ public class DigestServerAuthenticationHelper {
// 客户端随机数,这是一个不透明的字符串值,由客户端提供,并且客户端和服务器都会使用,以避免用明文文本。
// 这使得双方都可以查验对方的身份,并对消息的完整性提供一些保护
String cNonce = authHeader.getCNonce();
//String cNonce = authHeader.getCNonce();
// nonce计数器是一个16进制的数值表示同一nonce下客户端发送出请求的数量
int nc = authHeader.getNonceCount();

View File

@@ -1,7 +1,7 @@
package com.genersoft.iot.vmp.gb28181.bean;
import gov.nist.javax.sip.header.SIPDate;
//import gov.nist.javax.sip.header.SIPDate;
import java.util.List;

View File

@@ -10,6 +10,11 @@ import java.util.*;
*/
public class WvpSipDate extends SIPDate {
/**
*
*/
private static final long serialVersionUID = 1L;
private Calendar javaCal;
public WvpSipDate(long timeMillis) {

View File

@@ -1,22 +1,14 @@
package com.genersoft.iot.vmp.gb28181.event;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.sip.ResponseEvent;
import javax.sip.message.Request;
import java.util.EventObject;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class SipSubscribe {
private final static Logger logger = LoggerFactory.getLogger(SipSubscribe.class);
private Map<String, SipSubscribe.Event> errorSubscribes = new ConcurrentHashMap<>();
private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>();

View File

@@ -10,6 +10,11 @@ import org.springframework.context.ApplicationEvent;
*/
public class AlarmEvent extends ApplicationEvent {
/**
*
*/
private static final long serialVersionUID = 1L;
public AlarmEvent(Object source) {
super(source);
}

View File

@@ -3,18 +3,17 @@ package com.genersoft.iot.vmp.gb28181.event.offline;
import org.springframework.context.ApplicationEvent;
/**
* @Description:TODO(这里用一句话描述这个类的作用)
* @Description: 离线事件类
* @author: swwheihei
* @date: 2020年5月6日 上午11:33:13
*/
public class OfflineEvent extends ApplicationEvent {
/**
* @Title: OutlineEvent
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param source
* @throws
*/
/**
*
*/
private static final long serialVersionUID = 1L;
public OfflineEvent(Object source) {
super(source);
}

View File

@@ -3,18 +3,17 @@ package com.genersoft.iot.vmp.gb28181.event.online;
import org.springframework.context.ApplicationEvent;
/**
* @Description:TODO(这里用一句话描述这个类的作用)
* @Description: 在线事件类
* @author: swwheihei
* @date: 2020年5月6日 上午11:32:56
*/
public class OnlineEvent extends ApplicationEvent {
/**
* @Title: OnlineEvent
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param source
* @throws
*/
/**
*
*/
private static final long serialVersionUID = 1L;
public OnlineEvent(Object source) {
super(source);
}

View File

@@ -8,10 +8,9 @@ import javax.sip.message.Request;
import javax.sip.message.Response;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
@@ -40,14 +39,14 @@ import com.genersoft.iot.vmp.utils.SpringBeanFactory;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
/**
* @Description:TODO(这里用一句话描述这个类的作用)
* @Description: SIP信令处理分配
* @author: swwheihei
* @date: 2020年5月3日 下午4:24:37
*/
@Component
public class SIPProcessorFactory {
private final static Logger logger = LoggerFactory.getLogger(SIPProcessorFactory.class);
// private final static Logger logger = LoggerFactory.getLogger(SIPProcessorFactory.class);
@Autowired
private SipConfig sipConfig;

View File

@@ -1,6 +1,5 @@
package com.genersoft.iot.vmp.gb28181.transmit.callback;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -10,10 +9,11 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;
/**
* @Description:TODO(这里用一句话描述这个类的作用)
* @Description: 异步请求处理
* @author: swwheihei
* @date: 2020年5月8日 下午7:59:05
*/
@SuppressWarnings(value = {"rawtypes", "unchecked"})
@Component
public class DeferredResultHolder {

View File

@@ -1,7 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.callback;
/**
* @Description:TODO(这里用一句话描述这个类的作用)
* @Description: 请求信息定义
* @author: swwheihei
* @date: 2020年5月8日 下午1:09:18
*/

View File

@@ -1,6 +1,5 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;

View File

@@ -18,7 +18,6 @@ import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.Host;
/**
* @Description:摄像头命令request创造器 TODO 冗余代码太多待优化

View File

@@ -1,21 +1,18 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
import java.text.ParseException;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.sip.*;
import javax.sip.address.SipURI;
import javax.sip.header.CallIdHeader;
import javax.sip.header.Header;
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;

View File

@@ -50,26 +50,20 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
private SIPCommander cmder;
private IVideoManagerStorager storager;
private IRedisCatchStorage redisCatchStorage;
private EventPublisher publisher;
private RedisUtil redis;
private DeferredResultHolder deferredResultHolder;
private DeviceOffLineDetector offLineDetector;
private static final String NOTIFY_CATALOG = "Catalog";
private static final String NOTIFY_ALARM = "Alarm";
private static final String NOTIFY_MOBILE_POSITION = "MobilePosition";
@Override
public void process(RequestEvent evt) {
@Override
public void process(RequestEvent evt) {
try {
Element rootElement = getRootElement(evt);
String cmd = XmlUtil.getText(rootElement, "CmdType");
@@ -87,18 +81,19 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
logger.info("接收到消息:" + cmd);
response200Ok(evt);
}
} catch (DocumentException | SipException |InvalidArgumentException | ParseException e) {
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
e.printStackTrace();
}
}
}
/**
* 处理MobilePosition移动位置Notify
*
* @param evt
*/
private void processNotifyMobilePosition(RequestEvent evt) {
try {
//回复 200 OK
// 回复 200 OK
Element rootElement = getRootElement(evt);
MobilePosition mobilePosition = new MobilePosition();
Element deviceIdElement = rootElement.element("DeviceID");
@@ -112,8 +107,8 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID"));
mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(rootElement, "Speed")));
} else {
mobilePosition.setSpeed(0.0);
@@ -147,6 +142,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
/***
* 处理alarm设备报警Notify
*
* @param evt
*/
private void processNotifyAlarm(RequestEvent evt) {
@@ -180,7 +176,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
deviceAlarm.setLatitude(0.00);
}
if ( deviceAlarm.getAlarmMethod().equals("4")) {
if (deviceAlarm.getAlarmMethod().equals("4")) {
MobilePosition mobilePosition = new MobilePosition();
mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
mobilePosition.setTime(deviceAlarm.getAlarmTime());
@@ -245,7 +241,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setName(channelName);
deviceChannel.setChannelId(channelDeviceId);
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) {
deviceChannel.setStatus(1);
}
@@ -259,29 +255,34 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
if (XmlUtil.getText(itemDevice, "Parental") == null || XmlUtil.getText(itemDevice, "Parental") == "") {
if (XmlUtil.getText(itemDevice, "Parental") == null
|| XmlUtil.getText(itemDevice, "Parental") == "") {
deviceChannel.setParental(0);
} else {
deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
}
}
deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
if (XmlUtil.getText(itemDevice, "SafetyWay") == null || XmlUtil.getText(itemDevice, "SafetyWay")== "") {
if (XmlUtil.getText(itemDevice, "SafetyWay") == null
|| XmlUtil.getText(itemDevice, "SafetyWay") == "") {
deviceChannel.setSafetyWay(0);
} else {
deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
}
if (XmlUtil.getText(itemDevice, "RegisterWay") == null || XmlUtil.getText(itemDevice, "RegisterWay") =="") {
if (XmlUtil.getText(itemDevice, "RegisterWay") == null
|| XmlUtil.getText(itemDevice, "RegisterWay") == "") {
deviceChannel.setRegisterWay(1);
} else {
deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
}
deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") {
if (XmlUtil.getText(itemDevice, "Certifiable") == null
|| XmlUtil.getText(itemDevice, "Certifiable") == "") {
deviceChannel.setCertifiable(0);
} else {
deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
}
if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") {
if (XmlUtil.getText(itemDevice, "ErrCode") == null
|| XmlUtil.getText(itemDevice, "ErrCode") == "") {
deviceChannel.setErrCode(0);
} else {
deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
@@ -289,7 +290,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") =="") {
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") {
deviceChannel.setPort(0);
} else {
deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
@@ -305,7 +306,8 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
} else {
deviceChannel.setLatitude(0.00);
}
if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") {
if (XmlUtil.getText(itemDevice, "PTZType") == null
|| XmlUtil.getText(itemDevice, "PTZType") == "") {
deviceChannel.setPTZType(0);
} else {
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
@@ -330,9 +332,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
}
}
/***
/***
* 回复200 OK
*
* @param evt
* @throws SipException
* @throws InvalidArgumentException
@@ -343,7 +345,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
getServerTransaction(evt).sendResponse(response);
}
private Element getRootElement(RequestEvent evt) throws DocumentException {
private Element getRootElement(RequestEvent evt) throws DocumentException {
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
reader.setEncoding("gbk");
@@ -352,7 +354,6 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
}
public void setCmder(SIPCommander cmder) {
this.cmder = cmder;
}
public void setStorager(IVideoManagerStorager storager) {
@@ -364,11 +365,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
}
public void setRedis(RedisUtil redis) {
this.redis = redis;
}
public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
this.deferredResultHolder = deferredResultHolder;
}
public void setOffLineDetector(DeviceOffLineDetector offLineDetector) {

View File

@@ -145,7 +145,7 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
// 下发catelog查询目录
if (registerFlag == 1 && device != null) {
logger.info("注册成功! deviceId:" + device.getDeviceId());
boolean exists = storager.exists(device.getDeviceId());
// boolean exists = storager.exists(device.getDeviceId());
device.setRegisterTimeMillis(System.currentTimeMillis());
storager.updateDevice(device);
publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER);

View File

@@ -12,14 +12,12 @@ import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
import javax.sip.message.Response;
import gov.nist.javax.sip.header.CSeq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.SipLayer;
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory;
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
@@ -31,7 +29,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
@Component
public class InviteResponseProcessor implements ISIPResponseProcessor {
private final static Logger logger = LoggerFactory.getLogger(InviteResponseProcessor.class);
// private final static Logger logger = LoggerFactory.getLogger(InviteResponseProcessor.class);
/**
* 处理invite响应

View File

@@ -15,10 +15,10 @@ public class NumericUtil {
public static boolean isDouble(String str) {
try {
Double num2 = Double.valueOf(str);
System.out.println(num2 + " Is an Integer!");
System.out.println(num2 + " is a valid numeric string!");
return true;
} catch (Exception e) {
System.out.println(str + " Is not an Integer!");
System.out.println(str + " is an invalid numeric string!");
return false;
}
}
@@ -31,10 +31,10 @@ public class NumericUtil {
public static boolean isInteger(String str) {
try {
int num2 = Integer.valueOf(str);
System.out.println(num2 + " Is Number!");
System.out.println(num2 + " is an integer!");
return true;
} catch (Exception e) {
System.out.println(str + " Is not Number!");
System.out.println(str + " is not an integer!");
return false;
}
}