diff --git a/src/main/java/com/interplug/qcast/batch/system/AdminUserConfiguration.java b/src/main/java/com/interplug/qcast/batch/system/AdminUserConfiguration.java index 15d71ffd..d071c82f 100644 --- a/src/main/java/com/interplug/qcast/batch/system/AdminUserConfiguration.java +++ b/src/main/java/com/interplug/qcast/batch/system/AdminUserConfiguration.java @@ -71,7 +71,12 @@ public class AdminUserConfiguration implements JobExecutionListener { @Bean public ItemProcessor adminUserProcessor() { - return item -> item; + return item -> { + if (item.getCategory() != null && item.getCategory().length() > 20) { + item.setCategory(item.getCategory().substring(0, 20)); + } + return item; + }; } @Bean diff --git a/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java b/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java index 3d556324..85f85bfb 100644 --- a/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java +++ b/src/main/java/com/interplug/qcast/config/Exception/GlobalExceptionHandler.java @@ -1,6 +1,7 @@ package com.interplug.qcast.config.Exception; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -12,6 +13,7 @@ public class GlobalExceptionHandler { @ExceptionHandler(HttpRequestMethodNotSupportedException.class) protected ResponseEntity handle(HttpRequestMethodNotSupportedException e) { return ResponseEntity.badRequest() + .contentType(MediaType.APPLICATION_JSON) .body(ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED.getMessage())); } @@ -19,6 +21,7 @@ public class GlobalExceptionHandler { protected ResponseEntity handle(BaseException e) { final ErrorCode errorCode = e.getErrorCode(); return ResponseEntity.status(errorCode.getStatus()) + .contentType(MediaType.APPLICATION_JSON) .body(ErrorResponse.of(errorCode.getMessage())); } @@ -27,14 +30,18 @@ public class GlobalExceptionHandler { final ErrorCode errorCode = e.getErrorCode(); if (e.getMessage() == null) { return ResponseEntity.status(errorCode.getStatus()) + .contentType(MediaType.APPLICATION_JSON) .body(ErrorResponse.of(errorCode.getMessage())); } - return ResponseEntity.status(errorCode.getStatus()).body(ErrorResponse.of(e.getMessage())); + return ResponseEntity.status(errorCode.getStatus()) + .contentType(MediaType.APPLICATION_JSON) + .body(ErrorResponse.of(e.getMessage())); } @ExceptionHandler(Exception.class) protected ResponseEntity handle(Exception e) { return ResponseEntity.internalServerError() + .contentType(MediaType.APPLICATION_JSON) .body(ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR.getMessage())); } } diff --git a/src/main/java/com/interplug/qcast/util/InterfaceQsp.java b/src/main/java/com/interplug/qcast/util/InterfaceQsp.java index f813a461..384b625f 100644 --- a/src/main/java/com/interplug/qcast/util/InterfaceQsp.java +++ b/src/main/java/com/interplug/qcast/util/InterfaceQsp.java @@ -37,41 +37,41 @@ public class InterfaceQsp { * @return String * @throws Exception */ - public String callApi(HttpMethod httpMethod, String apiPath, Object requestObject) - throws Exception { - - URL url = null; - HttpURLConnection con = null; + public String callApi(HttpMethod httpMethod, String apiPath, Object requestObject) + throws Exception { + + URL url = null; + HttpURLConnection con = null; OutputStreamWriter osw = null; - BufferedReader br = null; - StringBuilder sb = null; - long startAt = System.currentTimeMillis(); - String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName(); - - try { - - // GET 요청 시 requestObject를 쿼리 스트링으로 변환 - if (HttpMethod.GET.equals(httpMethod) && requestObject != null) { + BufferedReader br = null; + StringBuilder sb = null; + long startAt = System.currentTimeMillis(); + String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName(); + + try { + + // GET 요청 시 requestObject를 쿼리 스트링으로 변환 + if (HttpMethod.GET.equals(httpMethod) && requestObject != null) { ObjectMapper om = new ObjectMapper(); Map params = om.convertValue(requestObject, Map.class); // Object -> Map 변환 String queryString = params.entrySet().stream() .map(entry -> entry.getKey() + "=" + entry.getValue()) - .reduce((p1, p2) -> p1 + "&" + p2) - .orElse(""); - apiPath += "?" + queryString; // 쿼리 스트링 추가 - } - - log.debug( - "QSP API call start: method={}, url={}, requestType={}", - httpMethod, - apiPath, - requestType); - url = new URL(apiPath); - con = (HttpURLConnection) url.openConnection(); - con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정 - con.setReadTimeout(120000); // InputStream 읽어 오는 Timeout 시간 설정 - con.setRequestMethod(httpMethod.toString()); + .reduce((p1, p2) -> p1 + "&" + p2) + .orElse(""); + apiPath += "?" + queryString; // 쿼리 스트링 추가 + } + + log.debug( + "QSP API call start: method={}, url={}, requestType={}", + httpMethod, + apiPath, + requestType); + url = new URL(apiPath); + con = (HttpURLConnection) url.openConnection(); + con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정 + con.setReadTimeout(120000); // InputStream 읽어 오는 Timeout 시간 설정 + con.setRequestMethod(httpMethod.toString()); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Referer", frontUrl); con.setDoInput(true); @@ -91,33 +91,34 @@ public class InterfaceQsp { } sb = new StringBuilder(); - int status = con.getResponseCode(); - if (status == HttpURLConnection.HTTP_OK) { - br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8")); - - String line; - while ((line = br.readLine()) != null) { - sb.append(line); - } - } - log.debug( - "QSP API call end: method={}, url={}, status={}, durationMs={}", - httpMethod, - apiPath, - status, - System.currentTimeMillis() - startAt); - } catch (Exception e) { - log.error( - "QSP API call failed: method={}, url={}, durationMs={}", - httpMethod, - apiPath, - System.currentTimeMillis() - startAt, - e); - throw e; - } finally { - try { - if (osw != null) osw.close(); - if (br != null) br.close(); + int status = con.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { + log.info("[DEBUG] QSP Content-Type: {}", con.getContentType()); + br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8")); + + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } + log.debug( + "QSP API call end: method={}, url={}, status={}, durationMs={}", + httpMethod, + apiPath, + status, + System.currentTimeMillis() - startAt); + } catch (Exception e) { + log.error( + "QSP API call failed: method={}, url={}, durationMs={}", + httpMethod, + apiPath, + System.currentTimeMillis() - startAt, + e); + throw e; + } finally { + try { + if (osw != null) osw.close(); + if (br != null) br.close(); } catch (Exception e) { throw e; } @@ -176,30 +177,30 @@ public class InterfaceQsp { * @return String * @throws Exception */ - public byte[] callApi( - HttpMethod httpMethod, String apiPath, Object requestObject, Map result) - throws Exception { - - URL url = null; + public byte[] callApi( + HttpMethod httpMethod, String apiPath, Object requestObject, Map result) + throws Exception { + + URL url = null; HttpURLConnection con = null; OutputStreamWriter osw = null; - BufferedReader br = null; - - byte[] bt = null; - long startAt = System.currentTimeMillis(); - String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName(); - - try { - log.debug( - "QSP API call start: method={}, url={}, requestType={}", - httpMethod, - apiPath, - requestType); - url = new URL(apiPath); - con = (HttpURLConnection) url.openConnection(); - con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정 - con.setReadTimeout(30000); // InputStream 읽어 오는 Timeout 시간 설정 - con.setRequestMethod(httpMethod.toString()); + BufferedReader br = null; + + byte[] bt = null; + long startAt = System.currentTimeMillis(); + String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName(); + + try { + log.debug( + "QSP API call start: method={}, url={}, requestType={}", + httpMethod, + apiPath, + requestType); + url = new URL(apiPath); + con = (HttpURLConnection) url.openConnection(); + con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정 + con.setReadTimeout(30000); // InputStream 읽어 오는 Timeout 시간 설정 + con.setRequestMethod(httpMethod.toString()); con.setRequestProperty("Content-Type", "application/json"); con.setRequestProperty("Referer", frontUrl); con.setDoInput(true); @@ -217,40 +218,40 @@ public class InterfaceQsp { osw.flush(); } } - int status = con.getResponseCode(); - if (status == HttpURLConnection.HTTP_OK) { - // response 헤더 값 결과 셋팅 - result.put("type", con.getHeaderField("Content-Type")); - result.put("disposition", con.getHeaderField("Content-Disposition")); - - InputStream inputStream = con.getInputStream(); + int status = con.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { + // response 헤더 값 결과 셋팅 + result.put("type", con.getHeaderField("Content-Type")); + result.put("disposition", con.getHeaderField("Content-Disposition")); + + InputStream inputStream = con.getInputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); - } - bt = outputStream.toByteArray(); // 파일 데이터 반환 - } - log.debug( - "QSP API call end: method={}, url={}, status={}, durationMs={}", - httpMethod, - apiPath, - status, - System.currentTimeMillis() - startAt); - } catch (Exception e) { - log.error( - "QSP API call failed: method={}, url={}, durationMs={}", - httpMethod, - apiPath, - System.currentTimeMillis() - startAt, - e); - throw e; - } finally { - try { - if (osw != null) osw.close(); - if (br != null) br.close(); + } + bt = outputStream.toByteArray(); // 파일 데이터 반환 + } + log.debug( + "QSP API call end: method={}, url={}, status={}, durationMs={}", + httpMethod, + apiPath, + status, + System.currentTimeMillis() - startAt); + } catch (Exception e) { + log.error( + "QSP API call failed: method={}, url={}, durationMs={}", + httpMethod, + apiPath, + System.currentTimeMillis() - startAt, + e); + throw e; + } finally { + try { + if (osw != null) osw.close(); + if (br != null) br.close(); } catch (Exception e) { throw e; } diff --git a/src/main/resources/mappers/estimate/estimateMapper.xml b/src/main/resources/mappers/estimate/estimateMapper.xml index 90931dbb..ed91b6b9 100644 --- a/src/main/resources/mappers/estimate/estimateMapper.xml +++ b/src/main/resources/mappers/estimate/estimateMapper.xml @@ -91,91 +91,94 @@