서버 테스트 반영

This commit is contained in:
Rinjae
2025-10-22 11:32:36 +09:00
parent 798f4e7ace
commit 3b7c4d4683
10 changed files with 170 additions and 48 deletions
@@ -6,9 +6,12 @@ import com.eactive.ext.kjb.common.KjbProperty;
import com.eactive.ext.kjb.ums.gson.IUmsGsonObject;
import com.eactive.ext.kjb.ums.gson.UmsRequestPayload;
import com.eactive.ext.kjb.ums.gson.VerifyPhoneUmsTemplate;
import com.eactive.ext.kjb.utils.JsonUtil;
import com.eactive.ext.kjb.utils.ValidationUtil;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
@@ -16,13 +19,17 @@ 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.core5.http.ContentType;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.util.Timeout;
import org.springframework.util.StreamUtils;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
@@ -104,13 +111,25 @@ public class KjbUmsService {
.msgSndChnlCd(UmsRequestPayload.ChannelCode.KM)
.build();
return callUms(SEND_URL, payload, (messageId, ex) -> {
try {
ValidationUtil.validateOrThrow(payload);
} catch (Exception ex) {
log.debug("UMS Request payload validation failed - {}", JsonUtil.toPrettyString(payload));
throw ex;
}
return callUms(SEND_URL, payload, (result, ex) -> {
if (ex != null) {
log.error("UMS Call error", ex);
log.error("UMS 발송 실패", ex);
throw new RuntimeException(ex);
}
log.info("UMS Call success. ({})", messageId);
if (result == null || !result.isSuccess()) {
log.error("UMS 발송 실패(return) - {}", JsonUtil.toPrettyString(result));
throw new RuntimeException("UMS 발송실패 - " + JsonUtil.toPrettyString(result != null ? result.getThrowable().getMessage() : "UMS 발송실패 - 알수 없는 오류"));
}
log.info("UMS Call success. ({})", result);
}).join().getUmsMessageId();
}
@@ -126,19 +145,52 @@ public class KjbUmsService {
httpPost.setHeader("Authorization", String.format(AUTHORIZATION_FMT, property.getUmsApiKey()));
httpPost.setEntity(EntityBuilder.create().setText(json).setContentType(ContentType.APPLICATION_JSON).build());
if (log.isDebugEnabled()) {
try {
log.debug("Header - {}", httpPost.getHeader("Content-Type"));
log.debug("Header - {}", httpPost.getHeader("Authorization"));
log.debug("Request Body : {}", StreamUtils.copyToString(httpPost.getEntity().getContent(), Charset.defaultCharset()));
} catch (ProtocolException | IOException e) {
throw new RuntimeException(e);
}
}
httpPost.setConfig(requestConfig);
AtomicReference<UmsCallResult> result = new AtomicReference<>();
if (isRealMode) {
try {
httpClient.execute(httpPost, res -> {
String body = EntityUtils.toString(res.getEntity());
result.set(gson.fromJson(body, UmsCallResult.class));
result.get().setUmsMessageId(requestPayload.getMessageIdentityNo());
result.get().setSuccess(true);
return result;
try {
String body = EntityUtils.toString(res.getEntity());
if (log.isDebugEnabled()) {
log.debug("Response - {}", body);
}
result.set(gson.fromJson(body, UmsCallResult.class));
result.get().setUmsMessageId(requestPayload.getMessageIdentityNo());
result.get().setSuccess(true);
return result;
} finally {
log.debug("Response status - {}", res.getCode());
if (res.getCode() != 200) {
Arrays.asList(res.getHeaders()).forEach(o -> {
log.warn("[Header] {}: {}", o.getName(), o.getValue());
});
}
}
});
} catch (IOException e) {
} catch (JsonSyntaxException e) {
log.error("UMS Call error(JSON Syntax)", e);
result.set(
UmsCallResult.builder()
.umsMessageId(requestPayload.getMessageIdentityNo())
.isSuccess(false)
.throwable(e)
.build()
);
} catch (Exception e) {
log.error("UMS Call error", e);
result.set(
UmsCallResult.builder()