fix: WebClient call log fix

CORS filter class add
dev
gitea-관리자 1 year ago
parent 590d01ce61
commit 6ad52cf26b

@ -1,14 +1,20 @@
package kr.xit.biz.kt.service; package kr.xit.biz.kt.service;
import java.util.ArrayList;
import java.util.List;
import kr.xit.biz.cmm.service.ICmmEnsCacheService; import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO; import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO; import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMainSendReqData;
import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMainSendRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse; import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse;
import kr.xit.biz.kt.mapper.IBizKtMmsMapper; import kr.xit.biz.kt.mapper.IBizKtMmsMapper;
import kr.xit.core.exception.BizRuntimeException; import kr.xit.core.exception.BizRuntimeException;
import kr.xit.ens.kt.service.IKtMmsService; import kr.xit.ens.kt.service.IKtMmsService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl; import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -32,6 +38,7 @@ import org.springframework.stereotype.Service;
@Service @Service
public class BizKtMmsService extends EgovAbstractServiceImpl implements IBizKtMmsService { public class BizKtMmsService extends EgovAbstractServiceImpl implements IBizKtMmsService {
private static final String profile = System.getProperty("spring.profiles.active"); private static final String profile = System.getProperty("spring.profiles.active");
private static final int MAX_KT_SEND_CNT = 100;
private final IKtMmsService ktMmsService; private final IKtMmsService ktMmsService;
private final ICmmEnsCacheService cacheService; private final ICmmEnsCacheService cacheService;
@ -73,6 +80,56 @@ public class BizKtMmsService extends EgovAbstractServiceImpl implements IBizKtMm
return resDTO; return resDTO;
} }
@Override
public KtCommonResponse mainSend(final KtMnsRequest reqDTO) {
List<KtMainSendReqData> mainSendReqs = new ArrayList<>();
KtMainSendReqData reqData = KtMainSendReqData.builder()
.srcKey("db")
.srcSeq("1++")
.ci("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678")
.mmsDtlCnts("db")
.docHash("db")
.mmsTitle("")
.url("/api/biz/kt/v1/receiveMain?kkk=llll") //distInfoCrtYn - N이면 필수
.mmsBinary("")
.fileFmat("")
.mdn("")
.distInfoCrtYn("N")
//.infoCfrmStr("")
.build();
mainSendReqs.add(reqData);
List<List<KtMainSendReqData>> parts = ListUtils.partition(mainSendReqs, MAX_KT_SEND_CNT);
KtCommonResponse ktTokenResponse = null;
for(List<KtMainSendReqData> reqs : parts) {
KtMainSendRequest ktReqDTO = KtMainSendRequest.builder()
.signguCode(reqDTO.getSignguCode())
.ffnlgCode(reqDTO.getFfnlgCode())
.profile(profile)
//.serviceCd("cache")
//.serviceKey("cache")
.msgCd("db")
//.msgType("2")
.makeDt("123456789012db")
.sndnExTime("123456789012db")
.exTime("123456789012db")
//.mType("4")
.sndnTotCnt(reqs.size()) //-> 요청건수 count
.mmsBinary("db")
.fileFmat("db")
.testSndnYn("N")
.reqs(reqs)
.build();
ktTokenResponse = ktMmsService.mainSend(ktReqDTO);
}
return ktTokenResponse;
}
// /** // /**
// * 사전 문자 수신 등록 요청(BC-AG-SN-001) // * 사전 문자 수신 등록 요청(BC-AG-SN-001)
// * @param reqDTO // * @param reqDTO

@ -1,6 +1,7 @@
package kr.xit.biz.kt.service; package kr.xit.biz.kt.service;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse; import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse;
@ -23,6 +24,8 @@ import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse;
public interface IBizKtMmsService { public interface IBizKtMmsService {
KtTokenResponse requestToken(final KtMnsRequest paramDTO); KtTokenResponse requestToken(final KtMnsRequest paramDTO);
KtCommonResponse mainSend(final KtMnsRequest reqDTO);
// KtCommonResponse beforeSend(final KtBefSendRequest reqDTO); // KtCommonResponse beforeSend(final KtBefSendRequest reqDTO);
// KtCommonResponse mainSend(final KtMainSendRequest reqDTO); // KtCommonResponse mainSend(final KtMainSendRequest reqDTO);
// KtCommonResponse blacklist(final KtBlacklistRequest reqDTO); // KtCommonResponse blacklist(final KtBlacklistRequest reqDTO);

@ -1,11 +1,16 @@
package kr.xit.biz.kt.web; package kr.xit.biz.kt.web;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Map;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.kt.service.IBizKtMmsService; import kr.xit.biz.kt.service.IBizKtMmsService;
import kr.xit.core.model.ApiResponseDTO; import kr.xit.core.model.ApiResponseDTO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -31,14 +36,68 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor @RequiredArgsConstructor
@RestController @RestController
@RequestMapping(value = "/api/biz/kt/v1") @RequestMapping(value = "/api/biz/kt/v1")
@Slf4j
public class BizKtMmsController { public class BizKtMmsController {
private static final String PARAM1 = """
{
"signguCode": "88328",
"ffnlgCode": "11",
"juminId": "9901011263512"
}
""";
private static final String PARAM2 = """
{
"signguCode": "88316",
"ffnlgCode": "11",
"juminId": "9901011263512"
}
""";
private final IBizKtMmsService service; private final IBizKtMmsService service;
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(
mediaType = "application/json",
examples = {
@ExampleObject(
name = "교통시설운영처",
value = PARAM1),
@ExampleObject(
name = "승화원",
value = PARAM2)
})
})
@Operation(summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청") @Operation(summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청")
@PostMapping(value = "/requestToken", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/requestToken", produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseDTO<?> requestToken(@RequestBody final KtMnsRequest paramDTO) { public ApiResponseDTO<?> requestToken(@RequestBody final KtMnsRequest paramDTO) {
return ApiResponseDTO.success(service.requestToken(paramDTO)); return ApiResponseDTO.success(service.requestToken(paramDTO));
} }
@io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
@Content(
mediaType = "application/json",
examples = {
@ExampleObject(
name = "교통시설운영처",
value = PARAM1),
@ExampleObject(
name = "승화원",
value = PARAM2)
})
})
@Operation(summary = "본문자 수신 등록 요청", description = "본문자 수신 등록 요청(BC-AG-SN-002)")
@PostMapping(value = "/mainSend", produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseDTO<?> mainSend(@RequestBody final KtMnsRequest reqDTO) {
KtCommonResponse dto = service.mainSend(reqDTO);
return ApiResponseDTO.success(dto);
}
@Operation(summary = "본문자 수신", description = "본문자 수신")
@PostMapping(value = "/receiveMain", produces = MediaType.APPLICATION_JSON_VALUE)
public void requestToken(@RequestBody final Map<String,Object> paramMap) {
log.debug("{}", paramMap);
}
// //
// /* // /*
// @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = { // @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {

@ -237,7 +237,7 @@ public class NiceCiService extends EgovAbstractServiceImpl implements INiceCiSer
//.infoReqType() //default: 1-CI제공 //.infoReqType() //default: 1-CI제공
.juminId(reqDTO.getJuminId()) .juminId(reqDTO.getJuminId())
.reqNo(CmmEnsUtils.generateLengthUuid(30)) .reqNo(CmmEnsUtils.generateLengthUuid(30))
.reqDtim(DateUtils.getTodayAndNowTime("yyyyMMddHHmmss"))
.clientIp(IpMacUtils.getIpAddress().get(0)) .clientIp(IpMacUtils.getIpAddress().get(0))
.build(); .build();
CmmEnsUtils.validate(encDataDTO); CmmEnsUtils.validate(encDataDTO);

@ -51,7 +51,7 @@ logging:
# Spring Security cors 설정 :: CorsConfiguration 설정 값 # Spring Security cors 설정 :: CorsConfiguration 설정 값
cors: cors:
allowed-origins: http://localhost:8082 allowed-origins: http://localhost:8080, http://localhost:8082
# ================================================================================================================== # ==================================================================================================================
# SQL logging lib setting # SQL logging lib setting

@ -406,7 +406,7 @@ public class KtMmsSendDTO {
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "DP112") @Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "DP112")
@Size(min = 5, max = 5, message = "문서 코드는 필수 입니다(max:5)") @Size(min = 1, max = 5, message = "문서 코드는 필수 입니다(max:5)")
private String msgCd; private String msgCd;
/** /**
@ -416,8 +416,8 @@ public class KtMmsSendDTO {
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "발송 메시지 타입", example = "2") @Schema(requiredMode = RequiredMode.REQUIRED, title = "발송 메시지 타입", example = "2")
@Size(min = 1, max = 1, message = "발송 메시지 타입은 필수 입니다") @Size(min = 1, max = 1, message = "발송 메시지 타입은 필수 입니다(1|2)")
private String msgType; private final String msgType = "2";
/** /**
* <pre> * <pre>
@ -426,7 +426,7 @@ public class KtMmsSendDTO {
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "발송시작일시", example = "20211229102000") @Schema(requiredMode = RequiredMode.REQUIRED, title = "발송시작일시", example = "20211229102000")
@Size(min = 14, max = 14, message = "발송시작일시는 필수 입니다") @Size(min = 14, max = 14, message = "발송시작일시는 필수 입니다(YYYYMMDDHHMiSS)")
private String makeDt; private String makeDt;
/** /**
@ -436,7 +436,7 @@ public class KtMmsSendDTO {
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "발송마감시간", example = "20211229180000") @Schema(requiredMode = RequiredMode.REQUIRED, title = "발송마감시간", example = "20211229180000")
@Size(min = 14, max = 14, message = "발송마감시간은 필수 입니다") @Size(min = 14, max = 14, message = "발송마감시간은 필수 입니다(YYYYMMDDHHMiSS)")
private String sndnExTime; private String sndnExTime;
/** /**
@ -446,7 +446,7 @@ public class KtMmsSendDTO {
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "열람마감시간", example = "20211229180000") @Schema(requiredMode = RequiredMode.REQUIRED, title = "열람마감시간", example = "20211229180000")
@Size(min = 14, max = 14, message = "열람마감시간은 필수 입니다") @Size(min = 14, max = 14, message = "열람마감시간은 필수 입니다(YYYYMMDDHHMiSS)")
private String exTime; private String exTime;
/** /**
@ -460,9 +460,8 @@ public class KtMmsSendDTO {
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "문서종류", example = "2") @Schema(requiredMode = RequiredMode.REQUIRED, title = "문서종류", example = "2")
@NotEmpty(message = "문서종류는 필수 입니다(max:3)") @NotEmpty(message = "문서종류는 필수 입니다(max:3)")
@Size(max = 3)
@JsonProperty("m_type") @JsonProperty("m_type")
private String mType; private final String mType = "4";
/** /**
* <pre> * <pre>
@ -700,10 +699,12 @@ public class KtMmsSendDTO {
private String ci; private String ci;
/** /**
* <pre>
* MMS : max 4000 * MMS : max 4000
* URL * URL
* {#INFO_CFRM_STR}, {#RCVE_RF_STR} . * {#INFO_CFRM_STR}, {#RCVE_RF_STR} .
* , 'Y' {#RCVE_RF_STR} . * , 'Y' {#RCVE_RF_STR} .
* </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "MMS 상세내용", example = "gdlIa53FZGQz5aKa3wLk33nW57N3mDpcwHytWlWMhzxHKulk7EZs143442394326642342364238648423864237") @Schema(requiredMode = RequiredMode.REQUIRED, title = "MMS 상세내용", example = "gdlIa53FZGQz5aKa3wLk33nW57N3mDpcwHytWlWMhzxHKulk7EZs143442394326642342364238648423864237")
@Size(min = 1, max = 4000, message = "MMS 상세내용은 4000자를 넘을 수 없습니다.") @Size(min = 1, max = 4000, message = "MMS 상세내용은 4000자를 넘을 수 없습니다.")

@ -101,7 +101,7 @@ public class WebClientConfig {
* pendingAcquireTimeout : * pendingAcquireTimeout :
* pendingAcquireMaxCount : (-1: no limit) * pendingAcquireMaxCount : (-1: no limit)
* maxIdleTime : idle * maxIdleTime : idle
* @return * @return ConnectionProvider
*/ */
@Bean @Bean
public ConnectionProvider connectionProvider() { public ConnectionProvider connectionProvider() {
@ -136,15 +136,15 @@ public class WebClientConfig {
} }
private ExchangeFilterFunction requestFilter() { private ExchangeFilterFunction requestFilter() {
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> { return ExchangeFilterFunction.ofRequestProcessor(cr -> {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder("\n>>>>>>>>>> WebClient Http Request <<<<<<<<<<<<<\n"); StringBuilder sb = new StringBuilder("\n>>>>>>>>>> WebClient Http Request <<<<<<<<<<<<<\n");
sb.append(logMethodAndUrl(clientRequest)); sb.append(logMethodAndUrl(cr));
sb.append(logHeaders(clientRequest)); sb.append(logHeaders(cr));
sb.append("-------------------------------------------------------"); sb.append("-------------------------------------------------------");
log.debug(sb.toString()); log.debug(sb.toString());
} }
return Mono.just(clientRequest); return Mono.just(cr);
}); });
} }
@ -153,29 +153,28 @@ public class WebClientConfig {
* @return ExchangeFilterFunction * @return ExchangeFilterFunction
*/ */
private ExchangeFilterFunction responseFilter() { private ExchangeFilterFunction responseFilter() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { return ExchangeFilterFunction.ofResponseProcessor(cr -> {
HttpStatus status = clientResponse.statusCode(); HttpStatus status = cr.statusCode();
if(clientResponse.statusCode().is4xxClientError()) { if(cr.statusCode().is4xxClientError()) {
return clientResponse.bodyToMono(String.class) return cr.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ClientError(status, errorBody))); .flatMap(errorBody -> Mono.error(new ClientError(status, errorBody)));
} else if(clientResponse.statusCode().is5xxServerError()) { } else if(cr.statusCode().is5xxServerError()) {
return clientResponse.bodyToMono(String.class) return cr.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ServerError(status, errorBody))); .flatMap(errorBody -> Mono.error(new ServerError(status, errorBody)));
} }
if(log.isDebugEnabled()) { if(log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder( StringBuilder sb = new StringBuilder(
"\n>>>>>>>>>> WebClient Http Response <<<<<<<<<<<<<\n"); "\n>>>>>>>>>> WebClient Http Response <<<<<<<<<<<<<\n");
sb.append(logStatus(clientResponse)); sb.append(logStatus(cr));
sb.append(logHeaders(clientResponse)); sb.append(logHeaders(cr));
sb.append("-------------------------------------------------------"); sb.append("-------------------------------------------------------");
log.debug(sb.toString()); log.debug(sb.toString());
return logBody(clientResponse);
} }
return Mono.just(clientResponse); return Mono.just(cr);
}); });
} }
@ -184,19 +183,6 @@ public class WebClientConfig {
return String.format("Returned staus code %s (%s)", status.value(), status.getReasonPhrase()); return String.format("Returned staus code %s (%s)", status.value(), status.getReasonPhrase());
} }
private static Mono<ClientResponse> logBody(ClientResponse response) {
if (response.statusCode() != null && (response.statusCode().is4xxClientError() || response.statusCode().is5xxServerError())) {
return response.bodyToMono(String.class)
.flatMap(body -> {
log.debug("Body is {}", body);
return Mono.just(response);
});
} else {
return Mono.just(response);
}
}
private static String logHeaders(ClientRequest request) { private static String logHeaders(ClientRequest request) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

@ -0,0 +1,63 @@
package kr.xit.core.spring.filter;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import kr.xit.core.spring.config.properties.CorsProperties;
import kr.xit.core.spring.util.CoreSpringUtils;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* <pre>
* description : Cors filter
* {@code @Override} {@link WebMvcConfigurer#addCorsMappings}
* packageName : kr.xit.core.spring.filter
* fileName : SimpleCORSFilter
* author : julim
* date : 2023-04-28
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-04-28 julim
*
* </pre>
*/
@Deprecated
public class SimpleCORSFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
CorsProperties corsProperties = CoreSpringUtils.getCorsProperties();
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Origins", toArrayString(corsProperties.getAllowedOrigins()));
httpResponse.setHeader("Access-Control-Allow-Methods", toArrayString(corsProperties.getAllowedMethods()));
httpResponse.setHeader("Access-Control-Allow-Headers", toArrayString(corsProperties.getAllowedHeaders()));
httpResponse.setHeader("Access-Control-Allow-Credentials", corsProperties.getAllowCredentials().toString());
httpResponse.setHeader("Access-Control-Max-Age", corsProperties.getMaxAge().toString());
httpResponse.setHeader("Access-Control-Expose-Headers", corsProperties.getExposeHeader());
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) {
// Do nothing
}
@Override
public void destroy() {
// Do nothing
}
private String toArrayString(String[] arrStr){
return Arrays.stream(arrStr)
.map(s -> s.trim())
.collect(Collectors.joining(","));
}
}
Loading…
Cancel
Save