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