From 61c9aa9864a1aa9d2876562131003ce0b73a3fe8 Mon Sep 17 00:00:00 2001 From: curry772 Date: Mon, 13 Jul 2026 13:25:38 +0900 Subject: [PATCH] =?UTF-8?q?REST,=20HTTP=20=EC=96=B4=EB=8C=91=ED=84=B0=20?= =?UTF-8?q?=EC=9E=AC=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EB=B3=B4?= =?UTF-8?q?=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/impl/DeadlineAwareRetryExecutor.java | 16 ++++++++-------- .../impl/HttpClient5AdapterServiceBody.java | 11 ++++++++++- .../adapter/http/client/impl/RetryPolicy.java | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/DeadlineAwareRetryExecutor.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/DeadlineAwareRetryExecutor.java index 43bc80b..b0ffd57 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/DeadlineAwareRetryExecutor.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/DeadlineAwareRetryExecutor.java @@ -88,10 +88,17 @@ public class DeadlineAwareRetryExecutor { if (!policy.shouldRetryOnStatus(request, status)) { // 성공 또는 재시도 불필요 → 호출부에서 close 책임 - log.debug("non-retryable response status={}, attempt={}", status, attempt + 1); + log.info("non-retryable response status={}, attempt={}", status, attempt + 1); return response; } + // ④ 마지막 시도였으면 종료 + if (attempt >= policy.getMaxRetries()) { + // 최대 재처리에 도달하여, 재시도하지 않고, 응답 객체를 리턴한다. + log.info("최대 재시도 횟수 도달 response status={}, attempt={}", status, attempt + 1); + return response; + } + // 재시도 대상 log.warn("retryable status={}, attempt={}/{}", status, attempt + 1, policy.getMaxRetries()); @@ -127,9 +134,6 @@ public class DeadlineAwareRetryExecutor { } } - // ④ 마지막 시도였으면 바로 종료 - if (attempt >= policy.getMaxRetries()) break; - // ⑤ 백오프 대기 전 남은 시간 재확인 long remainingBeforeWait = totalDeadlineMs - (System.currentTimeMillis() - startTime); if (remainingBeforeWait <= policy.getBackoffMs()) { @@ -171,10 +175,6 @@ public class DeadlineAwareRetryExecutor { log.info("RequestConfig = {}", config); } - private boolean isSuccess(int status) { - return status >= 200 && status < 300; - } - private void closeQuietly(CloseableHttpResponse response) { try { response.close(); diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceBody.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceBody.java index f4c1665..511072a 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceBody.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceBody.java @@ -14,6 +14,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.StopWatch; import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpHost; @@ -135,7 +136,15 @@ public class HttpClient5AdapterServiceBody extends HttpClient5AdapterServiceSupp byte[] responseMessage = null; String responseString = ""; - try (CloseableHttpResponse response = (CloseableHttpResponse) this.client.execute(method, context)) { + + DeadlineAwareRetryExecutor executor = + new DeadlineAwareRetryExecutor((CloseableHttpClient)this.client, + vo.getConnectionTimeout(), + vo.getTimeout()); + + // Properties에서 RetryPolicy 로드 + RetryPolicy policy = RetryPolicy.from(prop); // 설정 로드 방식에 맞게 + try (CloseableHttpResponse response = (CloseableHttpResponse) executor.execute(method, context, policy)) { status = response.getCode(); responseMessage = EntityUtils.toByteArray(response.getEntity()); responseString = new String(responseMessage, vo.getEncode()); diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/RetryPolicy.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/RetryPolicy.java index 99879a2..7639550 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/RetryPolicy.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/RetryPolicy.java @@ -65,7 +65,7 @@ public class RetryPolicy { return new RetryPolicy(getInt(props, RETRY_MAX_RETRIES, 0), getLong(props, RETRY_BACKOFF_MS, 1000L), codes, getBoolean(props, RETRY_ON_CONNECT_FAIL, false), getBoolean(props, RETRY_ON_TIMEOUT, false), - getBoolean(props, RETRY_IDEMPOTENT_ONLY, true)); + getBoolean(props, RETRY_IDEMPOTENT_ONLY, false)); } // ----------------------------------------------------------------