From 47b7b95b3f64889e678cb8d4d62af7701f9fa074 Mon Sep 17 00:00:00 2001 From: limju Date: Wed, 18 Oct 2023 10:49:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20WebClientConfig=20logging=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/support/WebClientConfig.java | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/mens-core/src/main/java/kr/xit/core/spring/config/support/WebClientConfig.java b/mens-core/src/main/java/kr/xit/core/spring/config/support/WebClientConfig.java index a106e00..1609620 100644 --- a/mens-core/src/main/java/kr/xit/core/spring/config/support/WebClientConfig.java +++ b/mens-core/src/main/java/kr/xit/core/spring/config/support/WebClientConfig.java @@ -18,7 +18,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.http.codec.LoggingCodecSupport; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.web.reactive.function.client.ClientRequest; @@ -78,17 +77,23 @@ public class WebClientConfig { .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024)) .exchangeStrategies(defaultExchangeStrategies()) .filters(exchangeFilterFunctions -> { - exchangeFilterFunctions.add(requestFilter()); + //exchangeFilterFunctions.add(requestFilter()); exchangeFilterFunctions.add(responseFilter()); }) .build(); } - + /** + *
+     * Http client 생성
+     * - 요청 / 응답 debugging을 위해 wiretap 설정 - AdvancedByteBufFormat.TEXTUAL
+     * @return HttpClient
+     * 
+ */ @Bean public HttpClient defaultHttpClient() { return HttpClient.create(connectionProvider()) - .wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL) + .wiretap(this.getClass().getCanonicalName(), LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout) .responseTimeout(Duration.ofMillis(this.connectTimeout)) .doOnConnected(conn -> @@ -113,10 +118,19 @@ public class WebClientConfig { .build(); } + /** + *
+     * 1. 256KB 보다 큰 HTTP 메시지를 처리 시도 → DataBufferLimitException 에러 발생 방어
+     * 2. messageWriters를 통한 logging(setEnableLoggingRequestDetails(true)
+     *    -> org.springframework.web.reactive.function.client.ExchangeFunctions: DEBUG 하여 활성
+     *    -> defaultHttpClient()의 wiretap 사용으로 비활성
+     * 
+ * @return ExchangeStrategies + */ @Bean public ExchangeStrategies defaultExchangeStrategies() { // 256KB 보다 큰 HTTP 메시지를 처리 시도 → DataBufferLimitException 에러 발생 방어 - ExchangeStrategies es = ExchangeStrategies.builder() + return ExchangeStrategies.builder() .codecs(config -> { config.defaultCodecs().maxInMemorySize(2 * 1024 * 1024); config.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); @@ -124,15 +138,10 @@ public class WebClientConfig { }) .build(); - //FIXME::rest call async 로깅 - // ExchangeStrategies를 통해 setEnableLoggingRequestDetails(true)로 설정 - // boot에서 로깅 org.springframework.web.reactive.function.client.ExchangeFunctions: DEBUG 하여 활성 - es.messageWriters() - .stream() - .filter(LoggingCodecSupport .class::isInstance) - .forEach(writer -> ((LoggingCodecSupport)writer).setEnableLoggingRequestDetails(true)); - - return es; +// es.messageWriters() +// .stream() +// .filter(LoggingCodecSupport.class::isInstance) +// .forEach(writer -> ((LoggingCodecSupport)writer).setEnableLoggingRequestDetails(true)); } private ExchangeFilterFunction requestFilter() { @@ -166,14 +175,14 @@ public class WebClientConfig { .flatMap(errorBody -> Mono.error(new ServerError(status, errorBody))); } - if(log.isDebugEnabled()) { - StringBuilder sb = new StringBuilder( - "\n>>>>>>>>>> WebClient Http Response <<<<<<<<<<<<<\n"); - sb.append(logStatus(cr)); - sb.append(logHeaders(cr)); - sb.append("-------------------------------------------------------"); - log.debug(sb.toString()); - } +// if(log.isDebugEnabled()) { +// StringBuilder sb = new StringBuilder( +// "\n>>>>>>>>>> WebClient Http Response <<<<<<<<<<<<<\n"); +// sb.append(logStatus(cr)); +// sb.append(logHeaders(cr)); +// sb.append("-------------------------------------------------------"); +// log.debug(sb.toString()); +// } return Mono.just(cr); }); }