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 12 import org.springframework.core.io.ClassPathResource;
13 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 19 import java.nio.file.Files;
17 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 111 }
112 112 boolean result = false;
113 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 115 futureMap.remove(key);
116 116 runnableMap.remove(key);
117 117 }
... ... @@ -143,7 +143,8 @@ public class DynamicTask {
143 143 public void execute(){
144 144 if (futureMap.size() > 0) {
145 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 148 futureMap.remove(key);
148 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 18  
19 19 import javax.servlet.ServletException;
20 20 import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
21 22 import java.io.IOException;
22 23 import java.net.ConnectException;
23 24  
... ... @@ -64,6 +65,18 @@ public class ProxyServletConfig {
64 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 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 35 /**
36 36 * token过期时间(分钟)
37 37 */
38   - public static final long expirationTime = 30;
  38 + public static final long expirationTime = 30 * 24 * 60;
39 39  
40 40 public static String createToken(String username, String password, Integer roleId) {
41 41 try {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
... ... @@ -20,6 +20,8 @@ public interface ISIPCommanderForPlatform {
20 20 void register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException;
21 21  
22 22 void register(ParentPlatform parentPlatform, SipTransactionInfo sipTransactionInfo, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws InvalidArgumentException, ParseException, SipException;
  23 +
  24 +
23 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 132  
133 133 if (CmdType.CATALOG.equals(cmd)) {
134 134 logger.info("接收到Catalog通知");
135   -// processNotifyCatalogList(take.getEvt());
  135 + processNotifyCatalogList(take.getEvt());
136 136 notifyRequestForCatalogProcessor.process(take.getEvt());
137 137 } else if (CmdType.ALARM.equals(cmd)) {
138 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 85 Response response = null;
86 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 93 FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
90 94 AddressImpl address = (AddressImpl) fromHeader.getAddress();
91 95 SipUri uri = (SipUri) address.getURI();
... ... @@ -96,11 +100,12 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
96 100 RemoteAddressInfo remoteAddressInfo = SipUtils.getRemoteAddressFromRequest(request,
97 101 userSetting.getSipUseSourceIpAsRemoteAddress());
98 102 String requestAddress = remoteAddressInfo.getIp() + ":" + remoteAddressInfo.getPort();
99   - logger.info("[注册请求] 设备:{}, 开始处理: {}", deviceId, requestAddress);
  103 + String title = registerFlag ? "[注册请求]": "[注销请求]";
  104 + logger.info(title + "设备:{}, 开始处理: {}", deviceId, requestAddress);
100 105 if (device != null &&
101 106 device.getSipTransactionInfo() != null &&
102 107 request.getCallIdHeader().getCallId().equals(device.getSipTransactionInfo().getCallId())) {
103   - logger.info("[注册请求] 设备:{}, 注册续订: {}",device.getDeviceId(), device.getDeviceId());
  108 + logger.info(title + "设备:{}, 注册续订: {}",device.getDeviceId(), device.getDeviceId());
104 109 device.setExpires(request.getExpires().getExpires());
105 110 device.setIp(remoteAddressInfo.getIp());
106 111 device.setPort(remoteAddressInfo.getPort());
... ... @@ -120,7 +125,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
120 125 String password = (device != null && !ObjectUtils.isEmpty(device.getPassword()))? device.getPassword() : sipConfig.getPassword();
121 126 AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
122 127 if (authHead == null && !ObjectUtils.isEmpty(password)) {
123   - logger.info("[注册请求] 设备:{}, 回复401: {}",deviceId, requestAddress);
  128 + logger.info(title + " 设备:{}, 回复401: {}",deviceId, requestAddress);
124 129 response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
125 130 new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
126 131 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
... ... @@ -135,7 +140,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
135 140 // 注册失败
136 141 response = getMessageFactory().createResponse(Response.FORBIDDEN, request);
137 142 response.setReasonPhrase("wrong password");
138   - logger.info("[注册请求] 设备:{}, 密码/SIP服务器ID错误, 回复403: {}", deviceId, requestAddress);
  143 + logger.info(title + " 设备:{}, 密码/SIP服务器ID错误, 回复403: {}", deviceId, requestAddress);
139 144 sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
140 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 108 inviteStreamService.clearInviteInfo(device.getDeviceId());
109 109 }
110 110 device.setUpdateTime(now);
  111 + device.setKeepaliveTime(now);
111 112 if (device.getKeepaliveIntervalTime() == 0) {
112 113 // 默认心跳间隔60
113 114 device.setKeepaliveIntervalTime(60);
... ... @@ -209,7 +210,7 @@ public class DeviceServiceImpl implements IDeviceService {
209 210 redisCatchStorage.updateDevice(device);
210 211 deviceMapper.update(device);
211 212 //进行通道离线
212   -// deviceChannelMapper.offlineByDeviceId(deviceId);
  213 + deviceChannelMapper.offlineByDeviceId(deviceId);
213 214 // 离线释放所有ssrc
214 215 List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(deviceId, null, null, null);
215 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 234 // 设置平台离线,并重新注册
235 235 logger.info("[国标级联] 三次心跳超时, 平台{}({})离线", parentPlatform.getName(), parentPlatform.getServerGBId());
236 236 offline(parentPlatform, false);
237   -
238 237 }
239 238  
240 239 }else {
... ... @@ -249,6 +248,7 @@ public class PlatformServiceImpl implements IPlatformService {
249 248 platformCatch.setKeepAliveReply(0);
250 249 redisCatchStorage.updatePlatformCatchInfo(platformCatch);
251 250 }
  251 + logger.info("[发送心跳] 国标级联 发送心跳, code: {}, msg: {}", eventResult.statusCode, eventResult.msg);
252 252 });
253 253 } catch (SipException | InvalidArgumentException | ParseException e) {
254 254 logger.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage());
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
... ... @@ -193,7 +193,7 @@ public interface DeviceChannelMapper {
193 193 @Update(value = {"UPDATE wvp_device_channel SET status=false WHERE device_id=#{deviceId} AND channel_id=#{channelId}"})
194 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 197 void offlineByDeviceId(String deviceId);
198 198  
199 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 16 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
17 17 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
18 18 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
  19 +import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
19 20 import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
20 21 import com.genersoft.iot.vmp.utils.DateUtil;
21 22 import com.genersoft.iot.vmp.utils.JsonUtil;
... ... @@ -41,6 +42,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
41 42 private DeviceChannelMapper deviceChannelMapper;
42 43  
43 44 @Autowired
  45 + private DeviceMapper deviceMapper;
  46 +
  47 + @Autowired
44 48 private UserSetting userSetting;
45 49  
46 50 @Autowired
... ... @@ -375,7 +379,8 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
375 379 for (Object o : keys) {
376 380 String key = (String) o;
377 381 Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class);
378   - if (Objects.nonNull(device)) { // 只取没有存过得
  382 + if (Objects.nonNull(device)) {
  383 + // 只取没有存过得
379 384 result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class));
380 385 }
381 386 }
... ... @@ -386,14 +391,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
386 391 @Override
387 392 public Device getDevice(String deviceId) {
388 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 404 @Override
393 405 public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
394 406 String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId();
395 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 412 @Override
... ...
src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
1 1 package com.genersoft.iot.vmp.utils.redis;
2 2  
  3 +import com.google.common.collect.Lists;
3 4 import org.springframework.data.redis.core.Cursor;
4 5 import org.springframework.data.redis.core.RedisCallback;
5 6 import org.springframework.data.redis.core.RedisTemplate;
... ... @@ -38,7 +39,7 @@ public class RedisUtil {
38 39 return keys;
39 40 });
40 41  
41   - return new ArrayList<>(resultKeys);
  42 + return Lists.newArrayList(resultKeys);
42 43 }
43 44 }
44 45  
... ...