From 05489cec684876a44098f991c4915a5214bba80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Sat, 23 Mar 2024 09:47:52 +0900 Subject: [PATCH] add: Webclient COnfig --- .../configuration/WebClientConfiguration.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/kotlin/com/trip/safe/common/webclient/configuration/WebClientConfiguration.kt diff --git a/src/main/kotlin/com/trip/safe/common/webclient/configuration/WebClientConfiguration.kt b/src/main/kotlin/com/trip/safe/common/webclient/configuration/WebClientConfiguration.kt new file mode 100644 index 0000000..b11955f --- /dev/null +++ b/src/main/kotlin/com/trip/safe/common/webclient/configuration/WebClientConfiguration.kt @@ -0,0 +1,31 @@ +package com.trip.safe.common.webclient.configuration + +import com.trip.safe.common.logger.logger +import org.slf4j.Logger +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.util.DefaultUriBuilderFactory + +@Configuration +class WebClientConfiguration( + @Value("\${service.url}") + private val serviceUrl: String, +) { + private val log: Logger = logger() + + @Bean + fun defaultUriFactory() = DefaultUriBuilderFactory(serviceUrl).apply { + encodingMode = DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY + } + + @Bean + fun webClient() = WebClient.builder() + .uriBuilderFactory(defaultUriFactory()) + .filter { request, next -> + log.info("try to request webclient url : ${request.url()}, method : ${request.method()}") + next.exchange(request) + } + .build() +}