UMS 코드 개선
This commit is contained in:
@@ -15,5 +15,6 @@ eapim-admin 에서 포함하여 테스트 이용시 느린 부팅 속도 떄문
|
|||||||
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa-jenkins' git pull origin jenkins_with_weblogic
|
GIT_SSH_COMMAND='ssh -i ~/.ssh/id_rsa-jenkins' git pull origin jenkins_with_weblogic
|
||||||
|
|
||||||
# test run
|
# test run
|
||||||
|
KJB_EAPIM_TEST_ENABLED=TRUE kjb-gradle.sh :eapim-admin-kjb:test --tests "com.eactive.ext.kjb.ums.test.UmsTest.testSms" -Psafedb
|
||||||
KJB_EAPIM_TEST_ENABLED=TRUE kjb-gradle.sh :eapim-admin-kjb:test --tests "com.eactive.ext.kjb.ums.test.UmsTest.testEmailInServer" -Psafedb
|
KJB_EAPIM_TEST_ENABLED=TRUE kjb-gradle.sh :eapim-admin-kjb:test --tests "com.eactive.ext.kjb.ums.test.UmsTest.testEmailInServer" -Psafedb
|
||||||
```
|
```
|
||||||
@@ -3,6 +3,7 @@ package com.eactive.ext.kjb.ums;
|
|||||||
import com.eactive.apim.portal.template.entity.MessageCode;
|
import com.eactive.apim.portal.template.entity.MessageCode;
|
||||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
import com.eactive.apim.portal.template.entity.MessageRequest;
|
||||||
import com.eactive.ext.kjb.common.KjbProperty;
|
import com.eactive.ext.kjb.common.KjbProperty;
|
||||||
|
import com.eactive.ext.kjb.common.KjbUmsException;
|
||||||
import com.eactive.ext.kjb.ums.gson.IUmsGsonObject;
|
import com.eactive.ext.kjb.ums.gson.IUmsGsonObject;
|
||||||
import com.eactive.ext.kjb.ums.gson.UmsRequestPayload;
|
import com.eactive.ext.kjb.ums.gson.UmsRequestPayload;
|
||||||
import com.eactive.ext.kjb.ums.gson.VerifyPhoneUmsTemplate;
|
import com.eactive.ext.kjb.ums.gson.VerifyPhoneUmsTemplate;
|
||||||
@@ -24,14 +25,11 @@ import org.apache.hc.core5.util.Timeout;
|
|||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class KjbUmsService {
|
public class KjbUmsService {
|
||||||
@@ -82,7 +80,7 @@ public class KjbUmsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean send(MessageRequest messageRequest) {
|
public boolean send(MessageRequest messageRequest) throws KjbUmsException {
|
||||||
if (messageRequest == null) {
|
if (messageRequest == null) {
|
||||||
throw new IllegalArgumentException("messageRequest is null");
|
throw new IllegalArgumentException("messageRequest is null");
|
||||||
}
|
}
|
||||||
@@ -106,7 +104,7 @@ public class KjbUmsService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendKakaoAlimTalk(String guid, UmsBizWorkCode bizWorkCode, String cpno, IUmsGsonObject content) {
|
public String sendKakaoAlimTalk(String guid, UmsBizWorkCode bizWorkCode, String cpno, IUmsGsonObject content) throws KjbUmsException {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
throw new IllegalArgumentException("content is null");
|
throw new IllegalArgumentException("content is null");
|
||||||
}
|
}
|
||||||
@@ -130,102 +128,84 @@ public class KjbUmsService {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return callUms(SEND_URL, payload, (result, ex) -> {
|
UmsCallResult result = call(SEND_URL, payload);
|
||||||
if (ex != null) {
|
if (!result.isSuccess()) {
|
||||||
log.error("UMS 발송 실패", ex);
|
throw new KjbUmsException(result.getThrowable().getMessage());
|
||||||
throw new RuntimeException(ex);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null || !result.isSuccess()) {
|
return result.getUmsMessageId();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<UmsCallResult> callUms(@SuppressWarnings("SameParameterValue") String url, UmsRequestPayload requestPayload,
|
private UmsCallResult call(String url, UmsRequestPayload requestPayload) throws KjbUmsException {
|
||||||
BiConsumer<UmsCallResult, Throwable> callback) {
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
return CompletableFuture
|
Gson gson = new Gson();
|
||||||
.supplyAsync(() -> {
|
String json = gson.toJson(requestPayload);
|
||||||
Gson gson = new Gson();
|
|
||||||
String json = gson.toJson(requestPayload);
|
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost(property.getUmsHostUrl() + url);
|
HttpPost httpPost = new HttpPost(property.getUmsHostUrl() + url);
|
||||||
httpPost.setHeader("Content-Type", CONTENT_TYPE);
|
httpPost.setHeader("Content-Type", CONTENT_TYPE);
|
||||||
httpPost.setHeader("Authorization", String.format(AUTHORIZATION_FMT, property.getUmsApiKey()));
|
httpPost.setHeader("Authorization", String.format(AUTHORIZATION_FMT, property.getUmsApiKey()));
|
||||||
httpPost.setEntity(EntityBuilder.create().setText(json).setContentType(ContentType.APPLICATION_JSON).build());
|
httpPost.setEntity(EntityBuilder.create().setText(json).setContentType(ContentType.APPLICATION_JSON).build());
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
try {
|
try {
|
||||||
log.debug("Header - {}", httpPost.getHeader("Content-Type"));
|
log.debug("Header - {}", httpPost.getHeader("Content-Type"));
|
||||||
log.debug("Header - {}", httpPost.getHeader("Authorization"));
|
log.debug("Header - {}", httpPost.getHeader("Authorization"));
|
||||||
log.debug("Request Body : {}", StreamUtils.copyToString(httpPost.getEntity().getContent(), Charset.defaultCharset()));
|
log.debug("Request Body : {}", StreamUtils.copyToString(httpPost.getEntity().getContent(), Charset.defaultCharset()));
|
||||||
} catch (ProtocolException | IOException e) {
|
} catch (ProtocolException | IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpPost.setConfig(requestConfig);
|
httpPost.setConfig(requestConfig);
|
||||||
|
|
||||||
AtomicReference<UmsCallResult> result = new AtomicReference<>();
|
|
||||||
if (isRealMode) {
|
|
||||||
try {
|
|
||||||
httpClient.execute(httpPost, res -> {
|
|
||||||
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 (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()
|
|
||||||
.umsMessageId(requestPayload.getMessageIdentityNo())
|
|
||||||
.isSuccess(false)
|
|
||||||
.throwable(e)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.warn("UMS URL 미지정으로 실제 호출을 진행하지 않음.");
|
|
||||||
result.set(UmsCallResult.builder().isSuccess(true).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isRealMode) {
|
||||||
|
Future<UmsCallResult> future = executor.submit(() -> {
|
||||||
|
return httpClient.execute(httpPost, res -> {
|
||||||
try {
|
try {
|
||||||
log.debug("UMS Call URI : {}", httpPost.getUri().toASCIIString());
|
UmsCallResult result;
|
||||||
log.debug("UMS Call Request payload : {}", json);
|
String body = EntityUtils.toString(res.getEntity());
|
||||||
} catch (URISyntaxException e) {
|
if (log.isDebugEnabled()) {
|
||||||
throw new RuntimeException(e);
|
log.debug("Response - {}", body);
|
||||||
}
|
}
|
||||||
|
result = gson.fromJson(body, UmsCallResult.class);
|
||||||
|
result.setUmsMessageId(requestPayload.getMessageIdentityNo());
|
||||||
|
result.setSuccess(true);
|
||||||
|
return result;
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
log.error("UMS Call error(JSON Syntax)", e);
|
||||||
|
return UmsCallResult.builder()
|
||||||
|
.umsMessageId(requestPayload.getMessageIdentityNo())
|
||||||
|
.isSuccess(false)
|
||||||
|
.throwable(e)
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("UMS Call error", e);
|
||||||
|
return UmsCallResult.builder()
|
||||||
|
.umsMessageId(requestPayload.getMessageIdentityNo())
|
||||||
|
.isSuccess(false)
|
||||||
|
.throwable(e)
|
||||||
|
.build();
|
||||||
|
} finally {
|
||||||
|
log.debug("Response status - {}", res.getCode());
|
||||||
|
|
||||||
return result.get();
|
if (res.getCode() != 200) {
|
||||||
})
|
Arrays.asList(res.getHeaders()).forEach(o -> {
|
||||||
.whenComplete(callback);
|
log.warn("[Header] {}: {}", o.getName(), o.getValue());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
return future.get(property.getUmsTimeout(), TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||||
|
log.error("EAI Batch call exception", e);
|
||||||
|
throw new KjbUmsException("EAI Ums call failed", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("UMS URL 미지정으로 실제 호출을 진행하지 않음.");
|
||||||
|
return UmsCallResult.builder().isSuccess(true).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import com.eactive.apim.portal.template.entity.MessageCode;
|
|||||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
import com.eactive.apim.portal.template.entity.MessageRequest;
|
||||||
import com.eactive.ext.kjb.common.KjbEaiBatchException;
|
import com.eactive.ext.kjb.common.KjbEaiBatchException;
|
||||||
import com.eactive.ext.kjb.common.KjbProperty;
|
import com.eactive.ext.kjb.common.KjbProperty;
|
||||||
|
import com.eactive.ext.kjb.common.KjbUmsException;
|
||||||
import com.eactive.ext.kjb.ums.KjbEmailSendModule;
|
import com.eactive.ext.kjb.ums.KjbEmailSendModule;
|
||||||
import com.eactive.ext.kjb.ums.KjbUmsService;
|
import com.eactive.ext.kjb.ums.KjbUmsService;
|
||||||
import com.eactive.ext.kjb.utils.OsUtil;
|
import com.eactive.ext.kjb.utils.OsUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -23,16 +25,22 @@ public class UmsTest {
|
|||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() {
|
public static void init() {
|
||||||
prop = new KjbProperty();
|
prop = new KjbProperty();
|
||||||
|
prop.setEaiBatchUrl("http://172.31.32.111:10230/BATAppWeb/EaiBatCall");
|
||||||
prop.setUmsEaiBatchInterfaceId("UAGFF00001UIE");
|
prop.setUmsEaiBatchInterfaceId("UAGFF00001UIE");
|
||||||
|
|
||||||
|
prop.setUmsHostUrl("http://172.31.35.144:9021");
|
||||||
|
prop.setUmsApiKey("7cca6d58-e4f7-474d-9edd-525806bc99ff");
|
||||||
|
|
||||||
if (OsUtil.isWindows()) {
|
if (OsUtil.isWindows()) {
|
||||||
prop.setUmsEaiBatchSendDir("c:\\kjb-logs\\sendmail\\snd");
|
prop.setUmsEaiBatchSendDir("c:\\kjb-logs\\sendmail\\snd");
|
||||||
prop.setUmsEaiBatchBackupDir("c:\\kjb-logs\\sendmail\\bak");
|
prop.setUmsEaiBatchBackupDir("c:\\kjb-logs\\sendmail\\bak");
|
||||||
|
prop.setUmsEaiBatchErrorDir("c:\\kjb-logs\\sendmail\\error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OsUtil.isLinux()) {
|
if (OsUtil.isLinux()) {
|
||||||
prop.setUmsEaiBatchSendDir("/Data/eapim/portal/sendmail/snd");
|
prop.setUmsEaiBatchSendDir("/Data/eapim/portal/sendmail/snd");
|
||||||
prop.setUmsEaiBatchBackupDir("/Data/eapim/portal/sendmail/bak");
|
prop.setUmsEaiBatchBackupDir("/Data/eapim/portal/sendmail/bak");
|
||||||
|
prop.setUmsEaiBatchErrorDir("/Data/eapim/portal/sendmail/error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,9 +50,6 @@ public class UmsTest {
|
|||||||
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
||||||
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
||||||
|
|
||||||
prop.setUmsHostUrl("http://172.31.35.144:9021");
|
|
||||||
prop.setUmsApiKey("7cca6d58-e4f7-474d-9edd-525806bc99ff");
|
|
||||||
|
|
||||||
MessageRequest messageRequest = new MessageRequest();
|
MessageRequest messageRequest = new MessageRequest();
|
||||||
messageRequest.setId(UUID.randomUUID().toString());
|
messageRequest.setId(UUID.randomUUID().toString());
|
||||||
messageRequest.setMessageCode(MessageCode.USER_VERIFICATION_MOBILEPHONE);
|
messageRequest.setMessageCode(MessageCode.USER_VERIFICATION_MOBILEPHONE);
|
||||||
@@ -52,10 +57,17 @@ public class UmsTest {
|
|||||||
messageRequest.setEmail("dearmai@dearmai.net");
|
messageRequest.setEmail("dearmai@dearmai.net");
|
||||||
messageRequest.setUsername("김광은");
|
messageRequest.setUsername("김광은");
|
||||||
messageRequest.setSubject("제목 - test");
|
messageRequest.setSubject("제목 - test");
|
||||||
messageRequest.setMessage("junit test");
|
messageRequest.setMessage("{\"ATHN_NO\"; \"369369\"}");
|
||||||
|
|
||||||
KjbUmsService umsService = new KjbUmsService(prop);
|
KjbUmsService umsService = new KjbUmsService(prop);
|
||||||
umsService.send(messageRequest);
|
try {
|
||||||
|
boolean result = umsService.send(messageRequest);
|
||||||
|
|
||||||
|
} catch (KjbUmsException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
Assertions.fail(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log.info("done");
|
log.info("done");
|
||||||
}
|
}
|
||||||
@@ -66,13 +78,6 @@ public class UmsTest {
|
|||||||
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
||||||
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
||||||
|
|
||||||
prop.setEaiBatchUrl("http://172.31.32.111:10230/BATAppWeb/EaiBatCall");
|
|
||||||
prop.setEaiBatchUrl("");
|
|
||||||
prop.setUmsEaiBatchSendDir("c:\\kjb-logs\\sendmail\\snd");
|
|
||||||
prop.setUmsEaiBatchBackupDir("c:\\kjb-logs\\sendmail\\bak");
|
|
||||||
prop.setUmsEaiBatchErrorDir("c:\\kjb-logs\\sendmail\\error");
|
|
||||||
prop.setUmsEaiBatchInterfaceId("UAGFF00001UIE");
|
|
||||||
|
|
||||||
|
|
||||||
System.getProperties().keySet().forEach(key -> {
|
System.getProperties().keySet().forEach(key -> {
|
||||||
log.info("{}: {}", key, System.getProperty((String) key));
|
log.info("{}: {}", key, System.getProperty((String) key));
|
||||||
@@ -105,13 +110,6 @@ public class UmsTest {
|
|||||||
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
"true".equalsIgnoreCase(System.getenv("KJB_EAPIM_TEST_ENABLED")),
|
||||||
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
"OS 환경변수 내 KJB_EAPIM_TEST_ENABLED=TRUE 설정되어 있어야 동작함");
|
||||||
|
|
||||||
prop.setEaiBatchUrl("http://172.31.32.111:10230/BATAppWeb/EaiBatCall");
|
|
||||||
prop.setUmsEaiBatchSendDir("/Data/eapim/portal/sendmail/snd");
|
|
||||||
prop.setUmsEaiBatchBackupDir("/Data/eapim/portal/sendmail/bak");
|
|
||||||
prop.setUmsEaiBatchErrorDir("/Data/eapim/portal/sendmail/error");
|
|
||||||
prop.setUmsEaiBatchInterfaceId("UAGFF00001UIE");
|
|
||||||
|
|
||||||
|
|
||||||
System.getProperties().keySet().forEach(key -> {
|
System.getProperties().keySet().forEach(key -> {
|
||||||
log.info("{}: {}", key, System.getProperty((String) key));
|
log.info("{}: {}", key, System.getProperty((String) key));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user