상황

외부 API 연동해야 해서 service key(인코딩된것) 넣고 돌리니까 계속 service key 등록 안 됐다고 뜸

→ %로 인코딩 되어있던게 다시 한 번 25%로 인코딩 됨

→ encodingMode를 VALUES_ONLY로 설정하고 uriBuilderFactory 좀 건드니까 해결됨


해결

suspend fun getCountrySafetyInfo(searchId: String): MutableMap<String, String> {
        val factory = DefaultUriBuilderFactory(serviceUrl).apply {
            encodingMode = DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY
        }

        val webClient = WebClient.builder()
            .uriBuilderFactory(factory)
            .filter { request, next ->
                log.info("try to request webclient url : ${request.url()}, method : ${request.method()}")
                next.exchange(request)
            }
            .build()

        val response = webClient
            .get()
            .uri { uriBuilder ->
                uriBuilder
                    .path("/getCountrySafetyInfo")
                    .queryParam("serviceKey", serviceKey)
                    .queryParam("id", searchId)
                    .build()
            }
            .retrieve()
            .awaitBody<String>()

        val documentBuilderFactory = DocumentBuilderFactory.newInstance()
        val documentBuilder = documentBuilderFactory.newDocumentBuilder()
        val document = withContext(Dispatchers.IO) {
            documentBuilder.parse(InputSource(StringReader(response)))
        }
        document.documentElement.normalize()

        val safetyInfoMap = mutableMapOf<String, String>()

        TAG_LIST.forEach { tagName ->
            safetyInfoMap[tagName] = document.getElementsByTagName(tagName).item(0).textContent
        }

        return safetyInfoMap
    }