feat: cache(CaffeineCache) API 적용

dev
gitea-관리자 1 year ago
parent 32beb10a24
commit 65de16171f

@ -1,7 +1,6 @@
package kr.xit.ens.support.cmm.service;
import kr.xit.biz.ens.model.nice.NiceCiDTO.CrtfInfo;
import org.springframework.cache.annotation.CacheEvict;
/**
* <pre>

@ -27,6 +27,7 @@ import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyRequest;
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyResDataBody;
import kr.xit.biz.ens.model.nice.NiceCiDTO.PublickeyResponse;
import kr.xit.biz.ens.model.nice.NiceCiDTO.RequestDataHeader;
import kr.xit.biz.ens.model.nice.NiceCiDTO.ResponseDataHeader;
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymmetrickeyRegRequest;
import kr.xit.biz.ens.model.nice.NiceCiDTO.SymmetrickeyRegResponse;
import kr.xit.biz.ens.model.nice.NiceCiDTO.TokenRequest;
@ -40,7 +41,7 @@ import kr.xit.ens.support.cmm.mapper.ICmmEnsMapper;
import kr.xit.ens.support.cmm.service.CmmEnsCacheService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.apache.commons.lang3.ObjectUtils;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
@ -90,6 +91,9 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
@Value("${contract.nice.api.ci}")
private String API_CI;
//FIXME::업무처리 최대 주기
private final int EXPIRED_CHECK_DAYS = 1;
private static final String AUTH_TYPE_BASIC = "Basic";
private static final String AUTH_TYPE_BEARER = "bearer";
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
@ -214,7 +218,7 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
CrtfInfo crtfInfo = cacheService.getNiceCrtfInfoCache(SIGNGU_CODE, FFNLG_CODE, CLIENT_ID);
cacheService.logCache();
if(crtfInfo.getRemainingDays() > 5) return crtfInfo;
if(crtfInfo.getRemainingDays() > EXPIRED_CHECK_DAYS) return crtfInfo;
//FIXME::공개키 발급요청 call
PublickeyRequest pubReqDTO = PublickeyRequest.builder()
@ -225,10 +229,12 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
.build();
PublickeyResponse pubResDTO = requestPublickey(pubReqDTO);
//PublickeyResponse pubResDTO = JsonUtils.toObject(pubResJson, PublickeyResponse.class);
//FIXME::공개키 정보 갱신
ResponseDataHeader dataHeader = pubResDTO.getDataHeader();
PublickeyResDataBody dataBody = pubResDTO.getDataBody();
if(pubResDTO.getDataHeader().getGwRsltCd().equals("1200")
if(dataHeader.getGwRsltCd().equals("1200")
&& dataBody.getRspCd().equals("P000")
&& dataBody.getResultCd().equals("0000")){
crtfInfo.setSiteCode(dataBody.getSiteCode());
@ -237,7 +243,8 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
crtfInfo.setValidDtim(dataBody.getValidDtim());
cmmEnsMapper.updateNiceCrtfPublickey(crtfInfo);
}else{
//FIXME::예외처리
//FIXME::에러처리 방안 설정후 적용 할 것
throw BizRuntimeException.create(JsonUtils.toJson(dataHeader));
}
cacheService.removeNiceCrtfInfoCache(SIGNGU_CODE, FFNLG_CODE, CLIENT_ID);
@ -251,7 +258,7 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
//-------------------------------------------------------------------------------
private Map<String,String> getHeaderMap(final String contentType, final String type){
Map<String,String> map = new HashMap<>();
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
if(ObjectUtils.isNotEmpty(contentType)) map.put(HttpHeaders.CONTENT_TYPE, contentType);
map.put(
HttpHeaders.AUTHORIZATION,
String.format("%s %s",

@ -18,7 +18,7 @@
key_version,
public_key,
valid_dtim,
timestampdiff(DAY, '20230911235959', now()) AS remainingDays /* 잔여일수-공용키 */
timestampdiff(DAY, now(), '20230911235959') AS remainingDays /* 잔여일수-공용키 */
FROM tb_cmm_nice_instn_crtf_info
WHERE signgu_code = #{signguCode}
AND ffnlg_code = #{ffnlgCode}

@ -72,7 +72,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status,
WebRequest request) {
log.error("==== MethodArgumentNotValidException override ====");
log.error("==== MethodArgumentNotValidException override ====\n{}", ex.getMessage());
Map<String, String> validErrorMap = new HashMap<>();
ex.getBindingResult().getFieldErrors()
.forEach(e -> validErrorMap.put(e.getField(), e.getDefaultMessage()));
@ -96,7 +96,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
protected ResponseEntity<Object> handleHttpMessageNotReadable(
HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status,
WebRequest request) {
log.error("==== HttpMessageNotReadableException override ====");
log.error("==== HttpMessageNotReadableException override ====\n{}", ex.getMessage());
return ResponseEntity
.ok()
@ -112,7 +112,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
*/
@ExceptionHandler(value = {BizRuntimeException.class})
protected ApiResponseDTO handleBizRutimeException(BizRuntimeException e) {
log.error("==== throw BizRutimeException====");
log.error("==== throw BizRutimeException====\n{}", e.getMessage());
return sendError(e);
}
@ -125,7 +125,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {EgovBizException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ApiResponseDTO handleEgovBizException(EgovBizException e) {
log.error("==== throw EgovBizException ====================");
log.error("==== throw EgovBizException ====================\n{}", e.getMessage());
return sendError(e);
}
@ -137,7 +137,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {NoSuchElementException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ApiResponseDTO handleNoSuchElementException(NoSuchElementException e) {
log.error("==== throw NoSuchElementException ====================");
log.error("==== throw NoSuchElementException ====================\n{}", e.getMessage());
return sendError(e);
}
@ -149,7 +149,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {IllegalArgumentException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ApiResponseDTO handleIllegalArgumentException(IllegalArgumentException e) {
log.error("==== throw IllegalArgumentException ====================");
log.error("==== throw IllegalArgumentException ====================\n{}", e.getMessage());
return sendError(e);
}
@ -172,7 +172,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {CompletionException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected ApiResponseDTO handleCompletionException(CompletionException e) {
log.error("==== throw CompletionException ====================");
log.error("==== throw CompletionException ====================\n{}", e.getMessage());
return sendError(e);
}
@ -185,7 +185,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {RuntimeException.class})
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
protected ApiResponseDTO handleRuntimeException(RuntimeException e) {
log.error("==== throw RuntimeException ====================");
log.error("==== throw RuntimeException ====================", e.getMessage());
return sendError(e);
}
@ -198,7 +198,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(value = {Exception.class})
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
protected ApiResponseDTO handleException(Exception e) {
log.error("==== throw Exception ====================");
log.error("==== throw Exception ====================\n{}", e.getMessage());
return sendError(e);
}

Loading…
Cancel
Save