优化异常处理

pull/608/head
648540858 2022-09-01 17:53:00 +08:00
parent 703c2e292a
commit 3146e63fc0
12 changed files with 47 additions and 39 deletions

View File

@ -32,6 +32,7 @@ public class GlobalExceptionHandler {
return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage()); return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
} }
/** /**
* controller * controller
* @param e * @param e

View File

@ -1,17 +1,23 @@
package com.genersoft.iot.vmp.conf; package com.genersoft.iot.vmp.conf;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import java.util.List;
/** /**
* *
* @author lin * @author lin
@ -25,6 +31,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
return true; return true;
} }
@Override @Override
public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) { public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) {
// 排除api文档的接口这个接口不需要统一 // 排除api文档的接口这个接口不需要统一
@ -50,4 +57,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
return WVPResult.success(body); return WVPResult.success(body);
} }
/**
* string
* @return
*/
@Bean
public HttpMessageConverters custHttpMessageConverter() {
return new HttpMessageConverters(new FastJsonHttpMessageConverter());
}
} }

View File

@ -151,7 +151,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
logger.info("[发送错误订阅]"); logger.info("[发送错误订阅]");
SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent); SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent);
subscribe.response(eventResult); if (subscribe != null){
subscribe.response(eventResult);
}
sipSubscribe.removeOkSubscribe(callIdHeader.getCallId()); sipSubscribe.removeOkSubscribe(callIdHeader.getCallId());
sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId()); sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId());
} }

View File

@ -184,8 +184,7 @@ public class ZLMHttpHookListener {
if (!"rtp".equals(param.getApp())) { if (!"rtp".equals(param.getApp())) {
Map<String, String> paramMap = urlParamToMap(param.getParams()); Map<String, String> paramMap = urlParamToMap(param.getParams());
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream()); StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
if (streamAuthorityInfo == null if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) {
|| (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) {
ret.put("code", 401); ret.put("code", 401);
ret.put("msg", "Unauthorized"); ret.put("msg", "Unauthorized");
return new ResponseEntity<>(ret.toString(),HttpStatus.OK); return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
@ -476,8 +475,12 @@ public class ZLMHttpHookListener {
if (mediaServerItem != null){ if (mediaServerItem != null){
if (regist) { if (regist) {
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
String callId = null;
if (streamAuthorityInfo != null) {
callId = streamAuthorityInfo.getCallId();
}
StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
app, stream, tracks, streamAuthorityInfo.getCallId()); app, stream, tracks, callId);
item.setStreamInfo(streamInfoByAppAndStream); item.setStreamInfo(streamInfoByAppAndStream);
redisCatchStorage.addStream(mediaServerItem, type, app, stream, item); redisCatchStorage.addStream(mediaServerItem, type, app, stream, item);
if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()

View File

@ -54,9 +54,10 @@ public class MediaServiceImpl implements IMediaService {
if (mediaInfo == null) { if (mediaInfo == null) {
return null; return null;
} }
String calld = null;
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
if (streamAuthorityInfo == null) { if (streamAuthorityInfo != null) {
return null; calld = streamAuthorityInfo.getCallId();
} }
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream); JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream);
if (mediaList != null) { if (mediaList != null) {
@ -68,7 +69,7 @@ public class MediaServiceImpl implements IMediaService {
JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class);
JSONArray tracks = mediaJSON.getJSONArray("tracks"); JSONArray tracks = mediaJSON.getJSONArray("tracks");
if (authority) { if (authority) {
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,streamAuthorityInfo.getCallId()); streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr, calld);
}else { }else {
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null); streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null);
} }

View File

@ -296,7 +296,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
public boolean start(String app, String stream) { public boolean start(String app, String stream) {
boolean result = false; boolean result = false;
StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
if (!streamProxy.isEnable() ) { if (streamProxy != null && !streamProxy.isEnable() ) {
JSONObject jsonObject = addStreamProxyToZlm(streamProxy); JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
if (jsonObject == null) { if (jsonObject == null) {
return false; return false;

View File

@ -76,8 +76,8 @@ public interface StreamPushMapper {
"WHERE " + "WHERE " +
"1=1 " + "1=1 " +
" <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> " + " <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> " +
" <if test='pushing == true' > AND (gs.gbId is null OR st.status=1)</if>" + " <if test='pushing == true' > AND (gs.gbId is null OR st.pushIng=1)</if>" +
" <if test='pushing == false' > AND st.status=0</if>" + " <if test='pushing == false' > AND st.pushIng=0</if>" +
" <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" + " <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" +
"order by st.createTime desc" + "order by st.createTime desc" +
" </script>"}) " </script>"})

View File

@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.util.StringUtil; import com.github.pagehelper.util.StringUtil;
@ -136,13 +138,9 @@ public class MobilePositionController {
@Parameter(name = "expires", description = "订阅超时时间", required = true) @Parameter(name = "expires", description = "订阅超时时间", required = true)
@Parameter(name = "interval", description = "上报时间间隔", required = true) @Parameter(name = "interval", description = "上报时间间隔", required = true)
@GetMapping("/subscribe/{deviceId}") @GetMapping("/subscribe/{deviceId}")
public String positionSubscribe(@PathVariable String deviceId, public void positionSubscribe(@PathVariable String deviceId,
@RequestParam String expires, @RequestParam String expires,
@RequestParam String interval) { @RequestParam String interval) {
String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置";
if (logger.isDebugEnabled()) {
logger.debug(msg);
}
if (StringUtil.isEmpty(interval)) { if (StringUtil.isEmpty(interval)) {
interval = "5"; interval = "5";
@ -151,13 +149,8 @@ public class MobilePositionController {
device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires)); device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
device.setMobilePositionSubmissionInterval(Integer.parseInt(interval)); device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
deviceService.updateDevice(device); deviceService.updateDevice(device);
String result = msg; if (!deviceService.removeMobilePositionSubscribe(device)) {
if (deviceService.removeMobilePositionSubscribe(device)) { throw new ControllerException(ErrorCode.ERROR100);
result += ",成功";
} else {
result += ",失败";
} }
return result;
} }
} }

View File

@ -56,20 +56,14 @@ public class DeviceControl {
@Operation(summary = "远程启动控制命令") @Operation(summary = "远程启动控制命令")
@Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "deviceId", description = "设备国标编号", required = true)
@GetMapping("/teleboot/{deviceId}") @GetMapping("/teleboot/{deviceId}")
public String teleBootApi(@PathVariable String deviceId) { public void teleBootApi(@PathVariable String deviceId) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("设备远程启动API调用"); logger.debug("设备远程启动API调用");
} }
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
boolean sucsess = cmder.teleBootCmd(device); if (!cmder.teleBootCmd(device)) {
if (sucsess) { logger.warn("设备远程启动API调用失败");
JSONObject json = new JSONObject(); throw new ControllerException(ErrorCode.ERROR100);
json.put("DeviceID", deviceId);
json.put("Result", "OK");
return json.toJSONString();
} else {
logger.warn("设备远程启动API调用失败");
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败");
} }
} }

View File

@ -244,7 +244,7 @@ public class PlatformController {
@Parameter(name = "serverGBId", description = "上级平台的国标编号") @Parameter(name = "serverGBId", description = "上级平台的国标编号")
@DeleteMapping("/delete/{serverGBId}") @DeleteMapping("/delete/{serverGBId}")
@ResponseBody @ResponseBody
public String deletePlatform(@PathVariable String serverGBId) { public void deletePlatform(@PathVariable String serverGBId) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("删除上级平台API调用"); logger.debug("删除上级平台API调用");
@ -278,9 +278,7 @@ public class PlatformController {
dynamicTask.stop(key); dynamicTask.stop(key);
// 删除缓存的订阅信息 // 删除缓存的订阅信息
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId()); subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
if (deleteResult) { if (!deleteResult) {
return null;
} else {
throw new ControllerException(ErrorCode.ERROR100); throw new ControllerException(ErrorCode.ERROR100);
} }
} }

View File

@ -12,14 +12,14 @@ module.exports = {
assetsPublicPath: '/', assetsPublicPath: '/',
proxyTable: { proxyTable: {
'/debug': { '/debug': {
target: 'http://localhost:18080', target: 'http://localhost:38080',
changeOrigin: true, changeOrigin: true,
pathRewrite: { pathRewrite: {
'^/debug': '/' '^/debug': '/'
} }
}, },
'/static/snap': { '/static/snap': {
target: 'http://localhost:18080', target: 'http://localhost:38080',
changeOrigin: true, changeOrigin: true,
// pathRewrite: { // pathRewrite: {
// '^/static/snap': '/static/snap' // '^/static/snap': '/static/snap'

View File

@ -220,7 +220,7 @@
this.getListLoading = true; this.getListLoading = true;
this.$axios({ this.$axios({
method: 'get', method: 'get',
url:`/api/media/stream_info_by_app_and_stream`, url:`/api/push/getPlayUrl`,
params: { params: {
app: row.app, app: row.app,
stream: row.stream, stream: row.stream,