From c0689d5f1b11f5725c0816d581ef8733b373132c Mon Sep 17 00:00:00 2001 From: limju Date: Mon, 25 Sep 2023 11:08:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20API=20=EC=97=90=EB=9F=AC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/xit/core/aop/TraceLoggerAspect.java | 12 ++++---- .../main/resources/config/application-ens.yml | 11 ++++---- .../kr/xit/core/aop/TraceLoggerAspect.java | 12 ++++---- .../kr/xit/core/model/ApiResponseDTO.java | 28 ++++++++++--------- .../main/java/kr/xit/core/model/ErrorDTO.java | 10 +++---- .../handler/CustomRestExceptionHandler.java | 20 +++++-------- .../core/spring/util/ApiWebClientUtil.java | 3 +- .../core/spring/util/error/ErrorParse.java | 28 +++++++------------ 8 files changed, 54 insertions(+), 70 deletions(-) diff --git a/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java b/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java index 4423ec6..99678b9 100644 --- a/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java +++ b/mens-api/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java @@ -269,28 +269,26 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap()); log.info("~~~~~~~~~~~~~~~~~~~~~~~>>>>{}", MDC.get(REQUEST_TRACE_ID)); if(Checks.isEmpty(MDC.get(REQUEST_TRACE_ID))) return; - Map map = ErrorParse.extractError(e); + ApiResponseDTO dto = ErrorParse.extractError(e); loggingService.modifyLogging( LoggingDTO .builder() .requestId(MDC.get(REQUEST_TRACE_ID)) .success("false") - .response(JsonUtils.toJson(ApiResponseDTO.error(String.valueOf(map.get(CODE)), String.valueOf(map.get(MESSAGE)), (HttpStatus)map.get("httpStatus")))) - .message(String.valueOf(map.get(MESSAGE))) + .response(JsonUtils.toJson(dto)) + .message(dto.getMessage()) .build()); //FIXME :: slack webhook log push if(isSlackEnabled){ if(RequestContextHolder.getRequestAttributes() != null) { slackWebhookPush.sendSlackAlertLog( - String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)), - String.valueOf(map.get(MESSAGE))), + String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()), ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest()); }else{ slackWebhookPush.sendSlackAlertLog( - String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)), - String.valueOf(map.get(MESSAGE))), + String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()), MDC.get("uri"), "batch call"); } diff --git a/mens-api/src/main/resources/config/application-ens.yml b/mens-api/src/main/resources/config/application-ens.yml index 8e3342c..e0f4a1a 100644 --- a/mens-api/src/main/resources/config/application-ens.yml +++ b/mens-api/src/main/resources/config/application-ens.yml @@ -39,11 +39,12 @@ contract: ci: /digital/niceid/cert/v1.0/ipin/addinfo/ci kt: dummy: true - # vpn 사용전 - host: http://172.16.0.13:10210/ONLWeb # vpn 사용 -# host: http://211.43.10.163:10210/ONLWeb +# host: http://172.16.0.13:10210/ONLWeb + # 공인 IP + host: http://211.43.10.163:10210/ONLWeb # 운영 #host: http://172.16.1.182:10210/ONLWeb -# signgu-code: 11000 -# ffnlg-code: 11 + api: + generate-token: /oauth/token + before-send: /api/message/before/send diff --git a/mens-batch/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java b/mens-batch/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java index fcc9c33..a1ea2bd 100644 --- a/mens-batch/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java +++ b/mens-batch/src/main/java/kr/xit/core/aop/TraceLoggerAspect.java @@ -227,28 +227,26 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap()); log.info("~~~~~~~~~~~~~~~~~~~~~~~>>>>{}", MDC.get(REQUEST_TRACE_ID)); if(Checks.isEmpty(MDC.get(REQUEST_TRACE_ID))) return; - Map map = ErrorParse.extractError(e); + ApiResponseDTO dto = ErrorParse.extractError(e); loggingService.modifyLogging( LoggingDTO .builder() .requestId(MDC.get(REQUEST_TRACE_ID)) .success("false") - .response(JsonUtils.toJson(ApiResponseDTO.error(String.valueOf(map.get(CODE)), String.valueOf(map.get(MESSAGE)), (HttpStatus)map.get("httpStatus")))) - .message(String.valueOf(map.get(MESSAGE))) + .response(JsonUtils.toJson(dto)) + .message(dto.getMessage()) .build()); //FIXME :: slack webhook log push if(isSlackEnabled){ if(RequestContextHolder.getRequestAttributes() != null) { slackWebhookPush.sendSlackAlertLog( - String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)), - String.valueOf(map.get(MESSAGE))), + String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()), ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest()); }else{ slackWebhookPush.sendSlackAlertLog( - String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)), - String.valueOf(map.get(MESSAGE))), + String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()), MDC.get("uri"), "batch call"); } diff --git a/mens-core/src/main/java/kr/xit/core/model/ApiResponseDTO.java b/mens-core/src/main/java/kr/xit/core/model/ApiResponseDTO.java index e05371d..c98ec2a 100644 --- a/mens-core/src/main/java/kr/xit/core/model/ApiResponseDTO.java +++ b/mens-core/src/main/java/kr/xit/core/model/ApiResponseDTO.java @@ -1,33 +1,31 @@ package kr.xit.core.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.google.gson.GsonBuilder; +import io.swagger.v3.oas.annotations.media.Schema; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; - -import org.apache.commons.lang.StringUtils; -import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; -import org.springframework.http.HttpStatus; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; -import org.springframework.validation.ObjectError; - -import com.google.gson.GsonBuilder; - -import io.swagger.v3.oas.annotations.media.Schema; import kr.xit.core.consts.ErrorCode; import kr.xit.core.exception.BizRuntimeException; import kr.xit.core.support.utils.Checks; import kr.xit.core.support.utils.ConvertHelper; import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; +import org.springframework.http.HttpStatus; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; /** *
@@ -46,7 +44,11 @@ import lombok.Setter;
 @Schema(name = "ApiResponseDTO", description = "Restful API 결과")
 @Getter
 @NoArgsConstructor(access = AccessLevel.PROTECTED)
-public class ApiResponseDTO implements Serializable {
+@AllArgsConstructor
+@Builder
+@JsonRootName("result")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class ApiResponseDTO implements IApiResponse {
     private static final String FAIL_STATUS = "fail";
     private static final String ERROR_STATUS = "error";
 
diff --git a/mens-core/src/main/java/kr/xit/core/model/ErrorDTO.java b/mens-core/src/main/java/kr/xit/core/model/ErrorDTO.java
index ac62c8e..c5c162d 100644
--- a/mens-core/src/main/java/kr/xit/core/model/ErrorDTO.java
+++ b/mens-core/src/main/java/kr/xit/core/model/ErrorDTO.java
@@ -1,12 +1,11 @@
 package kr.xit.core.model;
 
-import javax.validation.constraints.Size;
-
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
-
 import io.swagger.v3.oas.annotations.media.Schema;
+import javax.validation.constraints.Size;
 import lombok.AllArgsConstructor;
-import lombok.Data;
+import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.experimental.SuperBuilder;
 
@@ -26,10 +25,11 @@ import lombok.experimental.SuperBuilder;
  * 
*/ @Schema(name = "ErrorDTO", description = "에러 DTO") -@Data +@Getter @SuperBuilder @NoArgsConstructor @AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) public class ErrorDTO implements IApiResponse { /** * 에러 코드(max:40) diff --git a/mens-core/src/main/java/kr/xit/core/spring/handler/CustomRestExceptionHandler.java b/mens-core/src/main/java/kr/xit/core/spring/handler/CustomRestExceptionHandler.java index 9156e2a..a21f539 100644 --- a/mens-core/src/main/java/kr/xit/core/spring/handler/CustomRestExceptionHandler.java +++ b/mens-core/src/main/java/kr/xit/core/spring/handler/CustomRestExceptionHandler.java @@ -4,15 +4,17 @@ import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.CompletionException; - import javax.validation.ConstraintViolationException; - +import kr.xit.core.consts.ErrorCode; +import kr.xit.core.exception.BizRuntimeException; +import kr.xit.core.model.ApiResponseDTO; +import kr.xit.core.spring.util.error.ErrorParse; +import kr.xit.core.support.utils.Checks; +import lombok.extern.slf4j.Slf4j; import org.egovframe.rte.fdl.cmmn.exception.EgovBizException; -import org.slf4j.MDC; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -22,13 +24,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import kr.xit.core.consts.ErrorCode; -import kr.xit.core.model.ApiResponseDTO; -import kr.xit.core.exception.BizRuntimeException; -import kr.xit.core.spring.util.error.ErrorParse; -import kr.xit.core.support.utils.Checks; -import lombok.extern.slf4j.Slf4j; - /** *
  * description : ExceptionHandlerFilter(Filter에서 발생한 에러 처리)와 함께 에러 처리
@@ -204,7 +199,6 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
 
 
     private ApiResponseDTO sendError(Throwable e) {
-        Map map = ErrorParse.extractError(Checks.checkVal(e.getCause(), e));
-        return ApiResponseDTO.error(String.valueOf(map.get("code")), String.valueOf(map.get("message")), (HttpStatus)map.get("httpStatus"));
+        return ErrorParse.extractError(Checks.checkVal(e.getCause(), e));
     }
 }
diff --git a/mens-core/src/main/java/kr/xit/core/spring/util/ApiWebClientUtil.java b/mens-core/src/main/java/kr/xit/core/spring/util/ApiWebClientUtil.java
index 6752cdf..94edc9c 100644
--- a/mens-core/src/main/java/kr/xit/core/spring/util/ApiWebClientUtil.java
+++ b/mens-core/src/main/java/kr/xit/core/spring/util/ApiWebClientUtil.java
@@ -154,8 +154,7 @@ public class ApiWebClientUtil {
 
     public  ApiResponseDTO sendError(final Throwable e) {
 
-        Map map = ErrorParse.extractError(e.getCause());
-        return ApiResponseDTO.error(String.valueOf(map.get("code")), String.valueOf(map.get("message")), (HttpStatus)map.get("httpStatus"));
+        return ErrorParse.extractError(e.getCause());
     }
 
     private URI createUrl(final String endPoint, final String... value) {
diff --git a/mens-core/src/main/java/kr/xit/core/spring/util/error/ErrorParse.java b/mens-core/src/main/java/kr/xit/core/spring/util/error/ErrorParse.java
index 0b09767..fcdfb38 100644
--- a/mens-core/src/main/java/kr/xit/core/spring/util/error/ErrorParse.java
+++ b/mens-core/src/main/java/kr/xit/core/spring/util/error/ErrorParse.java
@@ -1,23 +1,19 @@
 package kr.xit.core.spring.util.error;
 
-import java.util.HashMap;
-import java.util.Map;
+import io.netty.channel.ConnectTimeoutException;
+import io.netty.handler.timeout.ReadTimeoutException;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
-
 import kr.xit.core.exception.BizRuntimeException;
+import kr.xit.core.model.ApiResponseDTO;
+import kr.xit.core.model.ErrorDTO;
+import kr.xit.core.support.utils.Checks;
+import kr.xit.core.support.utils.JsonUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.HttpStatus;
 import org.springframework.web.reactive.function.client.WebClientRequestException;
 
-import io.netty.channel.ConnectTimeoutException;
-import io.netty.handler.timeout.ReadTimeoutException;
-import kr.xit.core.model.ErrorDTO;
-import kr.xit.core.support.utils.Checks;
-import kr.xit.core.support.utils.JsonUtils;
-
 /**
  * 
  * description :
@@ -35,7 +31,7 @@ import kr.xit.core.support.utils.JsonUtils;
  */
 public class ErrorParse {
 
-    public static Map extractError(final Throwable e){
+    public static ApiResponseDTO extractError(final Throwable e){
         String errCode = String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value());
         String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
         HttpStatus httpStatus = null;
@@ -93,15 +89,11 @@ public class ErrorParse {
     }
 
     @NotNull
-    private static Map getStringObjectMap(String errCode, String message, HttpStatus httpStatus) {
-        Map errorMap = new HashMap<>();
-        errorMap.put("code", errCode);
-        errorMap.put("message", message);
-        errorMap.put("httpStatus", httpStatus);
-        return errorMap;
+    private static ApiResponseDTO getStringObjectMap(String errCode, String message, HttpStatus httpStatus) {
+        return ApiResponseDTO.error(errCode, message, httpStatus);
     }
 
-    private static  Map getTimeoutException(){
+    private static  ApiResponseDTO getTimeoutException(){
         return getStringObjectMap(
                 String.valueOf(HttpStatus.REQUEST_TIMEOUT.value()),
                 HttpStatus.REQUEST_TIMEOUT.getReasonPhrase(),