From 87dc3692dbb83ca2a0a3601edb52d25c48624f90 Mon Sep 17 00:00:00 2001 From: kristenhaerum Date: Sat, 13 Jan 2024 15:39:24 +0100 Subject: [PATCH] Oppdatert dekoding #deploy-tenor-search-service --- .../consumers/TenorClient.java | 15 ++++----------- .../consumers/command/GetTenorTestdata.java | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/TenorClient.java b/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/TenorClient.java index bb81158da71..3c90833af3a 100644 --- a/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/TenorClient.java +++ b/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/TenorClient.java @@ -13,31 +13,24 @@ @Service public class TenorClient { - private static final String TENOR_QUERY_URL = "/api/testnorge/v2/soek/freg"; private final WebClient webClient; private final MaskinportenClient maskinportenClient; public TenorClient(Consumers consumers, MaskinportenClient maskinportenClient) { + var uriFactory = new DefaultUriBuilderFactory(); + uriFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); + this.webClient = WebClient .builder() .baseUrl(consumers.getTenorSearchService().getUrl()) + .uriBuilderFactory(uriFactory) .build(); this.maskinportenClient = maskinportenClient; } public Mono getTestdata(String query) { - log.info("URI output: {}", new DefaultUriBuilderFactory().uriString(TENOR_QUERY_URL) - .queryParam("kql", query) - .queryParam("nokkelinformasjon", true) - .build()); - - log.info("URI output 2: {}", new DefaultUriBuilderFactory().uriString(TENOR_QUERY_URL) - .queryParam("kql", query) - .queryParam("nokkelinformasjon", true) - .build(false)); - return maskinportenClient.getAccessToken() .flatMap(token -> new GetTenorTestdata(webClient, query, token.value()).call()); } diff --git a/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/command/GetTenorTestdata.java b/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/command/GetTenorTestdata.java index 6afa47e8e16..b4a64d1e520 100644 --- a/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/command/GetTenorTestdata.java +++ b/apps/tenor-search-service/src/main/java/no/nav/testnav/apps/tenorsearchservice/consumers/command/GetTenorTestdata.java @@ -9,9 +9,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.DefaultUriBuilderFactory; import reactor.core.publisher.Mono; import reactor.util.retry.Retry; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.concurrent.Callable; @@ -30,11 +33,16 @@ public Mono call() { log.info("Query-parameter: {}", query); + var uri = new DefaultUriBuilderFactory(TENOR_QUERY_URL); + uri.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); + var ui = uri.builder() + .queryParam("kql", URLEncoder.encode(query, StandardCharsets.UTF_8)) + .queryParam("nokkelinformasjon", true) + .build(); + log.info("URI output: {}", ui); + return webClient.get() - .uri(uriBuilder -> uriBuilder.path(TENOR_QUERY_URL) - .queryParam("kql", query) - .queryParam("nokkelinformasjon", true) - .build()) + .uri(ui) .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .retrieve()