From 226bc3cbbcc3cec670f3ff1463e662f354f6bc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geir=20Andr=C3=A9=20Lund?= Date: Mon, 25 Nov 2024 13:45:20 +0100 Subject: [PATCH] =?UTF-8?q?Skudd=20i=20blinde.=20PR=C3=B8ver=20Apache5=20k?= =?UTF-8?q?tor=20engine.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mediator/build.gradle.kts | 1 + .../kotlin/no/nav/dagpenger/mottak/Config.kt | 1 - .../behov/journalpost/JournalpostApiClient.kt | 29 +++++++++-------- .../behov/saksbehandling/arena/Arena.kt | 31 ++++++++++++------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/mediator/build.gradle.kts b/mediator/build.gradle.kts index a69f5ac1..c5d5a84e 100644 --- a/mediator/build.gradle.kts +++ b/mediator/build.gradle.kts @@ -28,6 +28,7 @@ dependencies { implementation(libs.bundles.ktor.server) implementation(libs.bundles.ktor.client) + implementation("io.ktor:ktor-client-apache5:${libs.versions.ktor.get()}") implementation("io.ktor:ktor-client-logging-jvm:${libs.versions.ktor.get()}") implementation("de.slub-dresden:urnlib:2.0.1") diff --git a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/Config.kt b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/Config.kt index bf9d76c9..f81fcbd9 100644 --- a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/Config.kt +++ b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/Config.kt @@ -35,7 +35,6 @@ internal object Config { "PDL_API_SCOPE" to "api://dev-fss.pdl.pdl-api/.default", "SKJERMING_API_SCOPE" to "api://dev-gcp.nom.skjermede-personer-pip/.default", "SKJERMING_API_URL" to "http://skjermede-personer-pip.nom/skjermet", - "UNLEASH_URL" to "https://unleash.nais.io/api/", "AZURE_OPENID_CONFIG_ISSUER" to "azureAd", "AZURE_APP_CLIENT_ID" to "azureClientId", "AZURE_OPENID_CONFIG_JWKS_URI" to "http://localhost:4443", diff --git a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalpostApiClient.kt b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalpostApiClient.kt index ef2fd8ca..526a6181 100644 --- a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalpostApiClient.kt +++ b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/journalpost/JournalpostApiClient.kt @@ -4,7 +4,7 @@ import com.natpryce.konfig.Key import com.natpryce.konfig.stringType import io.ktor.client.HttpClient import io.ktor.client.engine.HttpClientEngine -import io.ktor.client.engine.cio.CIO +import io.ktor.client.engine.apache5.Apache5 import io.ktor.client.plugins.ClientRequestException import io.ktor.client.plugins.DefaultRequest import io.ktor.client.plugins.HttpTimeout @@ -25,7 +25,7 @@ import no.nav.dagpenger.mottak.behov.JsonMapper import kotlin.time.Duration.Companion.minutes internal class JournalpostApiClient( - engine: HttpClientEngine = CIO.create(), + engine: HttpClientEngine = Apache5.create(), private val tokenProvider: () -> String, private val basePath: String = "rest/journalpostapi/v1", ) : JournalpostDokarkiv { @@ -58,16 +58,17 @@ internal class JournalpostApiClient( ) { val feilmelding = "Kunne ikke oppdatere journalpost" try { - client.put { - url { encodedPath = "$basePath/journalpost/$journalpostId" } - header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") - header(HttpHeaders.XRequestId, eksternReferanseId) - header(HttpHeaders.ContentType, "application/json") - header(HttpHeaders.Accept, "application/json") - setBody(journalpost) - }.also { - logger.info { "Oppdaterte journalpost $journalpostId" } - } + client + .put { + url { encodedPath = "$basePath/journalpost/$journalpostId" } + header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") + header(HttpHeaders.XRequestId, eksternReferanseId) + header(HttpHeaders.ContentType, "application/json") + header(HttpHeaders.Accept, "application/json") + setBody(journalpost) + }.also { + logger.info { "Oppdaterte journalpost $journalpostId" } + } } catch (e: ClientRequestException) { logger.error(e) { feilmelding } throw JournalpostFeil.JournalpostException( @@ -105,5 +106,7 @@ internal class JournalpostApiClient( } } - private data class FerdigstillJournalpostRequest(val journalfoerendeEnhet: String = "9999") + private data class FerdigstillJournalpostRequest( + val journalfoerendeEnhet: String = "9999", + ) } diff --git a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/saksbehandling/arena/Arena.kt b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/saksbehandling/arena/Arena.kt index adde4526..adf5757b 100644 --- a/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/saksbehandling/arena/Arena.kt +++ b/mediator/src/main/kotlin/no/nav/dagpenger/mottak/behov/saksbehandling/arena/Arena.kt @@ -3,7 +3,7 @@ package no.nav.dagpenger.mottak.behov.saksbehandling.arena import com.natpryce.konfig.Configuration import io.ktor.client.HttpClient import io.ktor.client.call.body -import io.ktor.client.engine.cio.CIO +import io.ktor.client.engine.apache5.Apache5 import io.ktor.client.plugins.ClientRequestException import io.ktor.client.plugins.HttpTimeout import io.ktor.client.plugins.contentnegotiation.ContentNegotiation @@ -34,7 +34,9 @@ internal interface ArenaOppslag { ): OpprettVedtakOppgaveResponse? } -internal class ArenaApiClient(config: Configuration) : ArenaOppslag { +internal class ArenaApiClient( + config: Configuration, +) : ArenaOppslag { companion object { private val logger = KotlinLogging.logger {} private val sikkerlogg = KotlinLogging.logger("tjenestekall.ArenaApiClient") @@ -44,7 +46,7 @@ internal class ArenaApiClient(config: Configuration) : ArenaOppslag { private val baseUrl = "${config.dpProxyUrl()}/proxy/v1/arena" private val proxyArenaClient = - HttpClient(engine = CIO.create { requestTimeout = Long.MAX_VALUE }) { + HttpClient(engine = Apache5.create { connectionRequestTimeout = Long.MAX_VALUE }) { expectSuccess = true install(HttpTimeout) { connectTimeoutMillis = Duration.ofSeconds(30).toMillis() @@ -66,13 +68,14 @@ internal class ArenaApiClient(config: Configuration) : ArenaOppslag { parametereBody: OpprettArenaOppgaveParametere, ): OpprettVedtakOppgaveResponse? = try { - proxyArenaClient.request(url) { - header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") - header(HttpHeaders.ContentType, "application/json") - header(HttpHeaders.Accept, "application/json") - method = HttpMethod.Post - setBody(parametereBody) - }.body() + proxyArenaClient + .request(url) { + header(HttpHeaders.Authorization, "Bearer ${tokenProvider.invoke()}") + header(HttpHeaders.ContentType, "application/json") + header(HttpHeaders.Accept, "application/json") + method = HttpMethod.Post + setBody(parametereBody) + }.body() } catch (e: ClientRequestException) { val message = e.response.bodyAsText() if (e.response.status.value == 400) { @@ -89,9 +92,13 @@ internal class ArenaApiClient(config: Configuration) : ArenaOppslag { ): OpprettVedtakOppgaveResponse? = opprettArenaOppgave("$baseUrl/sak/henvendelse", parametere) } -private data class AktivSakRequest(val fnr: String) +private data class AktivSakRequest( + val fnr: String, +) -private data class AktivSakResponse(val harAktivSak: Boolean) +private data class AktivSakResponse( + val harAktivSak: Boolean, +) internal data class OpprettArenaOppgaveParametere( val naturligIdent: String,