fix: nice ci 전문 처리 fix

전송대상 조회시 err_msg 초기화 적용
     NICE CI 설정 fix
dev
Jonguk. Lim 4 weeks ago
parent 1c86c405f7
commit 221c652786

@ -9,6 +9,8 @@ import javax.validation.constraints.*;
import org.apache.commons.lang3.*;
import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.modules.nice.cmm.*;
import io.swagger.v3.oas.annotations.media.*;
import lombok.*;
@ -50,7 +52,7 @@ public class NiceCiApiSendDTO {
*/
private String trnscId = StringUtils.EMPTY;
public void setTrnscId(String trnscId) {
this.trnscId = StringUtils.leftPad(nvl(trnscId), 10, StringUtils.SPACE);
this.trnscId = StringUtils.leftPad(nvl(trnscId), 10, "0");
}
/**
@ -380,10 +382,8 @@ public class NiceCiApiSendDTO {
1, // 연락처조회구분
84, // 공란
};
// FIXME: 인코딩확인후 적용
//String tgtString = NiceCiUtils.covertCharset(tgtStr, "EUC-KR");
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString) >= 2320) {
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString) >= 2310) {
Response response = new Response();
int idx = 0;
response.setTrnscId(StringUtils.left(tgtString, parseLength[idx]));
@ -423,7 +423,7 @@ public class NiceCiApiSendDTO {
}
return response;
}
return null;
throw new EnsException(EnsErrCd.INVALID_RESPONSE, "NICE CI 송신 응답 전문 오류:: length - " + NiceCiUtils.lengthKr(tgtString));
}
}

@ -10,6 +10,8 @@ import javax.validation.constraints.*;
import org.apache.commons.lang3.*;
import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.modules.nice.cmm.*;
import io.swagger.v3.oas.annotations.media.*;
import lombok.*;
@ -53,7 +55,7 @@ public class NiceCiApiStatusDTO {
//@Size(min = 10, max = 10, message = "트랜잭션 코드는 10자리 입니다.")
private String trnscId = StringUtils.EMPTY;
public void setTrnscId(String trnscId) {
this.trnscId = StringUtils.leftPad(nvl(trnscId), 10, StringUtils.SPACE);
this.trnscId = StringUtils.leftPad(nvl(trnscId), 10, "0");
}
/**
@ -345,7 +347,7 @@ public class NiceCiApiStatusDTO {
}
return nr;
}
return null;
throw new EnsException(EnsErrCd.INVALID_RESPONSE, "NICE CI 상태(이력) 조회 응답 전문 오류:: length - " + NiceCiUtils.lengthKr(tgtString));
}
}

@ -1,6 +1,9 @@
package cokr.xit.ens.modules.nice.service;
import java.util.*;
import java.util.stream.*;
import javax.validation.*;
import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.Value;
@ -13,6 +16,7 @@ import cokr.xit.ens.core.aop.*;
import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.core.utils.*;
import cokr.xit.ens.modules.nice.cmm.*;
import cokr.xit.ens.modules.nice.mapper.*;
import cokr.xit.ens.modules.nice.model.*;
import cokr.xit.ens.modules.nice.service.support.*;
@ -41,8 +45,9 @@ public class NiceCiSendBulkService {
private String ORG_ID;
private final NiceCiApiService niceCiApiService;
private final INiceCiMapper niceCiMapper;
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
/**
@ -113,6 +118,9 @@ public class NiceCiSendBulkService {
);
NiceCiApiSendDTO.Request ciRequest = createCiRequest(tmpltMngDTO, data, niceSmsReqId);
String ciTxt = ciRequest.ofString();
ciRequest.setTrnscId(String.valueOf(NiceCiUtils.lengthKr(ciTxt)));
validate(ciRequest);
niceCiMapper.insertNiceSmsSndngRequest(ciRequest);
//----------------------------------------------------------
// API Call 전처리 END - request 저장
@ -122,7 +130,7 @@ public class NiceCiSendBulkService {
// Status API call & Get Result START
//----------------------------------------------------------
// FIXME : 연계 이후 확인 필요
EnsResponseVO<?> responseVO = niceCiApiService.requestSendBulk(ciRequest);
EnsResponseVO<?> responseVO = niceCiApiService.requestSendBulk(ciRequest.getTrnscId(), ciTxt);
if (!EnsErrCd.OK.equals(responseVO.getErrCode()))
throw new EnsException(responseVO.getErrCode(), responseVO.getErrMsg());
NiceCiApiSendDTO.Response resDTO = (NiceCiApiSendDTO.Response)responseVO.getResultInfo();
@ -294,4 +302,19 @@ public class NiceCiSendBulkService {
xit.setPrcsCd(IupPrcsCd.FAIL.getCode());
niceCiMapper.updatePrcsCdAndErrorOfInputXit(xit);
}
private void validate(final NiceCiApiSendDTO.Request ciRequest) {
List<String> errors = new ArrayList<>();
final Set<ConstraintViolation<NiceCiApiSendDTO.Request>> list = validator.validate(ciRequest);
if (!list.isEmpty()) {
errors.addAll(list.stream()
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
.collect(Collectors.toList())
);
}
if(!errors.isEmpty()){
throw new EnsException(EnsErrCd.INVALID_DATA, errors.toString());
}
}
}

@ -1,6 +1,9 @@
package cokr.xit.ens.modules.nice.service;
import java.util.*;
import java.util.stream.*;
import javax.validation.*;
import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.Value;
@ -11,6 +14,7 @@ import cokr.xit.ens.core.aop.*;
import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.core.utils.*;
import cokr.xit.ens.modules.nice.cmm.*;
import cokr.xit.ens.modules.nice.mapper.*;
import cokr.xit.ens.modules.nice.model.*;
import cokr.xit.ens.modules.nice.service.support.*;
@ -40,9 +44,11 @@ public class NiceCiStatBulkService {
private final NiceCiApiService niceCiApiService;
private final NiceCiNewTransactionService niceCiNewTransactionService;
private final INiceCiMapper niceCiMapper;
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
/**
* <pre>
* -- 1.
@ -210,6 +216,9 @@ public class NiceCiStatBulkService {
// API Call 전처리 START - request
//----------------------------------------------------------
ciRequest.setNiceSmsSndngInqireId(niceSmsInqId);
String ciTxt = ciRequest.ofString();
ciRequest.setTrnscId(String.valueOf(NiceCiUtils.lengthKr(ciTxt)));
validate(ciRequest);
niceCiMapper.insertNiceSmsSndngInquireRequest(ciRequest);
//----------------------------------------------------------
// API Call 전처리 END - request
@ -218,7 +227,7 @@ public class NiceCiStatBulkService {
//----------------------------------------------------------
// Status API call & Get Result START
//----------------------------------------------------------
EnsResponseVO<?> responseVO = niceCiApiService.findBulkStatus(ciRequest);
EnsResponseVO<?> responseVO = niceCiApiService.findBulkStatus(ciRequest.getTrnscId(), ciTxt);
if (!EnsErrCd.OK.equals(responseVO.getErrCode()))
throw new EnsException(responseVO.getErrCode(), responseVO.getErrMsg());
@ -268,4 +277,19 @@ public class NiceCiStatBulkService {
return resDTO;
}
private void validate(final NiceCiApiStatusDTO.Request ciRequest) {
List<String> errors = new ArrayList<>();
final Set<ConstraintViolation<NiceCiApiStatusDTO.Request>> list = validator.validate(ciRequest);
if (!list.isEmpty()) {
errors.addAll(list.stream()
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
.collect(Collectors.toList())
);
}
if(!errors.isEmpty()){
throw new EnsException(EnsErrCd.INVALID_DATA, errors.toString());
}
}
}

@ -3,8 +3,6 @@ package cokr.xit.ens.modules.nice.service.support;
import java.io.*;
import java.net.*;
import java.nio.charset.*;
import java.util.*;
import java.util.stream.*;
import javax.validation.*;
@ -55,28 +53,10 @@ public class NiceCiApiService {
* @param reqDTO NiceCiApiSendDTO.Request
* @return EnsResponseVO
*/
public EnsResponseVO<?> requestSendBulk(final NiceCiApiSendDTO.Request reqDTO) {
List<String> errors = new ArrayList<>();
final Set<ConstraintViolation<NiceCiApiSendDTO.Request>> list = validator.validate(reqDTO);
if (!list.isEmpty()) {
errors.addAll(list.stream()
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
.collect(Collectors.toList())
);
}
if(!errors.isEmpty()){
return EnsResponseVO.errBuilder()
.errCode(EnsErrCd.INVALID_DATA)
.errMsg(errors.toString())
.build();
}
log.info("API call parameter :: {}", reqDTO);
String ciTxt = reqDTO.ofString();
String ft = String.format("%s%s", StringUtils.leftPad(String.valueOf(NiceCiUtils.lengthKr(ciTxt)), 10, "0"),
ciTxt);
public EnsResponseVO<?> requestSendBulk(final String trscId, final String ciText) {
String ft = String.format("%s%s", trscId, ciText);
log.info("kr length - {}, utf-8 length - {}", NiceCiUtils.lengthKr(ft), ft.length());
log.debug("송신 요청 전문\n[{}]", ft);
final String rtnMsg;
try {
@ -97,32 +77,12 @@ public class NiceCiApiService {
/**
* NICE CI SMS API
* @param reqDTO NiceCiApiStatusDTO.Request
* @return EnsResponseVO
*/
public EnsResponseVO<?> findBulkStatus(final NiceCiApiStatusDTO.Request reqDTO) {
List<String> errors = new ArrayList<>();
final Set<ConstraintViolation<NiceCiApiStatusDTO.Request>> list = validator.validate(reqDTO);
if (!list.isEmpty()) {
errors.addAll(list.stream()
.map(row -> String.format("%s=%s", row.getPropertyPath(), row.getMessageTemplate()))
.collect(Collectors.toList())
);
}
if(!errors.isEmpty()){
return EnsResponseVO.errBuilder()
.errCode(EnsErrCd.INVALID_DATA)
.errMsg(errors.toString())
.build();
}
log.info("API call parameter :: {}", reqDTO);
String ciTxt = reqDTO.ofString();
String ft = String.format("%s%s", StringUtils.leftPad(String.valueOf(NiceCiUtils.lengthKr(ciTxt)), 10, "0"),
ciTxt);
public EnsResponseVO<?> findBulkStatus(final String trscId, final String ciText) {
String ft = String.format("%s%s", trscId, ciText);
log.info("kr length - {}, utf-8 length - {}", NiceCiUtils.lengthKr(ft), ft.length());
log.debug("상태 조회 요청 전문\n[{}]", ft);
final String rtnMsg;
try {
rtnMsg = sendNiceCiSocket(ft);
@ -146,31 +106,33 @@ public class NiceCiApiService {
try (Socket socket = new Socket(HOST, PORT); // 서버에 연결
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream(), Charset.forName("EUC-KR")));
//new OutputStreamWriter(socket.getOutputStream()));
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream(), Charset.forName("EUC-KR")))) {
socket.setSoTimeout(TIMEOUT); // 읽기 타임아웃 설정
out.write(binTxt);
// FIXME: 테스트 소켓서버 통신을 위해 임시로 추가 : 테스트 완료후 제거
// out.write("\nEXIT");
// out.newLine();
// FIXME: 테스트 소켓서버 통신을 위해 임시로 추가 : 테스트 완료후 제거
out.flush();
rtnMsg = in.readLine();
System.out.println("=============>>>서버 응답(EUC-KR로 읽어온 값)<<<====================================");
System.out.println(rtnMsg);
System.out.println("=============>>>서버 응답(EUC-KR로 읽어온 값)<<<====================================");
StringBuffer sb = new StringBuffer();
int ch;
while ((ch = in.read()) != -1) {
sb.append((char) ch);
}
rtnMsg = sb.toString();
log.info("=============>>>서버 응답(EUC-KR로 읽어온 값)<<<====================================");
log.info("[{}]", rtnMsg);
log.info("=============>>>서버 응답(EUC-KR로 읽어온 값)<<<====================================");
} catch (SocketTimeoutException e) {
// 타임아웃 발생 시 처리
log.error("NICE CI Socket 서버 응답 시간 초과: " + e.getMessage());
throw new EnsException(EnsErrCd.API_COMM_ERROR, "NICE CI Socket 서버 응답 시간 초과");
} catch (ConnectException e) {
log.error("NICE CI Socket 서버 ConnectException ERROR :: {}", ObjectUtils.isNotEmpty(e.getCause())? e.getCause().getMessage() : e.getMessage());
throw new EnsException(EnsErrCd.API_COMM_ERROR, ObjectUtils.isNotEmpty(e.getCause())? e.getCause().getMessage() : e.getMessage());
} catch (IOException e) {
log.error("NICE CI Socket 서버 ERROR :: {}", ObjectUtils.isNotEmpty(e.getCause())? e.getCause().getMessage() : e.getMessage());
throw new EnsException(EnsErrCd.API_COMM_ERROR, ObjectUtils.isNotEmpty(e.getCause())? e.getCause().getMessage() : e.getMessage());

@ -68,8 +68,8 @@ contract:
send: /v1/envelopes/{PRODUCT_CODE};POST
bulksend: /v1/bulk/envelopes/{PRODUCT_CODE};POST
niceCi:
host: 121.162.154.130
port: 51253 #10001
host: 127.0.0.1
port: 10001 #51253 10001
# //FIXME: NICE CI Socket 통신 timeout 시간 설정 - 단위 ms
# Nice secureconnetor system.prop의 전문호출후 대기시간 + 1초로 설정
timeout: 16000

@ -9,7 +9,7 @@
<select id="selectInputXits" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$NiceCiParam" resultType="cokr.xit.ens.modules.nice.model.NiceCiDTO$InputXit">
/** iup-niceci-mapper|selectInputXits-NICE CI 대상 조회|julim */
SELECT lnk_input_id /* 연계 ID */
, err_msg /* 오류 메시지 */
, '' AS err_msg /* 오류 메시지 */
, expires_dt /* 마감 일시 */
, org_cd /* 기관 코드 */
, pay_expires_dt /* 결제 만료 일시 */

Loading…
Cancel
Save