Commit 3146e63fc05fddf91e6df086e363a4f5584c1d6b

Authored by 648540858
1 parent 703c2e29

优化异常处理

src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java
@@ -32,6 +32,7 @@ public class GlobalExceptionHandler { @@ -32,6 +32,7 @@ public class GlobalExceptionHandler {
32 return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage()); 32 return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
33 } 33 }
34 34
  35 +
35 /** 36 /**
36 * 自定义异常处理, 处理controller中返回的错误 37 * 自定义异常处理, 处理controller中返回的错误
37 * @param e 异常 38 * @param e 异常
src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java
1 package com.genersoft.iot.vmp.conf; 1 package com.genersoft.iot.vmp.conf;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
4 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; 5 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
5 import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 6 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
6 import org.jetbrains.annotations.NotNull; 7 import org.jetbrains.annotations.NotNull;
  8 +import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
  9 +import org.springframework.context.annotation.Bean;
7 import org.springframework.core.MethodParameter; 10 import org.springframework.core.MethodParameter;
8 import org.springframework.http.MediaType; 11 import org.springframework.http.MediaType;
9 import org.springframework.http.converter.HttpMessageConverter; 12 import org.springframework.http.converter.HttpMessageConverter;
  13 +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
10 import org.springframework.http.server.ServerHttpRequest; 14 import org.springframework.http.server.ServerHttpRequest;
11 import org.springframework.http.server.ServerHttpResponse; 15 import org.springframework.http.server.ServerHttpResponse;
12 import org.springframework.web.bind.annotation.RestControllerAdvice; 16 import org.springframework.web.bind.annotation.RestControllerAdvice;
13 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; 17 import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
14 18
  19 +import java.util.List;
  20 +
15 /** 21 /**
16 * 全局统一返回结果 22 * 全局统一返回结果
17 * @author lin 23 * @author lin
@@ -25,6 +31,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> { @@ -25,6 +31,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
25 return true; 31 return true;
26 } 32 }
27 33
  34 +
28 @Override 35 @Override
29 public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) { 36 public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) {
30 // 排除api文档的接口,这个接口不需要统一 37 // 排除api文档的接口,这个接口不需要统一
@@ -50,4 +57,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice&lt;Object&gt; { @@ -50,4 +57,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice&lt;Object&gt; {
50 57
51 return WVPResult.success(body); 58 return WVPResult.success(body);
52 } 59 }
  60 +
  61 + /**
  62 + * 防止返回string时出错
  63 + * @return
  64 + */
  65 + @Bean
  66 + public HttpMessageConverters custHttpMessageConverter() {
  67 + return new HttpMessageConverters(new FastJsonHttpMessageConverter());
  68 + }
53 } 69 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
@@ -151,7 +151,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { @@ -151,7 +151,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
151 logger.info("[发送错误订阅]"); 151 logger.info("[发送错误订阅]");
152 SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); 152 SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
153 SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent); 153 SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent);
154 - subscribe.response(eventResult); 154 + if (subscribe != null){
  155 + subscribe.response(eventResult);
  156 + }
155 sipSubscribe.removeOkSubscribe(callIdHeader.getCallId()); 157 sipSubscribe.removeOkSubscribe(callIdHeader.getCallId());
156 sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId()); 158 sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId());
157 } 159 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -184,8 +184,7 @@ public class ZLMHttpHookListener { @@ -184,8 +184,7 @@ public class ZLMHttpHookListener {
184 if (!"rtp".equals(param.getApp())) { 184 if (!"rtp".equals(param.getApp())) {
185 Map<String, String> paramMap = urlParamToMap(param.getParams()); 185 Map<String, String> paramMap = urlParamToMap(param.getParams());
186 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream()); 186 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
187 - if (streamAuthorityInfo == null  
188 - || (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) { 187 + if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) {
189 ret.put("code", 401); 188 ret.put("code", 401);
190 ret.put("msg", "Unauthorized"); 189 ret.put("msg", "Unauthorized");
191 return new ResponseEntity<>(ret.toString(),HttpStatus.OK); 190 return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
@@ -476,8 +475,12 @@ public class ZLMHttpHookListener { @@ -476,8 +475,12 @@ public class ZLMHttpHookListener {
476 if (mediaServerItem != null){ 475 if (mediaServerItem != null){
477 if (regist) { 476 if (regist) {
478 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); 477 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
  478 + String callId = null;
  479 + if (streamAuthorityInfo != null) {
  480 + callId = streamAuthorityInfo.getCallId();
  481 + }
479 StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, 482 StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
480 - app, stream, tracks, streamAuthorityInfo.getCallId()); 483 + app, stream, tracks, callId);
481 item.setStreamInfo(streamInfoByAppAndStream); 484 item.setStreamInfo(streamInfoByAppAndStream);
482 redisCatchStorage.addStream(mediaServerItem, type, app, stream, item); 485 redisCatchStorage.addStream(mediaServerItem, type, app, stream, item);
483 if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() 486 if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
@@ -54,9 +54,10 @@ public class MediaServiceImpl implements IMediaService { @@ -54,9 +54,10 @@ public class MediaServiceImpl implements IMediaService {
54 if (mediaInfo == null) { 54 if (mediaInfo == null) {
55 return null; 55 return null;
56 } 56 }
  57 + String calld = null;
57 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); 58 StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
58 - if (streamAuthorityInfo == null) {  
59 - return null; 59 + if (streamAuthorityInfo != null) {
  60 + calld = streamAuthorityInfo.getCallId();
60 } 61 }
61 JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream); 62 JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream);
62 if (mediaList != null) { 63 if (mediaList != null) {
@@ -68,7 +69,7 @@ public class MediaServiceImpl implements IMediaService { @@ -68,7 +69,7 @@ public class MediaServiceImpl implements IMediaService {
68 JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); 69 JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class);
69 JSONArray tracks = mediaJSON.getJSONArray("tracks"); 70 JSONArray tracks = mediaJSON.getJSONArray("tracks");
70 if (authority) { 71 if (authority) {
71 - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,streamAuthorityInfo.getCallId()); 72 + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr, calld);
72 }else { 73 }else {
73 streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null); 74 streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null);
74 } 75 }
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -296,7 +296,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -296,7 +296,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
296 public boolean start(String app, String stream) { 296 public boolean start(String app, String stream) {
297 boolean result = false; 297 boolean result = false;
298 StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); 298 StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
299 - if (!streamProxy.isEnable() ) { 299 + if (streamProxy != null && !streamProxy.isEnable() ) {
300 JSONObject jsonObject = addStreamProxyToZlm(streamProxy); 300 JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
301 if (jsonObject == null) { 301 if (jsonObject == null) {
302 return false; 302 return false;
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
@@ -76,8 +76,8 @@ public interface StreamPushMapper { @@ -76,8 +76,8 @@ public interface StreamPushMapper {
76 "WHERE " + 76 "WHERE " +
77 "1=1 " + 77 "1=1 " +
78 " <if test='query != null'> AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " + 78 " <if test='query != null'> AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " +
79 - " <if test='pushing == true' > AND (gs.gbId is null OR st.status=1)</if>" +  
80 - " <if test='pushing == false' > AND st.status=0</if>" + 79 + " <if test='pushing == true' > AND (gs.gbId is null OR st.pushIng=1)</if>" +
  80 + " <if test='pushing == false' > AND st.pushIng=0</if>" +
81 " <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" + 81 " <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" +
82 "order by st.createTime desc" + 82 "order by st.createTime desc" +
83 " </script>"}) 83 " </script>"})
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition; @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
3 import java.util.List; 3 import java.util.List;
4 import java.util.UUID; 4 import java.util.UUID;
5 5
  6 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
6 import com.genersoft.iot.vmp.gb28181.bean.Device; 7 import com.genersoft.iot.vmp.gb28181.bean.Device;
7 import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; 8 import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
8 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; 9 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
@@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; @@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; 11 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
11 import com.genersoft.iot.vmp.service.IDeviceService; 12 import com.genersoft.iot.vmp.service.IDeviceService;
12 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 13 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  14 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
13 import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 15 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
14 import com.github.pagehelper.util.StringUtil; 16 import com.github.pagehelper.util.StringUtil;
15 17
@@ -136,13 +138,9 @@ public class MobilePositionController { @@ -136,13 +138,9 @@ public class MobilePositionController {
136 @Parameter(name = "expires", description = "订阅超时时间", required = true) 138 @Parameter(name = "expires", description = "订阅超时时间", required = true)
137 @Parameter(name = "interval", description = "上报时间间隔", required = true) 139 @Parameter(name = "interval", description = "上报时间间隔", required = true)
138 @GetMapping("/subscribe/{deviceId}") 140 @GetMapping("/subscribe/{deviceId}")
139 - public String positionSubscribe(@PathVariable String deviceId, 141 + public void positionSubscribe(@PathVariable String deviceId,
140 @RequestParam String expires, 142 @RequestParam String expires,
141 @RequestParam String interval) { 143 @RequestParam String interval) {
142 - String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置";  
143 - if (logger.isDebugEnabled()) {  
144 - logger.debug(msg);  
145 - }  
146 144
147 if (StringUtil.isEmpty(interval)) { 145 if (StringUtil.isEmpty(interval)) {
148 interval = "5"; 146 interval = "5";
@@ -151,13 +149,8 @@ public class MobilePositionController { @@ -151,13 +149,8 @@ public class MobilePositionController {
151 device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires)); 149 device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
152 device.setMobilePositionSubmissionInterval(Integer.parseInt(interval)); 150 device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
153 deviceService.updateDevice(device); 151 deviceService.updateDevice(device);
154 - String result = msg;  
155 - if (deviceService.removeMobilePositionSubscribe(device)) {  
156 - result += ",成功";  
157 - } else {  
158 - result += ",失败"; 152 + if (!deviceService.removeMobilePositionSubscribe(device)) {
  153 + throw new ControllerException(ErrorCode.ERROR100);
159 } 154 }
160 -  
161 - return result;  
162 } 155 }
163 } 156 }
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
@@ -56,20 +56,14 @@ public class DeviceControl { @@ -56,20 +56,14 @@ public class DeviceControl {
56 @Operation(summary = "远程启动控制命令") 56 @Operation(summary = "远程启动控制命令")
57 @Parameter(name = "deviceId", description = "设备国标编号", required = true) 57 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
58 @GetMapping("/teleboot/{deviceId}") 58 @GetMapping("/teleboot/{deviceId}")
59 - public String teleBootApi(@PathVariable String deviceId) { 59 + public void teleBootApi(@PathVariable String deviceId) {
60 if (logger.isDebugEnabled()) { 60 if (logger.isDebugEnabled()) {
61 logger.debug("设备远程启动API调用"); 61 logger.debug("设备远程启动API调用");
62 } 62 }
63 Device device = storager.queryVideoDevice(deviceId); 63 Device device = storager.queryVideoDevice(deviceId);
64 - boolean sucsess = cmder.teleBootCmd(device);  
65 - if (sucsess) {  
66 - JSONObject json = new JSONObject();  
67 - json.put("DeviceID", deviceId);  
68 - json.put("Result", "OK");  
69 - return json.toJSONString();  
70 - } else {  
71 - logger.warn("设备远程启动API调用失败!");  
72 - throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败!"); 64 + if (!cmder.teleBootCmd(device)) {
  65 + logger.warn("设备远程启动API调用失败!");
  66 + throw new ControllerException(ErrorCode.ERROR100);
73 } 67 }
74 } 68 }
75 69
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -244,7 +244,7 @@ public class PlatformController { @@ -244,7 +244,7 @@ public class PlatformController {
244 @Parameter(name = "serverGBId", description = "上级平台的国标编号") 244 @Parameter(name = "serverGBId", description = "上级平台的国标编号")
245 @DeleteMapping("/delete/{serverGBId}") 245 @DeleteMapping("/delete/{serverGBId}")
246 @ResponseBody 246 @ResponseBody
247 - public String deletePlatform(@PathVariable String serverGBId) { 247 + public void deletePlatform(@PathVariable String serverGBId) {
248 248
249 if (logger.isDebugEnabled()) { 249 if (logger.isDebugEnabled()) {
250 logger.debug("删除上级平台API调用"); 250 logger.debug("删除上级平台API调用");
@@ -278,9 +278,7 @@ public class PlatformController { @@ -278,9 +278,7 @@ public class PlatformController {
278 dynamicTask.stop(key); 278 dynamicTask.stop(key);
279 // 删除缓存的订阅信息 279 // 删除缓存的订阅信息
280 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId()); 280 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
281 - if (deleteResult) {  
282 - return null;  
283 - } else { 281 + if (!deleteResult) {
284 throw new ControllerException(ErrorCode.ERROR100); 282 throw new ControllerException(ErrorCode.ERROR100);
285 } 283 }
286 } 284 }
web_src/config/index.js
@@ -12,14 +12,14 @@ module.exports = { @@ -12,14 +12,14 @@ module.exports = {
12 assetsPublicPath: '/', 12 assetsPublicPath: '/',
13 proxyTable: { 13 proxyTable: {
14 '/debug': { 14 '/debug': {
15 - target: 'http://localhost:18080', 15 + target: 'http://localhost:38080',
16 changeOrigin: true, 16 changeOrigin: true,
17 pathRewrite: { 17 pathRewrite: {
18 '^/debug': '/' 18 '^/debug': '/'
19 } 19 }
20 }, 20 },
21 '/static/snap': { 21 '/static/snap': {
22 - target: 'http://localhost:18080', 22 + target: 'http://localhost:38080',
23 changeOrigin: true, 23 changeOrigin: true,
24 // pathRewrite: { 24 // pathRewrite: {
25 // '^/static/snap': '/static/snap' 25 // '^/static/snap': '/static/snap'
web_src/src/components/StreamProxyList.vue
@@ -220,7 +220,7 @@ @@ -220,7 +220,7 @@
220 this.getListLoading = true; 220 this.getListLoading = true;
221 this.$axios({ 221 this.$axios({
222 method: 'get', 222 method: 'get',
223 - url:`/api/media/stream_info_by_app_and_stream`, 223 + url:`/api/push/getPlayUrl`,
224 params: { 224 params: {
225 app: row.app, 225 app: row.app,
226 stream: row.stream, 226 stream: row.stream,