Skip to content

Commit

Permalink
Merge pull request #1232 from navikt/nav-call-id
Browse files Browse the repository at this point in the history
Common config for "nav-call-id" in webClients.
  • Loading branch information
flexable777 authored Oct 3, 2024
2 parents 6054f22 + ec05579 commit b0b0584
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.klage.oppgave.clients.kodeverk

import io.opentelemetry.api.trace.Span
import no.nav.klage.oppgave.config.CacheWithJCacheConfiguration
import no.nav.klage.oppgave.exceptions.KodeverkNotFoundException
import no.nav.klage.oppgave.util.TokenUtil
Expand Down Expand Up @@ -39,7 +38,6 @@ class KodeverkClient(
.queryParam("spraak", "NO")
.build()
}
.header("Nav-Call-Id", Span.current().spanContext.traceId)
.header(
HttpHeaders.AUTHORIZATION,
"Bearer ${tokenUtil.getSaksbehandlerAccessTokenWithKodeverkScope()}"
Expand Down Expand Up @@ -76,7 +74,6 @@ class KodeverkClient(
.queryParam("spraak", "NO")
.build()
}
.header("Nav-Call-Id", Span.current().spanContext.traceId)
.header(
HttpHeaders.AUTHORIZATION,
"Bearer ${tokenUtil.getSaksbehandlerAccessTokenWithKodeverkScope()}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.klage.oppgave.clients.krrproxy

import io.opentelemetry.api.trace.Span
import no.nav.klage.oppgave.config.CacheWithJCacheConfiguration
import no.nav.klage.oppgave.util.TokenUtil
import no.nav.klage.oppgave.util.getLogger
Expand Down Expand Up @@ -39,7 +38,6 @@ class KrrProxyClient(
logger.debug("Getting info from KRR")
return krrProxyWebClient.get()
.uri("/rest/v1/person")
.header("Nav-Call-Id", Span.current().spanContext.traceId)
.header(
HttpHeaders.AUTHORIZATION,
"Bearer $token"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.klage.oppgave.clients.oppgaveapi

import io.opentelemetry.api.trace.Span
import no.nav.klage.oppgave.util.TokenUtil
import no.nav.klage.oppgave.util.getLogger
import no.nav.klage.oppgave.util.getSecureLogger
Expand Down Expand Up @@ -34,7 +33,6 @@ class OppgaveApiClient(
HttpHeaders.AUTHORIZATION,
"Bearer ${if (systemContext) tokenUtil.getAppAccessTokenWithOppgaveApiScope() else tokenUtil.getSaksbehandlerAccessTokenWithOppgaveApiScope()}"
)
.header("X-Correlation-ID", Span.current().spanContext.traceId)
.header("Nav-Consumer-Id", applicationName)
.retrieve()
.bodyToMono<OppgaveApiRecord>()
Expand All @@ -57,7 +55,6 @@ class OppgaveApiClient(
HttpHeaders.AUTHORIZATION,
"Bearer ${if (systemContext) tokenUtil.getAppAccessTokenWithOppgaveApiScope() else tokenUtil.getSaksbehandlerAccessTokenWithOppgaveApiScope()}"
)
.header("X-Correlation-ID", Span.current().spanContext.traceId)
.header("Nav-Consumer-Id", applicationName)
.retrieve()
.bodyToMono<OppgaveApiRecord>()
Expand All @@ -80,7 +77,6 @@ class OppgaveApiClient(
HttpHeaders.AUTHORIZATION,
"Bearer ${tokenUtil.getSaksbehandlerAccessTokenWithOppgaveApiScope()}"
)
.header("X-Correlation-ID", Span.current().spanContext.traceId)
.header("Nav-Consumer-Id", applicationName)
.retrieve()
.bodyToMono<OppgaveMapperResponse>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class ArbeidOgInntektClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -19,9 +15,6 @@ class ArbeidOgInntektClientConfiguration(private val webClientBuilder: WebClient
fun arbeidOgInntektWebClient(): WebClient {
return webClientBuilder
.baseUrl(arbeidOgInntektUrl)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class DokDistKanalClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -22,6 +20,5 @@ class DokDistKanalClientConfiguration(private val webClientBuilder: WebClient.Bu
webClientBuilder
.baseUrl(url)
.defaultHeader("Nav-Consumer-Id", applicationName)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class EregClientConfiguration(
Expand All @@ -25,7 +23,6 @@ class EregClientConfiguration(
fun eregWebClient(): WebClient {
return webClientBuilder
.baseUrl(eregServiceURL)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class KodeverkClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -22,6 +20,5 @@ class KodeverkClientConfiguration(private val webClientBuilder: WebClient.Builde
webClientBuilder
.baseUrl(url)
.defaultHeader("Nav-Consumer-Id", applicationName)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient


@Configuration
Expand All @@ -27,7 +25,6 @@ class KrrProxyClientConfiguration(
fun krrProxyWebClient(): WebClient {
return webClientBuilder
.baseUrl(krrProxyURL)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class MicrosoftGraphClientConfiguration(
Expand All @@ -25,7 +23,6 @@ class MicrosoftGraphClientConfiguration(
fun microsoftGraphWebClient(): WebClient {
return webClientBuilder
.baseUrl(microsoftGraphServiceURL)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class NomClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -19,9 +15,6 @@ class NomClientConfiguration(private val webClientBuilder: WebClient.Builder) {
fun nomWebClient(): WebClient {
return webClientBuilder
.baseUrl(nomUrl)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class Norg2ClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -21,6 +19,5 @@ class Norg2ClientConfiguration(private val webClientBuilder: WebClient.Builder)
webClientBuilder
.baseUrl(url)
.defaultHeader("x-nav-apiKey", apiKey)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient.newConnection

@Configuration
class OppgaveApiClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -18,9 +14,6 @@ class OppgaveApiClientConfiguration(private val webClientBuilder: WebClient.Buil
fun oppgaveApiWebClient(): WebClient {
return webClientBuilder
.baseUrl(oppgaveBaseURL)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.clientConnector(ReactorClientHttpConnector(newConnection()))
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class PdlClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -25,9 +21,6 @@ class PdlClientConfiguration(private val webClientBuilder: WebClient.Builder) {
fun pdlWebClient(): WebClient {
return webClientBuilder
.baseUrl(pdlUrl)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader("Nav-Consumer-Id", username)
.defaultHeader("TEMA", "KLA")
//Fra behandlingskatalogen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class RegoppslagClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -21,6 +19,5 @@ class RegoppslagClientConfiguration(private val webClientBuilder: WebClient.Buil
webClientBuilder
.baseUrl(url)
.defaultHeader("Nav-Consumer-Id", applicationName)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class SafClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -19,9 +15,6 @@ class SafClientConfiguration(private val webClientBuilder: WebClient.Builder) {
fun safWebClient(): WebClient {
return webClientBuilder
.baseUrl(safUrl)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package no.nav.klage.oppgave.config
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
class SkjermetClientConfiguration(private val webClientBuilder: WebClient.Builder) {
Expand All @@ -19,9 +15,6 @@ class SkjermetClientConfiguration(private val webClientBuilder: WebClient.Builde
fun skjermedeWebClient(): WebClient {
return webClientBuilder
.baseUrl(skjermedeUrl)
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
}
47 changes: 47 additions & 0 deletions src/main/kotlin/no/nav/klage/oppgave/config/WebClientCustomizer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package no.nav.klage.oppgave.config

import io.opentelemetry.api.trace.Span
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.client.ClientRequest
import org.springframework.web.reactive.function.client.ExchangeFilterFunction
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Mono
import reactor.netty.http.client.HttpClient

/**
* Common configuration for all web clients.
*/
@Component
class WebClientCustomizer : WebClientCustomizer {

override fun customize(webClientBuilder: WebClient.Builder) {
val headersWithTraceId = listOf(
"Nav-Call-Id",
"Nav-Callid",
"X-Correlation-ID",
)

webClientBuilder
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.filter(
ExchangeFilterFunction.ofRequestProcessor { request ->
val traceId = Span.current().spanContext.traceId
Mono.just(
ClientRequest.from(request)
.headers { headers ->
headersWithTraceId.forEach { headerName ->
headers[headerName] = traceId
}
}
.build()
)
}
)
}
}

0 comments on commit b0b0584

Please sign in to comment.