From b5b6dd9a2ef15faeb5eebe0054f39d351572c649 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 14 Jul 2020 22:28:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=A1=E6=A0=B8=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=93=8D=E5=BA=94=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scan/common/enu/SysResponseEnum.java | 2 + ...ception.java => ExecuteHttpException.java} | 13 ++++-- .../scan/controller/ScanController.java | 10 ++--- .../scan/service/impl/ScanServiceImpl.java | 45 +++++++++---------- 4 files changed, 37 insertions(+), 33 deletions(-) rename epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/{ExeCuteHttpException.java => ExecuteHttpException.java} (63%) diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java index 67ee3cc9d2..a05b536f45 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/SysResponseEnum.java @@ -24,6 +24,8 @@ public enum SysResponseEnum { /*审核内容 业务 01*/ SCAN_TASK_LIST_PARAM_ERROR(110010001,"任务列表不能为空"), SCAN_PARAM_ERROR(110010002,"参数格式不正确"), + EXECUTE_ALI_RETURN_CODE_NOT_OK(110010003,"调用第三方检测服务响应异常"), + EXECUTE_ALI_DO_ACTION_EXCEPTION(110010004,"调用第三方检测服务异常"), ; private Integer code; diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java similarity index 63% rename from epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java rename to epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java index 99daf84bae..1eb4f8d0e3 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExeCuteHttpException.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/exception/ExecuteHttpException.java @@ -8,16 +8,23 @@ import com.epmet.openapi.scan.common.enu.SysResponseEnum; * @email liujianjun@yunzongnet.com * @date 2020-06-05 10:31 **/ -public class ExeCuteHttpException extends RuntimeException { +public class ExecuteHttpException extends RuntimeException { private int code; private String msg; - public ExeCuteHttpException(String msg) { + public ExecuteHttpException(String msg) { this(SysResponseEnum.EXCEPTION.getCode(), msg); } - public ExeCuteHttpException(int code, String... params) { + public ExecuteHttpException(int code, String... params) { this.code = code; this.msg = MessageUtils.getMessage(code, params); + } + + public int getCode() { + return code; + } + public String getMsg() { + return msg; } } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java index efaae3ddd5..e32460ce44 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/controller/ScanController.java @@ -24,7 +24,6 @@ public class ScanController { @Autowired private ScanService scanService; - /** * desc:图片同步检测接口 * @@ -34,8 +33,7 @@ public class ScanController { @RequestMapping("imgSyncScan") public Result ImgSyncScan(@RequestBody ImgScanParam param) { ValidatorUtils.validateEntity(param); - Result scanResultResult = scanService.sendSyncImgScan(param); - return scanResultResult; + return scanService.sendSyncImgScan(param); } /** @@ -47,13 +45,11 @@ public class ScanController { @RequestMapping("textSyncScan") public Result textSyncScan(@RequestBody TextScanParam param) { ValidatorUtils.validateEntity(param); - Result scanResultResult = scanService.sendTextScan(param); - return scanResultResult; + return scanService.sendTextScan(param); } //@RequestMapping("imgAsyncScan") public Result ImgAsyncScan(@RequestBody ImgScanParam param) { - Result scanResultResult = scanService.sendASyncImgScan(param); - return scanResultResult; + return scanService.sendASyncImgScan(param); } } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java index 58fd107bc0..1a88b5b86f 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -15,7 +15,7 @@ import com.epmet.openapi.scan.common.enu.ImgSceneEnum; import com.epmet.openapi.scan.common.enu.SuggestionEnum; import com.epmet.openapi.scan.common.enu.SysResponseEnum; import com.epmet.openapi.scan.common.enu.TextSceneEnum; -import com.epmet.openapi.scan.common.exception.ExeCuteHttpException; +import com.epmet.openapi.scan.common.exception.ExecuteHttpException; import com.epmet.openapi.scan.common.util.IAcsClientUtil; import com.epmet.openapi.scan.support.param.ImgScanParam; import com.epmet.openapi.scan.support.param.ImgTask; @@ -49,7 +49,6 @@ public class ScanServiceImpl implements ScanService { @Override public Result sendTextScan(TextScanParam textScanParam) { - //默认参数 // 鉴黄 暴恐涉政 textScanParam.setScenes(TextSceneEnum.getTextSceneList()); @@ -69,7 +68,7 @@ public class ScanServiceImpl implements ScanService { try { textScanRequest.setHttpContent(JSON.toJSONString(textScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); } catch (UnsupportedEncodingException e) { - log.error("sendTextScan exception", e.getMessage()); + log.error("sendTextScan parse param exception", e); } @@ -78,18 +77,18 @@ public class ScanServiceImpl implements ScanService { */ textScanRequest.setConnectTimeout(3000); textScanRequest.setReadTimeout(6000); + try { SyncScanResult textScanResult = executeSyncText(textScanRequest); return new Result().ok(textScanResult); - } catch (Exception e) { - log.error("sendTextScan exception", e); - throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } catch (ExecuteHttpException e) { + log.error("sendTextScan execute Exception", e); + return new Result().error(e.getCode(), e.getMsg()); } } @Override public Result sendSyncImgScan(ImgScanParam imgScanParam) { - ImageSyncScanRequest imageSyncScanRequest = new ImageSyncScanRequest(); imageSyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式 imageSyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法 @@ -109,7 +108,7 @@ public class ScanServiceImpl implements ScanService { try { imageSyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); } catch (UnsupportedEncodingException e) { - log.error("sendSyncImgScan exception", e.getMessage()); + log.error("sendSyncImgScan parse param exception", e); return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); } @@ -122,9 +121,9 @@ public class ScanServiceImpl implements ScanService { try { SyncScanResult scanResult = executeSyncImg(imageSyncScanRequest); return new Result().ok(scanResult); - } catch (Exception e) { - log.error("sendImgScan execute Exception", e); - return new Result().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + } catch (ExecuteHttpException e) { + log.error("sendImgScan execute exception,param:{},fail msg:{}", JSON.toJSONString(imgScanParam), e.getMsg()); + return new Result().error(e.getCode(), e.getMsg()); } } @@ -149,7 +148,7 @@ public class ScanServiceImpl implements ScanService { try { imageAsyncScanRequest.setHttpContent(JSON.toJSONString(imgScanParam).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); } catch (UnsupportedEncodingException e) { - log.error("sendASyncImgScan exception", e.getMessage()); + log.error("sendASyncImgScan parse param exception", e); return new Result().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); } @@ -163,7 +162,7 @@ public class ScanServiceImpl implements ScanService { ImgAsyncScanResult scanResult = null;//executeAsyncImg(imageAsyncScanRequest); return new Result().ok(scanResult); } catch (Exception e) { - log.error("sendImgScan execute Exception", e); + //log.error("sendASyncImgScan execute exception,param:{},fail msg:{}",JSON.toJSONString(imgScanParam), e.getMsg()); return new Result().error(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); } } @@ -209,15 +208,15 @@ public class ScanServiceImpl implements ScanService { return result; } else { log.warn("executeSyncText response not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExeCuteHttpException("executeSyncText detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getCode(), SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getMsg() + ",status:" + httpResponse.getStatus()); } } else { - log.warn("executeSyncText response not success. status:{}", httpResponse.getStatus()); - throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); + log.warn("executeSyncText response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getCode(), SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getMsg() + ",status:" + httpResponse.getStatus()); } } catch (Exception e) { - log.warn("executeSyncText exception", e); - throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + log.error("executeSyncText exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_DO_ACTION_EXCEPTION.getCode(), SysResponseEnum.EXECUTE_ALI_DO_ACTION_EXCEPTION.getMsg()); } } @@ -260,15 +259,15 @@ public class ScanServiceImpl implements ScanService { return result; } else { log.warn("executeSyncImg detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); - throw new ExeCuteHttpException("detect not success. code:" + scrResponse.getInteger(SysConstant.CODE)); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getCode(), SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getMsg() + ",status:" + httpResponse.getStatus()); } } else { - log.warn("executeSyncImg response not success. status:{}", httpResponse.getStatus()); - throw new ExeCuteHttpException("response not success. status:" + httpResponse.getStatus()); + log.warn("executeSyncImg response status is not success. httpResponse:{}", JSON.toJSONString(httpResponse)); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getCode(), SysResponseEnum.EXECUTE_ALI_RETURN_CODE_NOT_OK.getMsg() + ",status:" + httpResponse.getStatus()); } } catch (Exception e) { - log.warn("executeSyncImg exception", e); - throw new ExeCuteHttpException(SysResponseEnum.EXCEPTION.getCode(), SysResponseEnum.EXCEPTION.getMsg()); + log.error("executeSyncImg exception IAcsClientUtil do action exception", e); + throw new ExecuteHttpException(SysResponseEnum.EXECUTE_ALI_DO_ACTION_EXCEPTION.getCode(), SysResponseEnum.EXECUTE_ALI_DO_ACTION_EXCEPTION.getMsg()); } } }