fix: KT 토큰정보 오류시 발생하는 에러 fix

API 로깅 fix
dev
gitea-관리자 1 year ago
parent 5ee5c5eec3
commit 78fe7c5172

@ -71,7 +71,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
* @return CmmEnsRlaybsnmDTO
*/
@Transactional(readOnly = true)
//@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
@Cacheable(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public CmmEnsRlaybsnmDTO getRlaybsnmInfoCache(final CmmEnsRequestDTO dto) {
return cmmEnsMapper.selectEnsRlaybsnmInfo(dto);
}
@ -83,7 +83,7 @@ public class CmmEnsCacheService implements ICmmEnsCacheService {
@Transactional(readOnly = true)
@CacheEvict(cacheNames = "rlaybsnmInfo", keyGenerator = "simpleKeyGenerator")
public void removeRlaybsnmInfoCache(final CmmEnsRequestDTO dto) {
log.info("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&{} cache remove&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&", dto);
log.info("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&{} cache remove &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&", dto);
}
/**

@ -66,7 +66,7 @@ public class BizKtMmsController {
value = PARAM2)
})
})
@Operation(summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청")
@Operation(deprecated = true, summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청")
@PostMapping(value = "/requestToken", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse requestToken(@RequestBody final KtMnsRequest paramDTO) {
return ApiResponseDTO.success(service.requestToken(paramDTO));

@ -10,7 +10,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.servlet.http.HttpServletRequest;
import kr.xit.core.biz.model.LoggingDTO;
import kr.xit.core.biz.service.ILoggingService;
import kr.xit.core.biz.service.IApiLoggingService;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.spring.util.error.ErrorParse;
@ -85,12 +85,12 @@ public class TraceLoggerAspect {
@Value("#{'${app.log.mdc.exclude-patterns}'.split(',')}")
private String[] excludes;
private final ILoggingService loggingService;
private final IApiLoggingService apiLoggingService;
private final SlackWebhookPush slackWebhookPush;
private static final String REQUEST_TRACE_ID = "request_trace_id";
public TraceLoggerAspect(@Lazy ILoggingService loggingService, SlackWebhookPush slackWebhookPush) {
this.loggingService = loggingService;
public TraceLoggerAspect(@Lazy IApiLoggingService apiLoggingService, SlackWebhookPush slackWebhookPush) {
this.apiLoggingService = apiLoggingService;
this.slackWebhookPush = slackWebhookPush;
}
@ -122,7 +122,7 @@ public class TraceLoggerAspect {
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes != null? attributes.getRequest(): null;
traceLogging(JsonUtils.toObjByObj(pjp.getArgs()[0], JSONObject.class), request);
traceApiLogging(JsonUtils.toObjByObj(pjp.getArgs()[0], JSONObject.class), request);
Object result = pjp.proceed();
//noinspection rawtypes
@ -131,9 +131,9 @@ public class TraceLoggerAspect {
while(true) {
if (future.isDone()) break;
}
traceLoggingResult(future.get());
traceApiLoggingResult(future.get());
}else{
traceLoggingResult(result);
traceApiLoggingResult(result);
}
return result;
}
@ -151,7 +151,7 @@ public class TraceLoggerAspect {
@AfterThrowing(value = "errorPointCut()", throwing="error")
public void afterThrowingProceed(final JoinPoint jp, final Throwable error) {
traceLoggingError(jp, error);
traceApiLoggingError(jp, error);
}
/**
@ -159,7 +159,7 @@ public class TraceLoggerAspect {
* @param json JSONObject
* @param request HttpServletRequest
*/
protected void traceLogging(final JSONObject json, final HttpServletRequest request) {
protected void traceApiLogging(final JSONObject json, final HttpServletRequest request) {
String uri = "";
if(request != null) {
uri = request.getRequestURI();
@ -197,11 +197,11 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
.accessToken("")
.sessionId(MDC.getCopyOfContextMap().get("sessionId"))
.build();
loggingService.saveLogging(loggingDTO);
apiLoggingService.saveApiLogging(loggingDTO);
}
protected void traceLoggingResult(final Object result) {
protected void traceApiLoggingResult(final Object result) {
String success = "true";
//FIXME: slack webhook log push
if(result instanceof ApiResponseDTO<?> apiResponseDTO){
@ -237,7 +237,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
.message(HttpStatus.OK.name())
.build();
//}
loggingService.modifyLogging(reqDTO);
apiLoggingService.modifyApiLogging(reqDTO);
//loggingService.saveLogging(reqDTO);
log.info("@@@@@@@@@@@@@@로깅 end[\n{}\n]", MDC.getCopyOfContextMap());
@ -265,13 +265,14 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
}
}
protected void traceLoggingError(final JoinPoint jp, final Throwable e) {
protected void traceApiLoggingError(final JoinPoint jp, final Throwable e) {
log.info("MDC request_trace_id :: {}", MDC.get(REQUEST_TRACE_ID));
if(Checks.isEmpty(MDC.get(REQUEST_TRACE_ID))) return;
@SuppressWarnings("rawtypes")
ApiResponseDTO dto = ErrorParse.extractError(e);
loggingService.modifyLogging(
apiLoggingService.modifyApiLogging(
LoggingDTO
.builder()
.requestId(MDC.get(REQUEST_TRACE_ID))
@ -378,6 +379,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
PPLUS("POST-PLUS", "Post Plus", "/pplus/"),
NICE("NICE", "NICE CI", "/nice/"),
EPOST("EPOST", "E-POST", "/ag/"),
SISUL("SISUL", "시설공단", "/sisul/"),
BATCH("BATCH", "미정의", "/미정의/"),
;

@ -11,7 +11,7 @@ import kr.xit.core.biz.model.LoggingDTO;
* description : API db logging
*
* packageName : kr.xit.core.biz.mapper
* fileName : ILoggingMapper
* fileName : IApiLoggingMapper
* author : limju
* date : 2023-05-11
* ======================================================================
@ -22,11 +22,11 @@ import kr.xit.core.biz.model.LoggingDTO;
* </pre>
*/
@Mapper
public interface ILoggingMapper {
public interface IApiLoggingMapper {
List<LoggingDTO> selectLogging(final LoggingDTO reqDTO);
LoggingDTO selectLogging();
List<LoggingDTO> selectApiLogging(final LoggingDTO reqDTO);
LoggingDTO selectApiLogging();
void saveLogging(final LoggingDTO reqDTO);
void updateLogging(final LoggingDTO reqDTO);
void saveApiLogging(final LoggingDTO reqDTO);
void updateApiLogging(final LoggingDTO reqDTO);
}

@ -1,8 +1,9 @@
package kr.xit.core.biz.service;
import java.util.List;
import kr.xit.core.biz.mapper.ILoggingMapper;
import kr.xit.core.biz.mapper.IApiLoggingMapper;
import kr.xit.core.biz.model.LoggingDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.springframework.stereotype.Service;
@ -26,33 +27,30 @@ import org.springframework.transaction.annotation.Transactional;
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class LoggingService extends EgovAbstractServiceImpl implements ILoggingService{
private final ILoggingMapper mapper;
public LoggingService(ILoggingMapper mapper) {
this.mapper = mapper;
}
public class ApiLoggingService extends EgovAbstractServiceImpl implements IApiLoggingService {
private final IApiLoggingMapper mapper;
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public void saveLogging(final LoggingDTO reqDTO){
mapper.saveLogging(reqDTO);
public void saveApiLogging(final LoggingDTO reqDTO){
mapper.saveApiLogging(reqDTO);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public void modifyLogging(final LoggingDTO reqDTO){
mapper.updateLogging(reqDTO);
public void modifyApiLogging(final LoggingDTO reqDTO){
mapper.updateApiLogging(reqDTO);
}
@Override
public List<LoggingDTO> findLogging(final LoggingDTO reqDTO) {
return mapper.selectLogging(reqDTO);
public List<LoggingDTO> findApiLogging(final LoggingDTO reqDTO) {
return mapper.selectApiLogging(reqDTO);
}
@Override
public LoggingDTO findLogging() {
return mapper.selectLogging();
public LoggingDTO findApiLogging() {
return mapper.selectApiLogging();
}
}

@ -19,9 +19,9 @@ import kr.xit.core.biz.model.LoggingDTO;
*
* </pre>
*/
public interface ILoggingService {
List<LoggingDTO> findLogging(LoggingDTO reqDTO);
LoggingDTO findLogging();
void saveLogging(LoggingDTO reqDTO);
void modifyLogging(LoggingDTO reqDTO);
public interface IApiLoggingService {
List<LoggingDTO> findApiLogging(LoggingDTO reqDTO);
LoggingDTO findApiLogging();
void saveApiLogging(LoggingDTO reqDTO);
void modifyApiLogging(LoggingDTO reqDTO);
}

@ -2,9 +2,9 @@ package kr.xit.core.spring.util;
import kr.xit.biz.cmm.service.CmmEnsCacheService;
import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.kt.service.IBizKtMmsService;
import kr.xit.biz.nice.service.IBizNiceCiService;
import kr.xit.core.spring.config.support.ApplicationContextProvider;
import kr.xit.ens.kt.service.IKtMmsService;
import kr.xit.ens.nice.service.INiceCiService;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@ -58,7 +58,7 @@ public class ApiSpringUtils {
return (IBizNiceCiService)getBean(IBizNiceCiService.class);
}
public static IKtMmsService getKtMmsService(){
return (IKtMmsService)getBean(IKtMmsService.class);
public static IBizKtMmsService getBizKtMmsService(){
return (IBizKtMmsService)getBean(IBizKtMmsService.class);
}
}

@ -34,11 +34,11 @@ import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.kt.KtCommonDTO.ErrorMsg;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.kt.service.IBizKtMmsService;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.spring.util.ApiSpringUtils;
import kr.xit.core.spring.util.CoreSpringUtils;
import kr.xit.core.support.utils.DateUtils;
import kr.xit.ens.kt.service.IKtMmsService;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
@ -65,7 +65,7 @@ import org.springframework.util.Base64Utils;
public class CmmEnsUtils {
private static final EgovMessageSource messageSource = CoreSpringUtils.getMessageSource();
private static final ICmmEnsCacheService cacheService = ApiSpringUtils.getCmmEnsCacheService();
private static final IKtMmsService ktMmsService = ApiSpringUtils.getKtMmsService();
private static final IBizKtMmsService bizKtService = ApiSpringUtils.getBizKtMmsService();
/**
*
@ -83,17 +83,18 @@ public class CmmEnsUtils {
.build();
final CmmEnsRlaybsnmDTO dto = cacheService.getRlaybsnmInfoCache(ensDTO);
cacheService.logCache();
if(ObjectUtils.isEmpty(dto)) throw BizRuntimeException.create(messageSource.getMessage("fail.api.rlaybsnm.info"));
// KT인 경우 토큰유효기간 check
if(SndngSeCode.KT_BC.equals(seCode)){
if(StringUtils.isNotEmpty(dto.getKtTokenExpiresIn())
&& DateUtils.getTodayAndNowTime(ApiConstants.FMT_DT_STD).compareTo(dto.getKtTokenExpiresIn()) < 0) return dto;
&& DateUtils.getTodayAndNowTime(ApiConstants.FMT_DT_STD).compareTo(dto.getKtTokenExpiresIn()) < 0
&& ObjectUtils.isNotEmpty(dto.getKtAccessToken())
) return dto;
// 유효기간이 경과된 경우 재발급
ktMmsService.requestToken(
bizKtService.requestToken(
KtMnsRequest.builder()
.signguCode(signguCode)
.ffnlgCode(ffnlgCode)

@ -1,8 +1,12 @@
package kr.xit.ens.kt.service;
import egovframework.com.cmm.EgovMessageSource;
import java.util.HashMap;
import java.util.Map;
import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.common.ApiConstants;
import kr.xit.biz.common.ApiConstants.SndngSeCode;
import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfRequest;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfResponse;
@ -156,6 +160,8 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
private String API_APPROVE_RCV;
private final ApiWebClientUtil webClient;
private final ICmmEnsCacheService cacheService;
private final EgovMessageSource messageSource;
//-----------------------------------------------------------
@ -165,7 +171,12 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
@Override
@TraceLogging
public KtTokenResponse requestToken(final KtMnsRequest paramDTO) {
final CmmEnsRlaybsnmDTO ktMnsInfo = getRlaybsnmInfo(paramDTO);
final CmmEnsRlaybsnmDTO ktMnsInfo = cacheService.getRlaybsnmInfoCache(CmmEnsRequestDTO.builder()
.signguCode(paramDTO.getSignguCode())
.ffnlgCode(paramDTO.getFfnlgCode())
.profile(ApiConstants.PROFILE)
.build());
final KtTokenRequest reqDTO = KtTokenRequest.builder()
.clientId(ktMnsInfo.getKtSvcClientId())
.clientSecret(ktMnsInfo.getKtSvcClientSecret())

@ -25,7 +25,6 @@ import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenConfirmRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenConfirmResponse;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenExcaRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenReadRequest;
import kr.xit.biz.kt.service.IBizKtMmsService;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.model.IApiResponse;
import kr.xit.ens.kt.service.IKtMmsService;
@ -58,7 +57,6 @@ import org.springframework.web.bind.annotation.RestController;
public class KtMmsController {
private final IKtMmsService service;
private final IBizKtMmsService bizService;
//------------------------------------------------------------------------------
// mens 사용 API
@ -69,7 +67,7 @@ public class KtMmsController {
return ApiResponseDTO.success(service.requestToken(paramDTO));
}
@Operation(summary = "본문자 수신 등록 요청(BC-AG-SN-002) -> 업무(Biz)단 API 사용", description = "본문자 수신 등록 요청(BC-AG-SN-002) -> bulk처리를 위해 업무단의 API를 사용하여야 함")
@Operation(summary = "본문자 수신 등록 요청(BC-AG-SN-002)", description = "본문자 수신 등록 요청(BC-AG-SN-002)")
@PostMapping(value = "/mainSend", produces = MediaType.APPLICATION_JSON_VALUE)
public IApiResponse mainSend(@RequestBody final KtMainSendRequest reqDTO) {
KtCommonResponse dto = service.mainSend(reqDTO);

@ -51,8 +51,11 @@
IF(#{profile} = 'prod', kt_prod_client_secret, kt_dev_client_secret) AS ktSvcClientSecret, /* KT client service secret */
IF(#{profile} = 'prod', kt_prod_service_cerf_key, kt_dev_service_cerf_key) AS ktSvcCerfKey, /* KT client service cerf key */
IF(#{profile} = 'prod', kt_prod_access_token, kt_dev_access_token) AS ktAccessToken, /* KT access token */
DATE_ADD(NOW(), INTERVAL IF(#{profile} = 'prod', kt_prod_token_expires_in, kt_dev_token_expires_in) - 86400 SECOND) AS ktTokenExpiresIn, /* KT 토큰 유효기간 : (7775999)(90일) */
IF(#{profile} = 'prod', kt_prod_token_jti, kt_dev_token_jti) AS ktTokenJti, /* KT 토큰 식별자 */
CASE WHEN IFNULL(IF(#{profile} = 'prod', kt_prod_token_expires_in, kt_dev_token_expires_in), '') = ''
THEN NULL
ELSE DATE_ADD(NOW(), INTERVAL IF(#{profile} = 'prod', kt_prod_token_expires_in, kt_dev_token_expires_in) - 86400 SECOND)
END AS ktTokenExpiresIn, /* KT 토큰 유효기간 : (7775999)(90일) */
epost_service_key, /* epost service key */
pplus_api_key, /* postplus api key */
sender_nm, /* 발송인 명 */

@ -2,10 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.core.biz.mapper.ILoggingMapper">
<mapper namespace="kr.xit.core.biz.mapper.IApiLoggingMapper">
<insert id="saveLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|saveLogging|julim */
<insert id="saveApiLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|saveApiLogging|julim */
INSERT INTO tb_cmm_api_log (
request_id
, system_id
@ -39,7 +39,7 @@
)
</insert>
<update id="updateLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
<update id="updateApiLogging" parameterType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|updateLogging|julim */
UPDATE tb_cmm_api_log
SET success = #{success}
@ -50,8 +50,8 @@
WHERE request_id = #{requestId}
</update>
<select id="selectLogging" resultType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|selectLogging|julim */
<select id="selectApiLogging" resultType="kr.xit.core.biz.model.LoggingDTO">
/** logging-mysql-mapper|selectApiLogging|julim */
SELECT request_id
, system_id
, req_system_id

@ -355,10 +355,8 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
throw e;
}
// mobile page create
sendReqs.forEach(d -> mapper.insertKtMobilePageManage(d.getSrcKey()));
final List<List<KtMainSendReqData>> partitions = ListUtils.partition(sendReqs, bulkKtMaxCnt);
@SuppressWarnings("rawtypes")
List<ApiResponseDTO> apiResults = partitions.stream()
.map(bulkSendList -> {
mstDTO.setReqs(bulkSendList);
@ -374,6 +372,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
boolean isSuccess = false;
List<ErrorMsg> errList = new ArrayList<>();
//noinspection rawtypes
for(ApiResponseDTO apiResult : apiResults) {
// KT-BC API 정상 호출
if(ObjectUtils.isNotEmpty(apiResult.getData())) {
@ -411,6 +410,8 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
extractService.updateSndngMstFailStatus(mstId, SndngSeCode.KT_BC, dto.getErrorCode(), dto.getErrorMssage(), "[send] KT-BC 발송(bulks)요청 실패");
return;
}
// mobile page create
sendReqs.forEach(d -> mapper.insertKtMobilePageManage(d.getSrcKey()));
// 성공 건수 존재시 성공 처리
dto.setResultCd("00");
@ -452,6 +453,7 @@ public class EnsBatchSendService extends EgovAbstractServiceImpl implements IEns
private void sendBulkPplus(final SndngMssageParam dto) {
final String url = apiHost + apiPplusBulkSend;
//noinspection rawtypes
ApiResponseDTO apiResult = apiWebClient.exchange(
url,
HttpMethod.POST,

@ -29,7 +29,7 @@
/** batch-cmm-mysql-mapper|updateBatchLock-배치 실행 상태 및 결과 반영|julim */
UPDATE tb_cmm_batch_lock
SET result = #{result}
, message = IFNULL(SUBSTRING(#{message}, 1, 200), message)
, message = SUBSTRING(#{message}, 1, 200)
, use_yn = #{useYn}
, updt_dt = NOW(3)
WHERE instance_id = #{instanceId}

Loading…
Cancel
Save