-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #529 from navikt/header_config
Header config
- Loading branch information
Showing
10 changed files
with
69 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/main/kotlin/no/nav/klage/config/AzureADClientConfiguration.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/no/nav/klage/config/WebClientCustomizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package no.nav.klage.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() | ||
) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters