49 lines
1.7 KiB
Java
49 lines
1.7 KiB
Java
package com.myoa.engineering.crawl.ppomppu.support.webclient.factory;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.reactive.function.client.ClientRequest;
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
/**
|
|
* WebClientFilterFactory
|
|
*
|
|
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
|
* @since 2021-09-07
|
|
*/
|
|
@Slf4j
|
|
public final class WebClientFilterFactory {
|
|
|
|
private WebClientFilterFactory() {}
|
|
|
|
public static ExchangeFilterFunction logRequest() {
|
|
return ExchangeFilterFunction.ofRequestProcessor(WebClientFilterFactory::writeRequest);
|
|
}
|
|
|
|
public static ExchangeFilterFunction logResponse() {
|
|
return ExchangeFilterFunction.ofResponseProcessor(WebClientFilterFactory::writeResponse);
|
|
}
|
|
|
|
private static Mono<ClientRequest> writeRequest(ClientRequest clientRequest) {
|
|
try {
|
|
log.info("[WEBCLIENT REQUEST] uri : {} method : {} headers : {}, body: {}",
|
|
clientRequest.url(), clientRequest.method(), clientRequest.headers(), clientRequest.body());
|
|
} catch (Exception e) {
|
|
log.error("[WEBCLIENT REQUEST] write request failed", e);
|
|
}
|
|
return Mono.just(clientRequest);
|
|
}
|
|
|
|
private static Mono<ClientResponse> writeResponse(ClientResponse clientResponse) {
|
|
try {
|
|
log.info("[WEBCLIENT RESPONSE] statusCode : {} headers : {}",
|
|
clientResponse.rawStatusCode(), clientResponse.headers().asHttpHeaders());
|
|
} catch (Exception e) {
|
|
log.error("[WEBCLIENT RESPONSE] write response failed", e);
|
|
}
|
|
return Mono.just(clientResponse);
|
|
}
|
|
|
|
}
|