fix: WebClientConfig logging 정리

dev
gitea-관리자 1 year ago
parent c7f524213b
commit 47b7b95b3f

@ -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();
}
/**
* <pre>
* Http client
* - / debugging wiretap - AdvancedByteBufFormat.TEXTUAL
* @return HttpClient
* </pre>
*/
@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();
}
/**
* <pre>
* 1. 256KB HTTP DataBufferLimitException
* 2. messageWriters logging(setEnableLoggingRequestDetails(true)
* -> org.springframework.web.reactive.function.client.ExchangeFunctions: DEBUG
* -> defaultHttpClient() wiretap
* </pre>
* @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);
});
}

Loading…
Cancel
Save