优化异常处理
This commit is contained in:
parent
703c2e292a
commit
3146e63fc0
@ -32,6 +32,7 @@ public class GlobalExceptionHandler {
|
||||
return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义异常处理, 处理controller中返回的错误
|
||||
* @param e 异常
|
||||
|
@ -1,17 +1,23 @@
|
||||
package com.genersoft.iot.vmp.conf;
|
||||
|
||||
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.WVPResult;
|
||||
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.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 全局统一返回结果
|
||||
* @author lin
|
||||
@ -25,6 +31,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) {
|
||||
// 排除api文档的接口,这个接口不需要统一
|
||||
@ -50,4 +57,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
return WVPResult.success(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 防止返回string时出错
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public HttpMessageConverters custHttpMessageConverter() {
|
||||
return new HttpMessageConverters(new FastJsonHttpMessageConverter());
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
|
||||
logger.info("[发送错误订阅]");
|
||||
SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
|
||||
SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent);
|
||||
subscribe.response(eventResult);
|
||||
if (subscribe != null){
|
||||
subscribe.response(eventResult);
|
||||
}
|
||||
sipSubscribe.removeOkSubscribe(callIdHeader.getCallId());
|
||||
sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId());
|
||||
}
|
||||
|
@ -184,8 +184,7 @@ public class ZLMHttpHookListener {
|
||||
if (!"rtp".equals(param.getApp())) {
|
||||
Map<String, String> paramMap = urlParamToMap(param.getParams());
|
||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
|
||||
if (streamAuthorityInfo == null
|
||||
|| (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) {
|
||||
if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) {
|
||||
ret.put("code", 401);
|
||||
ret.put("msg", "Unauthorized");
|
||||
return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
|
||||
@ -476,8 +475,12 @@ public class ZLMHttpHookListener {
|
||||
if (mediaServerItem != null){
|
||||
if (regist) {
|
||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
||||
String callId = null;
|
||||
if (streamAuthorityInfo != null) {
|
||||
callId = streamAuthorityInfo.getCallId();
|
||||
}
|
||||
StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
|
||||
app, stream, tracks, streamAuthorityInfo.getCallId());
|
||||
app, stream, tracks, callId);
|
||||
item.setStreamInfo(streamInfoByAppAndStream);
|
||||
redisCatchStorage.addStream(mediaServerItem, type, app, stream, item);
|
||||
if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
|
||||
|
@ -54,9 +54,10 @@ public class MediaServiceImpl implements IMediaService {
|
||||
if (mediaInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String calld = null;
|
||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
|
||||
if (streamAuthorityInfo == null) {
|
||||
return null;
|
||||
if (streamAuthorityInfo != null) {
|
||||
calld = streamAuthorityInfo.getCallId();
|
||||
}
|
||||
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream);
|
||||
if (mediaList != null) {
|
||||
@ -68,7 +69,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class);
|
||||
JSONArray tracks = mediaJSON.getJSONArray("tracks");
|
||||
if (authority) {
|
||||
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,streamAuthorityInfo.getCallId());
|
||||
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr, calld);
|
||||
}else {
|
||||
streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null);
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
public boolean start(String app, String stream) {
|
||||
boolean result = false;
|
||||
StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
|
||||
if (!streamProxy.isEnable() ) {
|
||||
if (streamProxy != null && !streamProxy.isEnable() ) {
|
||||
JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
|
||||
if (jsonObject == null) {
|
||||
return false;
|
||||
|
@ -76,8 +76,8 @@ public interface StreamPushMapper {
|
||||
"WHERE " +
|
||||
"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='pushing == true' > AND (gs.gbId is null OR st.status=1)</if>" +
|
||||
" <if test='pushing == false' > AND st.status=0</if>" +
|
||||
" <if test='pushing == true' > AND (gs.gbId is null OR st.pushIng=1)</if>" +
|
||||
" <if test='pushing == false' > AND st.pushIng=0</if>" +
|
||||
" <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" +
|
||||
"order by st.createTime desc" +
|
||||
" </script>"})
|
||||
|
@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition;
|
||||
import java.util.List;
|
||||
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.MobilePosition;
|
||||
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.service.IDeviceService;
|
||||
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.github.pagehelper.util.StringUtil;
|
||||
|
||||
@ -136,13 +138,9 @@ public class MobilePositionController {
|
||||
@Parameter(name = "expires", description = "订阅超时时间", required = true)
|
||||
@Parameter(name = "interval", description = "上报时间间隔", required = true)
|
||||
@GetMapping("/subscribe/{deviceId}")
|
||||
public String positionSubscribe(@PathVariable String deviceId,
|
||||
public void positionSubscribe(@PathVariable String deviceId,
|
||||
@RequestParam String expires,
|
||||
@RequestParam String interval) {
|
||||
String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置";
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(msg);
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(interval)) {
|
||||
interval = "5";
|
||||
@ -151,13 +149,8 @@ public class MobilePositionController {
|
||||
device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires));
|
||||
device.setMobilePositionSubmissionInterval(Integer.parseInt(interval));
|
||||
deviceService.updateDevice(device);
|
||||
String result = msg;
|
||||
if (deviceService.removeMobilePositionSubscribe(device)) {
|
||||
result += ",成功";
|
||||
} else {
|
||||
result += ",失败";
|
||||
if (!deviceService.removeMobilePositionSubscribe(device)) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -56,20 +56,14 @@ public class DeviceControl {
|
||||
@Operation(summary = "远程启动控制命令")
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@GetMapping("/teleboot/{deviceId}")
|
||||
public String teleBootApi(@PathVariable String deviceId) {
|
||||
public void teleBootApi(@PathVariable String deviceId) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备远程启动API调用");
|
||||
}
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
boolean sucsess = cmder.teleBootCmd(device);
|
||||
if (sucsess) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("DeviceID", deviceId);
|
||||
json.put("Result", "OK");
|
||||
return json.toJSONString();
|
||||
} else {
|
||||
logger.warn("设备远程启动API调用失败!");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败!");
|
||||
if (!cmder.teleBootCmd(device)) {
|
||||
logger.warn("设备远程启动API调用失败!");
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,7 @@ public class PlatformController {
|
||||
@Parameter(name = "serverGBId", description = "上级平台的国标编号")
|
||||
@DeleteMapping("/delete/{serverGBId}")
|
||||
@ResponseBody
|
||||
public String deletePlatform(@PathVariable String serverGBId) {
|
||||
public void deletePlatform(@PathVariable String serverGBId) {
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("删除上级平台API调用");
|
||||
@ -278,9 +278,7 @@ public class PlatformController {
|
||||
dynamicTask.stop(key);
|
||||
// 删除缓存的订阅信息
|
||||
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
|
||||
if (deleteResult) {
|
||||
return null;
|
||||
} else {
|
||||
if (!deleteResult) {
|
||||
throw new ControllerException(ErrorCode.ERROR100);
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ module.exports = {
|
||||
assetsPublicPath: '/',
|
||||
proxyTable: {
|
||||
'/debug': {
|
||||
target: 'http://localhost:18080',
|
||||
target: 'http://localhost:38080',
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/debug': '/'
|
||||
}
|
||||
},
|
||||
'/static/snap': {
|
||||
target: 'http://localhost:18080',
|
||||
target: 'http://localhost:38080',
|
||||
changeOrigin: true,
|
||||
// pathRewrite: {
|
||||
// '^/static/snap': '/static/snap'
|
||||
|
@ -220,7 +220,7 @@
|
||||
this.getListLoading = true;
|
||||
this.$axios({
|
||||
method: 'get',
|
||||
url:`/api/media/stream_info_by_app_and_stream`,
|
||||
url:`/api/push/getPlayUrl`,
|
||||
params: {
|
||||
app: row.app,
|
||||
stream: row.stream,
|
||||
|
Loading…
Reference in New Issue
Block a user