Skip to content

Commit

Permalink
Refactor to use WebClient.Builder in consumers (#3638)
Browse files Browse the repository at this point in the history
Updated the constructors of various consumer classes to accept and use WebClient.Builder for creating WebClient instances. This improves consistency across the codebase and allows easier customization of WebClient configurations.
  • Loading branch information
krharum authored Sep 26, 2024
1 parent 2d28ec7 commit 956bb0e
Show file tree
Hide file tree
Showing 96 changed files with 348 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@

@Service
public class PdlAdresseConsumer {

private final WebClient webClient;
private final TokenExchange tokenExchange;
private final ServerProperties serverProperties;

public PdlAdresseConsumer(
TokenExchange tokenExchange,
Consumers consumers) {
Consumers consumers,
WebClient.Builder webClientBuilder) {
this.tokenExchange = tokenExchange;
serverProperties = consumers.getPdlServices();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public class OppsummeringsdokumentConsumer {
public OppsummeringsdokumentConsumer(
Consumers consumers,
ObjectMapper objectMapper,
ApplicationProperties applicationProperties) {
ApplicationProperties applicationProperties,
WebClient.Builder webClientBuilder) {

this.applicationProperties = applicationProperties;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(consumers.getOppsummeringsdokumentService().getUrl())
.codecs(
clientDefaultCodecsConfigurer -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public class GithubConsumer {
private static final int PAGE_SIZE = 100;
private final WebClient webClient;

public GithubConsumer(@Value("${consumers.github.url}") String url, @Value("${consumers.github.token}") String token) {
public GithubConsumer(@Value("${consumers.github.url}") String url,
@Value("${consumers.github.token}") String token,
WebClient.Builder webClientBuilder) {

this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(url)
.defaultHeader(HttpHeaders.AUTHORIZATION, "token " + token)
.exchangeStrategies(ExchangeStrategies.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public class AaregConsumer {
public AaregConsumer(
Consumers consumers,
TokenExchange tokenExchange,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTestnavAaregProxy();
this.tokenExchange = tokenExchange;
ExchangeStrategies jacksonStrategy = ExchangeStrategies
Expand All @@ -47,8 +49,7 @@ public AaregConsumer(
.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
})
.build();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.exchangeStrategies(jacksonStrategy)
.baseUrl(serverProperties.getUrl())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class PersonOrganisasjonTilgangConsumer {
public PersonOrganisasjonTilgangConsumer(
Consumers consumers,
TokenExchange tokenExchange,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {
serverProperties = consumers.getTestnavPersonOrganisasjonTilgangService();
this.tokenExchange = tokenExchange;
ExchangeStrategies jacksonStrategy = ExchangeStrategies
Expand All @@ -36,8 +37,7 @@ public PersonOrganisasjonTilgangConsumer(
.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
})
.build();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.exchangeStrategies(jacksonStrategy)
.baseUrl(serverProperties.getUrl())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
log.warn("Persondata for {} gir tom response fra PDL", dollyPerson.getIdent());
}
})
.filter(utvidetPersondata -> !utvidetPersondata.getT1().isEmpty())
.flatMap(utvidetPersondata -> Flux.concat(
opprettPersoner(dollyPerson.getIdent(), tilgjengeligeMiljoer, utvidetPersondata.getT1())
.map(response -> PENSJON_FORVALTER + decodeStatus(response, dollyPerson.getIdent())),
Expand All @@ -150,6 +151,7 @@ public Flux<ClientFuture> gjenopprett(RsDollyUtvidetBestilling bestilling, Dolly
)
.collectList()
.doOnNext(statusResultat::addAll)
.filter(status -> status.stream().allMatch(entry -> entry.contains("OK")))
.map(status -> Flux.just(bestilling1)
.filter(bestilling2 -> nonNull(bestilling2.getPensjonforvalter()))
.map(RsDollyUtvidetBestilling::getPensjonforvalter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class BrukerConsumer {
private final AccessService accessService;

public BrukerConsumer(TestnavBrukerServiceProperties serviceProperties,
AccessService accessService) {
AccessService accessService,
WebClient.Builder webClientBuilder) {

this.serviceProperties = serviceProperties;
this.accessService = accessService;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serviceProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import no.nav.dolly.web.consumers.command.GetPersonOrganisasjonTilgangCommand;
import no.nav.dolly.web.config.Consumers;
import no.nav.dolly.web.consumers.command.GetPersonOrganisasjonTilgangCommand;
import no.nav.dolly.web.service.AccessService;
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import org.springframework.http.MediaType;
Expand All @@ -27,7 +27,8 @@ public class PersonOrganisasjonTilgangConsumer {
public PersonOrganisasjonTilgangConsumer(
Consumers consumers,
AccessService accessService,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {

this.accessService = accessService;
serverProperties = consumers.getTestnavPersonOrganisasjonTilgangService();
Expand All @@ -39,8 +40,7 @@ public PersonOrganisasjonTilgangConsumer(
.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON));
}).build();

this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.exchangeStrategies(jacksonStrategy)
.baseUrl(serverProperties.getUrl())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class TilbakemeldingConsumer {

public TilbakemeldingConsumer(
Consumers consumers,
AccessService accessService) {
AccessService accessService,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTestnorgeTilbakemeldingApi();
this.webClient = WebClient.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
this.accessService = accessService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public class AdresseServiceConsumer {

public AdresseServiceConsumer(
TokenExchange tokenExchange,
Consumers consumers) {
Consumers consumers,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getAdresseService();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public class GenererNavnServiceConsumer {

public GenererNavnServiceConsumer(
TokenExchange tokenExchange,
Consumers consumers) {
Consumers consumers,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getGenererNavnService();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public class IdentPoolConsumer {

public IdentPoolConsumer(
TokenExchange tokenExchange,
Consumers consumers) {
Consumers consumers,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getIdentPool();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class TpsMessagingConsumer {
public TpsMessagingConsumer(
Consumers consumers,
TokenExchange tokenExchange,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTpsMessagingService();
this.accessTokenService = tokenExchange;
Expand All @@ -59,8 +60,7 @@ public TpsMessagingConsumer(
}).build();


this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.exchangeStrategies(jacksonStrategy)
.baseUrl(serverProperties.getUrl())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class GenererOrganisasjonPopulasjonConsumer {

public GenererOrganisasjonPopulasjonConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTestnavGenererOrganisasjonPopulasjonService();
this.tokenExchange = tokenExchange;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public OppsummeringsdokumentConsumer(
TokenExchange tokenExchange,
Consumers consumers,
ObjectMapper objectMapper,
ApplicationProperties applicationProperties) {
ApplicationProperties applicationProperties,
WebClient.Builder webClientBuilder) {

this.applicationProperties = applicationProperties;
this.tokenExchange = tokenExchange;
serverProperties = consumers.getOppsummeringsdokumentService();
this.executor = Executors.newFixedThreadPool(20);

this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.codecs(clientDefaultCodecsConfigurer -> {
clientDefaultCodecsConfigurer.defaultCodecs().maxInMemorySize(BYTE_COUNT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public class OrganisasjonConsumer {

public OrganisasjonConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTestnavOrganisasjonService();
this.tokenExchange = tokenExchange;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public class SyntArbeidsforholdConsumer {
public SyntArbeidsforholdConsumer(
TokenExchange tokenExchange,
Consumers consumers,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getSyntAmelding();
this.objectMapper = objectMapper;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.codecs(clientDefaultCodecsConfigurer -> {
clientDefaultCodecsConfigurer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public class GenererNavnConsumer {

public GenererNavnConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getGenererNavnService();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public class OrgnummerConsumer {

public OrgnummerConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

serverProperties = consumers.getTestnavOrgnummerService();
this.tokenExchange = tokenExchange;
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class SyntAmeldingConsumer {
private final TokenExchange tokenExchange;

public SyntAmeldingConsumer(TokenExchange tokenExchange,
Consumers consumers) {
Consumers consumers,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getSyntAmelding();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.exchangeStrategies(
ExchangeStrategies
.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public class DokmotConsumer {

public DokmotConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getTestnavDokarkivProxy();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Component;

import org.springframework.web.reactive.function.client.WebClient;

@Slf4j
Expand All @@ -20,11 +19,12 @@ public class GenererInntektsmeldingConsumer {

public GenererInntektsmeldingConsumer(
Consumers consumers,
TokenExchange tokenExchange) {
TokenExchange tokenExchange,
WebClient.Builder webClientBuilder) {

this.tokenExchange = tokenExchange;
serverProperties = consumers.getInntektsmeldingGeneratorService();
this.webClient = WebClient
.builder()
this.webClient = webClientBuilder
.baseUrl(serverProperties.getUrl())
.build();
}
Expand Down
Loading

0 comments on commit 956bb0e

Please sign in to comment.