Merge branch '알람기능_및_UMS_연동' into jenkins_with_weblogic

This commit is contained in:
cho
2026-02-27 13:31:13 +09:00
@@ -1,20 +1,15 @@
package com.eactive.eai.custom.alarm.ums;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.annotation.PreDestroy;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.EntityBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.springframework.stereotype.Component;
@@ -43,24 +38,6 @@ public class UmsService {
private final static String DEFAULT_API_KEY = "7cca6d58-e4f7-474d-9edd-525806bc99ff";
private final static String AUTHORIZATION_FMT = "Bearer %s";
// 재사용되는 HttpClient (Thread-Safe)
private final CloseableHttpClient httpClient;
public UmsService() {
// 커넥션 풀 설정: 매번 소켓을 열고 닫지 않고 재사용함
HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
.setMaxConnTotal(100) // 전체 최대 커넥션 수
.setMaxConnPerRoute(20) // 호스트당 최대 커넥션 수
.setConnectionTimeToLive(TimeValue.ofMinutes(3)) // TTL
.setValidateAfterInactivity(TimeValue.ofSeconds(5)) // 🔥 중요
.build();
this.httpClient = HttpClients.custom()
.setConnectionManager(cm)
.evictExpiredConnections() // 만료 제거
.evictIdleConnections(TimeValue.ofSeconds(20)) // 20초 idle 제거
.build();
}
public UmsCallResult send(UmsRequestPayload payload) throws Exception {
if (payload.getContent() == null) {
@@ -95,6 +72,9 @@ public class UmsService {
.setContentType(ContentType.APPLICATION_JSON)
.setContentEncoding("UTF-8")
.build());
httpPost.setVersion(HttpVersion.HTTP_1_0);
httpPost.setHeader("Connection", "close");
// 3. 타임아웃 설정 (설정파일 값 적용)
RequestConfig config = RequestConfig.custom()
@@ -109,7 +89,7 @@ public class UmsService {
}
// 4. 실행 (HttpClient 재사용)
try {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
return httpClient.execute(httpPost, response -> {
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
@@ -140,15 +120,4 @@ public class UmsService {
}
}
@PreDestroy
public void destroy() {
try {
if (httpClient != null) {
httpClient.close();
logger.info("UMS HttpClient closed.");
}
} catch (IOException e) {
logger.error("Error closing UMS HttpClient", e);
}
}
}