Commit dd2ae6578673651712134fd1867dca514cfec61f

Authored by chenzhangyue
1 parent 6106bda1

修复代理访问跨域问题,和ScheduledFuture取消任务时指令重排异常,不结束正在运行的任务。防止 Command interrupted

src/main/java/com/genersoft/iot/vmp/conf/CivilCodeFileConf.java
@@ -12,7 +12,10 @@ import org.springframework.core.annotation.Order; @@ -12,7 +12,10 @@ import org.springframework.core.annotation.Order;
12 import org.springframework.core.io.ClassPathResource; 12 import org.springframework.core.io.ClassPathResource;
13 import org.springframework.util.ObjectUtils; 13 import org.springframework.util.ObjectUtils;
14 14
15 -import java.io.*; 15 +import java.io.BufferedReader;
  16 +import java.io.File;
  17 +import java.io.InputStream;
  18 +import java.io.InputStreamReader;
16 import java.nio.file.Files; 19 import java.nio.file.Files;
17 import java.util.Map; 20 import java.util.Map;
18 21
src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
@@ -111,7 +111,7 @@ public class DynamicTask { @@ -111,7 +111,7 @@ public class DynamicTask {
111 } 111 }
112 boolean result = false; 112 boolean result = false;
113 if (!ObjectUtils.isEmpty(futureMap.get(key)) && !futureMap.get(key).isCancelled() && !futureMap.get(key).isDone()) { 113 if (!ObjectUtils.isEmpty(futureMap.get(key)) && !futureMap.get(key).isCancelled() && !futureMap.get(key).isDone()) {
114 - result = futureMap.get(key).cancel(true); 114 + result = futureMap.get(key).cancel(false);
115 futureMap.remove(key); 115 futureMap.remove(key);
116 runnableMap.remove(key); 116 runnableMap.remove(key);
117 } 117 }
@@ -143,7 +143,8 @@ public class DynamicTask { @@ -143,7 +143,8 @@ public class DynamicTask {
143 public void execute(){ 143 public void execute(){
144 if (futureMap.size() > 0) { 144 if (futureMap.size() > 0) {
145 for (String key : futureMap.keySet()) { 145 for (String key : futureMap.keySet()) {
146 - if (futureMap.get(key).isDone() || futureMap.get(key).isCancelled()) { 146 + ScheduledFuture<?> future = futureMap.get(key);
  147 + if (future.isDone() || future.isCancelled()) {
147 futureMap.remove(key); 148 futureMap.remove(key);
148 runnableMap.remove(key); 149 runnableMap.remove(key);
149 } 150 }
src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java
@@ -18,6 +18,7 @@ import org.springframework.util.ObjectUtils; @@ -18,6 +18,7 @@ import org.springframework.util.ObjectUtils;
18 18
19 import javax.servlet.ServletException; 19 import javax.servlet.ServletException;
20 import javax.servlet.http.HttpServletRequest; 20 import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
21 import java.io.IOException; 22 import java.io.IOException;
22 import java.net.ConnectException; 23 import java.net.ConnectException;
23 24
@@ -64,6 +65,18 @@ public class ProxyServletConfig { @@ -64,6 +65,18 @@ public class ProxyServletConfig {
64 return queryStr; 65 return queryStr;
65 } 66 }
66 67
  68 +
  69 + @Override
  70 + protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
  71 + HttpRequest proxyRequest) throws IOException {
  72 + HttpResponse response = super.doExecute(servletRequest, servletResponse, proxyRequest);
  73 + response.removeHeaders("Access-Control-Allow-Origin");
  74 + response.setHeader("Access-Control-Allow-Credentials","true");
  75 + response.removeHeaders("Access-Control-Allow-Credentials");
  76 +
  77 + return response;
  78 + }
  79 +
67 /** 80 /**
68 * 异常处理 81 * 异常处理
69 */ 82 */
@@ -181,6 +194,18 @@ public class ProxyServletConfig { @@ -181,6 +194,18 @@ public class ProxyServletConfig {
181 return queryStr; 194 return queryStr;
182 } 195 }
183 196
  197 +
  198 + @Override
  199 + protected HttpResponse doExecute(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
  200 + HttpRequest proxyRequest) throws IOException {
  201 + HttpResponse response = super.doExecute(servletRequest, servletResponse, proxyRequest);
  202 + String origin = servletRequest.getHeader("origin");
  203 + response.setHeader("Access-Control-Allow-Origin",origin);
  204 + response.setHeader("Access-Control-Allow-Credentials","true");
  205 +
  206 + return response;
  207 + }
  208 +
184 /** 209 /**
185 * 异常处理 210 * 异常处理
186 */ 211 */
src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java
@@ -35,7 +35,7 @@ public class JwtUtils { @@ -35,7 +35,7 @@ public class JwtUtils {
35 /** 35 /**
36 * token过期时间(分钟) 36 * token过期时间(分钟)
37 */ 37 */
38 - public static final long expirationTime = 30; 38 + public static final long expirationTime = 30 * 24 * 60;
39 39
40 public static String createToken(String username, String password, Integer roleId) { 40 public static String createToken(String username, String password, Integer roleId) {
41 try { 41 try {
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
@@ -20,6 +20,8 @@ public interface ISIPCommanderForPlatform { @@ -20,6 +20,8 @@ public interface ISIPCommanderForPlatform {
20 void register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException; 20 void register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException;
21 21
22 void register(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException; 22 void register(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException;
  23 +
  24 +
23 void register(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean isRegister) throws SipException, InvalidArgumentException, ParseException; 25 void register(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent, boolean isRegister) throws SipException, InvalidArgumentException, ParseException;
24 26
25 /** 27 /**
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
@@ -132,7 +132,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -132,7 +132,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
132 132
133 if (CmdType.CATALOG.equals(cmd)) { 133 if (CmdType.CATALOG.equals(cmd)) {
134 logger.info("接收到Catalog通知"); 134 logger.info("接收到Catalog通知");
135 -// processNotifyCatalogList(take.getEvt()); 135 + processNotifyCatalogList(take.getEvt());
136 notifyRequestForCatalogProcessor.process(take.getEvt()); 136 notifyRequestForCatalogProcessor.process(take.getEvt());
137 } else if (CmdType.ALARM.equals(cmd)) { 137 } else if (CmdType.ALARM.equals(cmd)) {
138 logger.info("接收到Alarm通知"); 138 logger.info("接收到Alarm通知");
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
@@ -85,7 +85,11 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @@ -85,7 +85,11 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
85 Response response = null; 85 Response response = null;
86 boolean passwordCorrect = false; 86 boolean passwordCorrect = false;
87 // 注册标志 87 // 注册标志
88 - boolean registerFlag; 88 + boolean registerFlag = true;
  89 + if (request.getExpires().getExpires() == 0) {
  90 + // 注销成功
  91 + registerFlag = false;
  92 + }
89 FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME); 93 FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
90 AddressImpl address = (AddressImpl) fromHeader.getAddress(); 94 AddressImpl address = (AddressImpl) fromHeader.getAddress();
91 SipUri uri = (SipUri) address.getURI(); 95 SipUri uri = (SipUri) address.getURI();
@@ -96,11 +100,12 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @@ -96,11 +100,12 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
96 RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request, 100 RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
97 userSetting.getSipUseSourceIpAsRemoteAddress()); 101 userSetting.getSipUseSourceIpAsRemoteAddress());
98 String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort(); 102 String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort();
99 - logger.info("[注册请求] 设备:{}, 开始处理: {}", deviceId, requestAddress); 103 + String title = registerFlag ? "[注册请求]": "[注销请求]";
  104 + logger.info(title + "设备:{}, 开始处理: {}", deviceId, requestAddress);
100 if (device != null && 105 if (device != null &&
101 device.getSipTransactionInfo() != null && 106 device.getSipTransactionInfo() != null &&
102 request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) { 107 request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
103 - logger.info("[注册请求] 设备:{}, 注册续订: {}",device.getDeviceId(), device.getDeviceId()); 108 + logger.info(title + "设备:{}, 注册续订: {}",device.getDeviceId(), device.getDeviceId());
104 device.setExpires(request.getExpires().getExpires()); 109 device.setExpires(request.getExpires().getExpires());
105 device.setIp(remoteAddressInfo.getIp()); 110 device.setIp(remoteAddressInfo.getIp());
106 device.setPort(remoteAddressInfo.getPort()); 111 device.setPort(remoteAddressInfo.getPort());
@@ -120,7 +125,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @@ -120,7 +125,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
120 String password = (device != null && !ObjectUtils.isEmpty(device.getPassword()))? device.getPassword() : sipConfig.getPassword(); 125 String password = (device != null && !ObjectUtils.isEmpty(device.getPassword()))? device.getPassword() : sipConfig.getPassword();
121 AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME); 126 AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
122 if (authHead == null && !ObjectUtils.isEmpty(password)) { 127 if (authHead == null && !ObjectUtils.isEmpty(password)) {
123 - logger.info("[注册请求] 设备:{}, 回复401: {}",deviceId, requestAddress); 128 + logger.info(title + " 设备:{}, 回复401: {}",deviceId, requestAddress);
124 response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request); 129 response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
125 new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain()); 130 new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
126 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); 131 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
@@ -135,7 +140,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen @@ -135,7 +140,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
135 // 注册失败 140 // 注册失败
136 response = getMessageFactory().createResponse(Response.FORBIDDEN, request); 141 response = getMessageFactory().createResponse(Response.FORBIDDEN, request);
137 response.setReasonPhrase("wrong password"); 142 response.setReasonPhrase("wrong password");
138 - logger.info("[注册请求] 设备:{}, 密码/SIP服务器ID错误, 回复403: {}", deviceId, requestAddress); 143 + logger.info(title + " 设备:{}, 密码/SIP服务器ID错误, 回复403: {}", deviceId, requestAddress);
139 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); 144 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
140 return; 145 return;
141 } 146 }
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -108,6 +108,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -108,6 +108,7 @@ public class DeviceServiceImpl implements IDeviceService {
108 inviteStreamService.clearInviteInfo(device.getDeviceId()); 108 inviteStreamService.clearInviteInfo(device.getDeviceId());
109 } 109 }
110 device.setUpdateTime(now); 110 device.setUpdateTime(now);
  111 + device.setKeepaliveTime(now);
111 if (device.getKeepaliveIntervalTime() == 0) { 112 if (device.getKeepaliveIntervalTime() == 0) {
112 // 默认心跳间隔60 113 // 默认心跳间隔60
113 device.setKeepaliveIntervalTime(60); 114 device.setKeepaliveIntervalTime(60);
@@ -209,7 +210,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -209,7 +210,7 @@ public class DeviceServiceImpl implements IDeviceService {
209 redisCatchStorage.updateDevice(device); 210 redisCatchStorage.updateDevice(device);
210 deviceMapper.update(device); 211 deviceMapper.update(device);
211 //进行通道离线 212 //进行通道离线
212 -// deviceChannelMapper.offlineByDeviceId(deviceId); 213 + deviceChannelMapper.offlineByDeviceId(deviceId);
213 // 离线释放所有ssrc 214 // 离线释放所有ssrc
214 List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(deviceId, null, null, null); 215 List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(deviceId, null, null, null);
215 if (ssrcTransactions != null && ssrcTransactions.size() > 0) { 216 if (ssrcTransactions != null && ssrcTransactions.size() > 0) {
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -234,7 +234,6 @@ public class PlatformServiceImpl implements IPlatformService { @@ -234,7 +234,6 @@ public class PlatformServiceImpl implements IPlatformService {
234 // 设置平台离线,并重新注册 234 // 设置平台离线,并重新注册
235 logger.info("[国标级联] 三次心跳超时, 平台{}({})离线", parentPlatform.getName(), parentPlatform.getServerGBId()); 235 logger.info("[国标级联] 三次心跳超时, 平台{}({})离线", parentPlatform.getName(), parentPlatform.getServerGBId());
236 offline(parentPlatform, false); 236 offline(parentPlatform, false);
237 -  
238 } 237 }
239 238
240 }else { 239 }else {
@@ -249,6 +248,7 @@ public class PlatformServiceImpl implements IPlatformService { @@ -249,6 +248,7 @@ public class PlatformServiceImpl implements IPlatformService {
249 platformCatch.setKeepAliveReply(0); 248 platformCatch.setKeepAliveReply(0);
250 redisCatchStorage.updatePlatformCatchInfo(platformCatch); 249 redisCatchStorage.updatePlatformCatchInfo(platformCatch);
251 } 250 }
  251 + logger.info("[发送心跳] 国标级联 发送心跳, code: {}, msg: {}", eventResult.statusCode, eventResult.msg);
252 }); 252 });
253 } catch (SipException | InvalidArgumentException | ParseException e) { 253 } catch (SipException | InvalidArgumentException | ParseException e) {
254 logger.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage()); 254 logger.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage());
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -193,7 +193,7 @@ public interface DeviceChannelMapper { @@ -193,7 +193,7 @@ public interface DeviceChannelMapper {
193 @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId} AND channel_id=#{channelId}"}) 193 @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId} AND channel_id=#{channelId}"})
194 void offline(String deviceId, String channelId); 194 void offline(String deviceId, String channelId);
195 195
196 - @Update(value = {"UPDATE wvp_device_channel SET status=fasle WHERE device_id=#{deviceId}"}) 196 + @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId}"})
197 void offlineByDeviceId(String deviceId); 197 void offlineByDeviceId(String deviceId);
198 198
199 @Insert("<script> " + 199 @Insert("<script> " +
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -16,6 +16,7 @@ import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; @@ -16,6 +16,7 @@ import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
16 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; 16 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
17 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 17 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
18 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; 18 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
  19 +import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
19 import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo; 20 import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
20 import com.genersoft.iot.vmp.utils.DateUtil; 21 import com.genersoft.iot.vmp.utils.DateUtil;
21 import com.genersoft.iot.vmp.utils.JsonUtil; 22 import com.genersoft.iot.vmp.utils.JsonUtil;
@@ -41,6 +42,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -41,6 +42,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
41 private DeviceChannelMapper deviceChannelMapper; 42 private DeviceChannelMapper deviceChannelMapper;
42 43
43 @Autowired 44 @Autowired
  45 + private DeviceMapper deviceMapper;
  46 +
  47 + @Autowired
44 private UserSetting userSetting; 48 private UserSetting userSetting;
45 49
46 @Autowired 50 @Autowired
@@ -375,7 +379,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -375,7 +379,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
375 for (Object o : keys) { 379 for (Object o : keys) {
376 String key = (String) o; 380 String key = (String) o;
377 Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); 381 Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
378 - if (Objects.nonNull(device)) { // 只取没有存过得 382 + if (Objects.nonNull(device)) {
  383 + // 只取没有存过得
379 result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class)); 384 result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class));
380 } 385 }
381 } 386 }
@@ -386,14 +391,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -386,14 +391,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
386 @Override 391 @Override
387 public Device getDevice(String deviceId) { 392 public Device getDevice(String deviceId) {
388 String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId; 393 String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
389 - return JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); 394 + Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
  395 + if (device == null){
  396 + device = deviceMapper.getDeviceByDeviceId(deviceId);
  397 + if (device != null) {
  398 + updateDevice(device);
  399 + }
  400 + }
  401 + return device;
390 } 402 }
391 403
392 @Override 404 @Override
393 public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { 405 public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
394 String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId(); 406 String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId();
395 Duration duration = Duration.ofSeconds(60L); 407 Duration duration = Duration.ofSeconds(60L);
396 - redisTemplate.opsForValue().set(key, gpsMsgInfo, duration); // 默认GPS消息保存1分钟 408 + redisTemplate.opsForValue().set(key, gpsMsgInfo, duration);
  409 + // 默认GPS消息保存1分钟
397 } 410 }
398 411
399 @Override 412 @Override
src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
1 package com.genersoft.iot.vmp.utils.redis; 1 package com.genersoft.iot.vmp.utils.redis;
2 2
  3 +import com.google.common.collect.Lists;
3 import org.springframework.data.redis.core.Cursor; 4 import org.springframework.data.redis.core.Cursor;
4 import org.springframework.data.redis.core.RedisCallback; 5 import org.springframework.data.redis.core.RedisCallback;
5 import org.springframework.data.redis.core.RedisTemplate; 6 import org.springframework.data.redis.core.RedisTemplate;
@@ -38,7 +39,7 @@ public class RedisUtil { @@ -38,7 +39,7 @@ public class RedisUtil {
38 return keys; 39 return keys;
39 }); 40 });
40 41
41 - return new ArrayList<>(resultKeys); 42 + return Lists.newArrayList(resultKeys);
42 } 43 }
43 } 44 }
44 45