Skip to content

Commit

Permalink
Skudd i blinde. PRøver Apache5 ktor engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
geiralund committed Nov 25, 2024
1 parent a02d97f commit 226bc3c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions mediator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 0 additions & 1 deletion mediator/src/main/kotlin/no/nav/dagpenger/mottak/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -105,5 +106,7 @@ internal class JournalpostApiClient(
}
}

private data class FerdigstillJournalpostRequest(val journalfoerendeEnhet: String = "9999")
private data class FerdigstillJournalpostRequest(
val journalfoerendeEnhet: String = "9999",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 226bc3c

Please sign in to comment.