RestTemplateConfig 수정, 추론실행 수정 #19
@@ -5,11 +5,9 @@ import java.net.InetAddress;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
|
|
||||||
public class NetUtils {
|
public class NetUtils {
|
||||||
|
|
||||||
@@ -56,9 +54,8 @@ public class NetUtils {
|
|||||||
|
|
||||||
public HttpHeaders jsonHeaders() {
|
public HttpHeaders jsonHeaders() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.set(HttpHeaders.ACCEPT, "application/json;charset=UTF-8");
|
||||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
headers.set(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.kamco.cd.kamcoback.config.resttemplate;
|
package com.kamco.cd.kamcoback.config.resttemplate;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@@ -18,8 +20,12 @@ public class RestTemplateConfig {
|
|||||||
baseFactory.setConnectTimeout(2000);
|
baseFactory.setConnectTimeout(2000);
|
||||||
baseFactory.setReadTimeout(3000);
|
baseFactory.setReadTimeout(3000);
|
||||||
|
|
||||||
|
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
|
||||||
|
jsonConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
.requestFactory(() -> new BufferingClientHttpRequestFactory(baseFactory))
|
.requestFactory(() -> new BufferingClientHttpRequestFactory(baseFactory))
|
||||||
|
.messageConverters(jsonConverter)
|
||||||
.additionalInterceptors(new RetryInterceptor())
|
.additionalInterceptors(new RetryInterceptor())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package com.kamco.cd.kamcoback.config.resttemplate;
|
package com.kamco.cd.kamcoback.config.resttemplate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.http.HttpRequest;
|
import org.springframework.http.HttpRequest;
|
||||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
public class RetryInterceptor implements ClientHttpRequestInterceptor {
|
public class RetryInterceptor implements ClientHttpRequestInterceptor {
|
||||||
|
|
||||||
private static final int MAX_RETRY = 3;
|
private static final int MAX_RETRY = 3;
|
||||||
@@ -20,21 +23,25 @@ public class RetryInterceptor implements ClientHttpRequestInterceptor {
|
|||||||
|
|
||||||
for (int attempt = 1; attempt <= MAX_RETRY; attempt++) {
|
for (int attempt = 1; attempt <= MAX_RETRY; attempt++) {
|
||||||
try {
|
try {
|
||||||
// HTTP 응답을 받으면(2xx/4xx/5xx 포함) 그대로 반환
|
log.info("[WIRE-REQ] {} {}", request.getMethod(), request.getURI());
|
||||||
return execution.execute(request, body);
|
log.info("[WIRE-REQ-HEADERS] {}", request.getHeaders());
|
||||||
|
log.info("[WIRE-REQ-BODY] {}", new String(body, StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
ClientHttpResponse response = execution.execute(request, body);
|
||||||
|
|
||||||
|
log.info("[WIRE-RES-STATUS] {}", response.getStatusCode());
|
||||||
|
return response;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// 네트워크/타임아웃 등 I/O 예외만 재시도
|
|
||||||
lastException = e;
|
lastException = e;
|
||||||
|
log.error("[WIRE-IO-ERR] attempt={} msg={}", attempt, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 마지막 시도가 아니면 대기
|
|
||||||
if (attempt < MAX_RETRY) {
|
if (attempt < MAX_RETRY) {
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 마지막 예외를 그대로 던져서 원인이 로그에 남게 함
|
|
||||||
throw lastException;
|
throw lastException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,12 @@ import jakarta.persistence.EntityNotFoundException;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
@@ -81,23 +83,28 @@ public class InferenceResultCoreService {
|
|||||||
* @param req
|
* @param req
|
||||||
*/
|
*/
|
||||||
public UUID saveInferenceInfo(InferenceResultDto.RegReq req, List<MngListDto> targetList) {
|
public UUID saveInferenceInfo(InferenceResultDto.RegReq req, List<MngListDto> targetList) {
|
||||||
String firstMapSheetName = null;
|
List<MngListDto> distinctList =
|
||||||
String mapSheetName = "";
|
targetList.stream()
|
||||||
int detectingCnt = 0;
|
.filter(dto -> dto.getMapSheetName() != null && !dto.getMapSheetName().isBlank())
|
||||||
|
.collect(
|
||||||
|
Collectors.toMap(
|
||||||
|
MngListDto::getMapSheetName,
|
||||||
|
dto -> dto,
|
||||||
|
(existing, duplicate) -> existing,
|
||||||
|
LinkedHashMap::new))
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
|
.toList();
|
||||||
|
|
||||||
for (MngListDto dto : targetList) {
|
int detectingCnt = distinctList.size();
|
||||||
if (detectingCnt == 0) {
|
|
||||||
firstMapSheetName = dto.getMapSheetName();
|
|
||||||
}
|
|
||||||
detectingCnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
String mapSheetName;
|
||||||
if (detectingCnt == 0) {
|
if (detectingCnt == 0) {
|
||||||
mapSheetName = "";
|
mapSheetName = "";
|
||||||
} else if (detectingCnt == 1) {
|
} else if (detectingCnt == 1) {
|
||||||
mapSheetName = firstMapSheetName + " 1건";
|
mapSheetName = distinctList.get(0).getMapSheetName() + " 1건";
|
||||||
} else {
|
} else {
|
||||||
mapSheetName = firstMapSheetName + " 외 " + (detectingCnt - 1) + "건";
|
mapSheetName = distinctList.get(0).getMapSheetName() + " 외 " + (detectingCnt - 1) + "건";
|
||||||
}
|
}
|
||||||
|
|
||||||
MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity();
|
MapSheetLearnEntity mapSheetLearnEntity = new MapSheetLearnEntity();
|
||||||
|
|||||||
Reference in New Issue
Block a user