Skip to content

Commit

Permalink
Oppdatert dekoding #deploy-tenor-search-service
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Jan 13, 2024
1 parent 442b739 commit 87dc369
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TenorResponse> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,11 +33,16 @@ public Mono<TenorResponse> 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()
Expand Down

0 comments on commit 87dc369

Please sign in to comment.