|
|
|
@ -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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|