멀티쓰레드 환경에서 1번의 초기화만 진행하도록 변경

master
minkyu1128 3 years ago
parent 6dc7187cdf
commit 01a2a82c42

@ -3,6 +3,7 @@ package cokr.xit.ci.api.service;
import cokr.xit.ci.api.code.ErrCd;
import cokr.xit.ci.api.model.ResponseVO;
import cokr.xit.ci.api.service.support.NiceCiGenerator;
import cokr.xit.ci.api.service.support.rest.utils.SymmetricKey;
import cokr.xit.ci.api.service.support.socket.Interop;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -13,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@ -37,6 +39,7 @@ public class NiceCiService {
* @return
*/
public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List<String> jids) {
AtomicInteger i = new AtomicInteger();
return ResponseVO.builder()
.errCode(ErrCd.OK)
.errMsg(ErrCd.OK.getCodeNm())
@ -67,7 +70,10 @@ public class NiceCiService {
======================== */
if("socket".equals(type)) {
responseVO = Interop.getCI(siteCode, sitePw, jid);
}else{
}else if("rest".equals(type)){
if(0 == i.getAndIncrement())
if(!SymmetricKey.isValidStat())
niceCiGenerator.initialKey();
responseVO = niceCiGenerator.getCI(jid, null);
}

@ -45,18 +45,9 @@ public class NiceCiGenerator {
@Value("${contract.nice.ci.rest.api.ci}")
private String API_CI;
public ResponseVO<String> getCI(String jid, String clientIp) {
public ResponseVO initialKey(){
NiceCiApiExecutor executor = NiceCiApiExecutor.builder()
.HOST(this.HOST)
.CLIENT_ID(this.CLIENT_ID)
.CLIENT_SECRET(this.CLIENT_SECRET)
.API_GENERATE_TOKEN(this.API_GENERATE_TOKEN)
.API_REVOKE_TOKEN(this.API_REVOKE_TOKEN)
.API_PUBLICKEY(this.API_PUBLICKEY)
.API_SYMMETRICKEY(this.API_SYMMETRICKEY)
.API_CI(this.API_CI)
.build();
NiceCiApiExecutor executor = buildExecutor();
try {
/* ==========================================================================
@ -80,7 +71,7 @@ public class NiceCiGenerator {
========================================================================== */
// NiceCiRespVO<DataBodySymkeyResp> symkeyResponseVO = executor.symkey();
// if (!NiceCiApiCd.OK.equals(symkeyResponseVO.getErrCode()))
// return ResponseVO.<String>builder().errCode(ErrCd.ERR600).errMsg(symkeyResponseVO.getErrCode().getCode() + " " + symkeyResponseVO.getErrMsg()).build();
// return ResponseVO.<String>errRsltBuilder().errCode(ErrCd.ERR600).errMsg(symkeyResponseVO.getErrCode().getCode() + " " + symkeyResponseVO.getErrMsg()).build();
ObjectMapper mapper = new ObjectMapper();
DataBodySymkeyResp dataBodySymkeyResp = null;
if (SymmetricKey.isValidStat()) {
@ -114,11 +105,23 @@ public class NiceCiGenerator {
}
}
return ResponseVO.<String>builder().errCode(ErrCd.OK).errMsg(ErrCd.OK.getCodeNm()).build();
} catch (Exception e) {
return ResponseVO.<String>builder().errCode(ErrCd.ERR699).errMsg(e.getMessage()).build();
}
}
public ResponseVO<String> getCI(String jid, String clientIp) {
NiceCiApiExecutor executor = this.buildExecutor();
try {
/* ==========================================================================
* 4. CI
========================================================================== */
NiceCiRespVO<DataBodyCiResp> ciResponseVO = executor.ci(jid, clientIp);
if (!NiceCiApiCd.OK.equals(pubkeyResponseVO.getErrCode()))
if (!NiceCiApiCd.OK.equals(ciResponseVO.getErrCode()))
return ResponseVO.<String>builder().errCode(ErrCd.ERR600).errMsg(ciResponseVO.getErrCode().getCode() + " " + ciResponseVO.getErrMsg()).build();
@ -127,4 +130,17 @@ public class NiceCiGenerator {
return ResponseVO.<String>builder().errCode(ErrCd.ERR699).errMsg(e.getMessage()).build();
}
}
private NiceCiApiExecutor buildExecutor(){
return NiceCiApiExecutor.builder()
.HOST(this.HOST)
.CLIENT_ID(this.CLIENT_ID)
.CLIENT_SECRET(this.CLIENT_SECRET)
.API_GENERATE_TOKEN(this.API_GENERATE_TOKEN)
.API_REVOKE_TOKEN(this.API_REVOKE_TOKEN)
.API_PUBLICKEY(this.API_PUBLICKEY)
.API_SYMMETRICKEY(this.API_SYMMETRICKEY)
.API_CI(this.API_CI)
.build();
}
}

Loading…
Cancel
Save