From a8b54908527ff4ecb2774d636eed6208d75bb5c1 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Fri, 12 Jul 2024 08:56:01 -0700 Subject: [PATCH] MAT-7348: Revision. Fix double encoding. Manually construct Query String --- .../FhirTerminologyServiceWebClient.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java index d9a8905..8fd7df9 100644 --- a/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java +++ b/src/main/java/gov/cms/madie/terminology/webclient/FhirTerminologyServiceWebClient.java @@ -19,8 +19,12 @@ import reactor.core.publisher.Mono; import java.net.URI; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Map; +import java.util.stream.Collectors; @Component @Slf4j @@ -72,19 +76,22 @@ public String searchValueSets(String apiKey, Map queryParams) { if (!urlValue.startsWith("http://cts.nlm.nih.gov/fhir/ValueSet/")) { urlValue = "http://cts.nlm.nih.gov/fhir/ValueSet/" + urlValue; } - // if user didnt add htpp:// we do + // if user didn't add http:// we do if (!urlValue.startsWith("http://")) { urlValue = "http://" + urlValue; } queryParams.put("url", urlValue); } - MultiValueMap multiValueMap = new LinkedMultiValueMap<>(); - multiValueMap.setAll(queryParams); - URI uri = - UriComponentsBuilder.fromUriString(searchValueSetEndpoint) - .queryParams(multiValueMap) - .build() - .toUri(); + + // Manually construct the query string + String queryString = queryParams.entrySet().stream() + .map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)) + .collect(Collectors.joining("&")); + + String url = searchValueSetEndpoint + "?" + queryString; + + URI uri = URI.create(url); + log.info("value set search url is: {}", uri.toString()); return fetchResourceFromVsac(uri.toString(), apiKey, "bundle"); } @@ -113,6 +120,8 @@ public String getCodeResource(String code, CodeSystem codeSystem, String apiKey) } private String fetchResourceFromVsac(String uri, String apiKey, String resourceType) { + var currentUri = uri; + log.info("[{}] currentUri is", currentUri); return fhirTerminologyWebClient .get() .uri(uri)