Skip to content

Commit d94aab2

Browse files
authored
Oppdatere til ktor 2.3.x (#127)
* Oppdatere til ktor 2.3.x - Fjernet ktor-moshi og erstattet med Jackson contentnegotation -- La på @JsonProperty for å mappe json felt til enum for jackson også. - Sanity test av at jackson gir samme svar som moshi * Legg på statusmeldinger om deploy i slack
1 parent df2624c commit d94aab2

File tree

11 files changed

+294
-58
lines changed

11 files changed

+294
-58
lines changed

.github/workflows/dp-inntekt-api-deploy.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
needs: [build]
4646
if: github.ref == 'refs/heads/master'
4747
runs-on: ubuntu-latest
48+
environment: dev-fss
4849
steps:
4950
- uses: actions/checkout@v3
5051
- uses: nais/deploy/actions/deploy@v1
@@ -59,6 +60,7 @@ jobs:
5960
needs: [deploy-dev]
6061
if: github.ref == 'refs/heads/master'
6162
runs-on: ubuntu-latest
63+
environment: prod-fss
6264
steps:
6365
- uses: actions/checkout@v3
6466

buildSrc/src/main/kotlin/Constants.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Cucumber {
2424
object Dagpenger {
2525

2626
object Biblioteker {
27-
const val version = "2022.12.07-09.10.209e073691b5"
27+
const val version = "2023.01.16-10.20.e8450fdff15a"
2828
const val stsKlient = "com.github.navikt.dp-biblioteker:sts-klient:$version"
2929
const val ktorUtils = "com.github.navikt.dp-biblioteker:ktor-utils:$version"
3030

@@ -44,9 +44,9 @@ object Dagpenger {
4444
}
4545
}
4646

47-
const val Grunnbeløp = "com.github.navikt:dp-grunnbelop:2022.05.20-09.36.a361a7eb490e"
48-
const val Streams = "com.github.navikt:dagpenger-streams:2022.11.23-13.03.cdf78b1c92f9"
49-
const val Events = "com.github.navikt:dagpenger-events:2022.11.23-12.45.96e145a02427"
47+
const val Grunnbeløp = "com.github.navikt:dp-grunnbelop:2023.04.11-15.15.dd33088904de"
48+
const val Streams = "com.github.navikt:dagpenger-streams:2023.04.26-10.04.3a1a87ddfe2c"
49+
const val Events = "com.github.navikt:dagpenger-events:2023.04.26-10.02.4df92899b455"
5050
}
5151

5252
object Database {
@@ -69,14 +69,14 @@ object GradleWrapper {
6969
}
7070

7171
object Jackson {
72-
const val version = "2.14.1"
72+
const val version = "2.15.0"
7373
const val core = "com.fasterxml.jackson.core:jackson-core:$version"
7474
const val kotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:$version"
7575
const val jsr310 = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$version"
7676
}
7777

7878
object Junit5 {
79-
const val version = "5.9.1"
79+
const val version = "5.9.2"
8080
const val api = "org.junit.jupiter:junit-jupiter-api:$version"
8181
const val params = "org.junit.jupiter:junit-jupiter-params:$version"
8282
const val engine = "org.junit.jupiter:junit-jupiter-engine:$version"
@@ -118,7 +118,7 @@ object Konfig {
118118
}
119119

120120
object Kotlin {
121-
const val version = "1.7.21"
121+
const val version = "1.8.10"
122122
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"
123123

124124
object Coroutines {
@@ -133,7 +133,7 @@ object Kotlin {
133133
}
134134

135135
object KoTest {
136-
const val version = "5.5.4"
136+
const val version = "5.5.5"
137137

138138
// for kotest framework
139139
const val runner = "io.kotest:kotest-runner-junit5-jvm:$version"
@@ -153,7 +153,7 @@ object Kotlinx {
153153
}
154154

155155
object Ktor {
156-
const val version = "1.6.6"
156+
const val version = "1.6.8"
157157
const val server = "io.ktor:ktor-server:$version"
158158
const val serverNetty = "io.ktor:ktor-server-netty:$version"
159159
const val auth = "io.ktor:ktor-auth:$version"
@@ -165,7 +165,7 @@ object Ktor {
165165
}
166166

167167
object Ktor2 {
168-
const val version = "2.1.3"
168+
const val version = "2.3.0"
169169
object Client {
170170
fun library(name: String) = "io.ktor:ktor-client-$name:$version"
171171
}
@@ -175,7 +175,7 @@ object Ktor2 {
175175
}
176176

177177
object Log4j2 {
178-
const val version = "2.19.0"
178+
const val version = "2.20.0"
179179
const val api = "org.apache.logging.log4j:log4j-api:$version"
180180
const val core = "org.apache.logging.log4j:log4j-core:$version"
181181
const val slf4j = "org.apache.logging.log4j:log4j-slf4j2-impl:$version"
@@ -194,18 +194,18 @@ object Micrometer {
194194
}
195195

196196
object Moshi {
197-
const val version = "1.9.2"
197+
const val version = "1.14.0"
198198
const val moshi = "com.squareup.moshi:moshi:$version"
199199
const val moshiKotlin = "com.squareup.moshi:moshi-kotlin:$version"
200200
const val moshiAdapters = "com.squareup.moshi:moshi-adapters:$version"
201201

202202
// waiting for https://github.com/rharter/ktor-moshi/pull/8
203-
const val moshiKtor = "com.github.cs125-illinois:ktor-moshi:2b13e43520"
203+
const val moshiKtor = "com.github.cs125-illinois:ktor-moshi:2022.9.0"
204204
fun library(name: String) = "com.squareup.moshi:moshi-$name:$version"
205205
}
206206

207207
object Mockk {
208-
const val version = "1.13.2"
208+
const val version = "1.13.4"
209209
const val mockk = "io.mockk:mockk:$version"
210210
}
211211

@@ -228,7 +228,7 @@ object Prometheus {
228228
}
229229

230230
const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:2022.03.25-09.17.0628678a7192"
231-
const val RapidAndRiversKtor2 = "com.github.navikt:rapids-and-rivers:2022111011111668075098.65e508dcde8b"
231+
const val RapidAndRiversKtor2 = "com.github.navikt:rapids-and-rivers:2023042611061682500003.f24c0756e00a"
232232

233233
object Slf4j {
234234
const val version = "1.7.25"
@@ -270,7 +270,7 @@ object Wiremock {
270270
}
271271

272272
object Graphql {
273-
const val version = "6.3.3"
273+
const val version = "5.2.0"
274274
const val graphql = "com.expediagroup.graphql"
275275
val client = library("client")
276276
fun library(name: String) = "com.expediagroup:graphql-kotlin-$name:$version"

dp-inntekt-api/build.gradle.kts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
33

4+
45
plugins {
56
application
67
id(Shadow.shadow) version Shadow.version
7-
id(Graphql.graphql) version Graphql.version
8+
id("com.expediagroup.graphql") version "6.4.0"
89
id("de.undercouch.download") version "5.3.0"
910
}
1011

@@ -25,6 +26,7 @@ application {
2526
}
2627

2728
val grpcVersion = "1.38.1"
29+
val expediaGraphqlVersion = "6.4.0"
2830

2931
dependencies {
3032
implementation(project(":dp-inntekt-grpc"))
@@ -39,24 +41,28 @@ dependencies {
3941
implementation(Ktor2.Server.library("call-logging"))
4042
implementation(Ktor2.Server.library("default-headers"))
4143
implementation(Ktor2.Server.library("content-negotiation"))
42-
implementation(Ktor2.Server.library("metrics-micrometer"))
44+
implementation("io.ktor:ktor-serialization-jackson:${Ktor2.version}")
4345
implementation(Ktor2.Server.library("metrics-micrometer"))
4446

4547
implementation(Micrometer.prometheusRegistry)
4648

47-
implementation(Graphql.client)
48-
implementation(Graphql.library("ktor-client"))
49-
implementation(Graphql.library("client-jackson"))
49+
implementation("com.expediagroup:graphql-kotlin-client:$expediaGraphqlVersion")
50+
implementation("com.expediagroup:graphql-kotlin-ktor-client:$expediaGraphqlVersion")
51+
implementation("com.expediagroup:graphql-kotlin-client-jackson:$expediaGraphqlVersion")
52+
5053
implementation(Ktor2.Client.library("logging-jvm"))
5154
implementation(Ktor2.Client.library("apache"))
5255

56+
implementation(Jackson.core)
57+
implementation(Jackson.kotlin)
58+
implementation(Jackson.jsr310)
59+
5360
// unleash
54-
implementation("no.finn.unleash:unleash-client-java:3.3.1")
61+
implementation("io.getunleash:unleash-client-java:8.0.0")
5562

5663
implementation(Moshi.moshi)
5764
implementation(Moshi.moshiAdapters)
5865
implementation(Moshi.moshiKotlin)
59-
implementation("com.github.cs125-illinois:ktor-moshi:2b13e43520")
6066

6167
implementation(Dagpenger.Streams)
6268
implementation(Kafka.clients)
@@ -82,6 +88,7 @@ dependencies {
8288
implementation(Database.Postgres)
8389
implementation(Database.Kotlinquery)
8490
implementation(Konfig.konfig)
91+
implementation("org.slf4j:slf4j-api:2.0.7")
8592
implementation(Database.VaultJdbc) {
8693
exclude(module = "slf4j-simple")
8794
exclude(module = "slf4j-api")
@@ -110,6 +117,7 @@ dependencies {
110117
testImplementation(Junit5.params)
111118
testRuntimeOnly(Junit5.engine)
112119
testImplementation(Wiremock.standalone)
120+
testImplementation(KoTest.library("assertions-json"))
113121
testImplementation(KoTest.assertions)
114122
testImplementation(KoTest.runner)
115123
testImplementation(KoTest.property)

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/InntektApi.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package no.nav.dagpenger.inntekt
22

33
import com.natpryce.konfig.Configuration
4-
import com.ryanharter.ktor.moshi.moshi
54
import com.squareup.moshi.JsonDataException
65
import com.squareup.moshi.JsonEncodingException
76
import de.huxhorn.sulky.ulid.ULID
7+
import io.ktor.http.ContentType
88
import io.ktor.http.HttpHeaders
99
import io.ktor.http.HttpStatusCode
1010
import io.ktor.http.isSuccess
11+
import io.ktor.serialization.jackson.JacksonConverter
1112
import io.ktor.server.application.Application
1213
import io.ktor.server.application.install
1314
import io.ktor.server.auth.Authentication
1415
import io.ktor.server.auth.authenticate
1516
import io.ktor.server.auth.jwt.jwt
1617
import io.ktor.server.metrics.micrometer.MicrometerMetrics
18+
import io.ktor.server.plugins.BadRequestException
1719
import io.ktor.server.plugins.callid.CallId
1820
import io.ktor.server.plugins.callid.callIdMdc
1921
import io.ktor.server.plugins.callloging.CallLogging
@@ -39,6 +41,7 @@ import no.nav.dagpenger.inntekt.inntektskomponenten.v1.InntektskomponentenHttpCl
3941
import no.nav.dagpenger.inntekt.oppslag.PersonNotFoundException
4042
import no.nav.dagpenger.inntekt.oppslag.PersonOppslag
4143
import no.nav.dagpenger.inntekt.oppslag.enhetsregister.EnhetsregisterClient
44+
import no.nav.dagpenger.inntekt.serder.jacksonObjectMapper
4245
import no.nav.dagpenger.inntekt.v1.enhetsregisteret
4346
import no.nav.dagpenger.inntekt.v1.inntekt
4447
import no.nav.dagpenger.inntekt.v1.opptjeningsperiodeApi
@@ -153,6 +156,15 @@ internal fun Application.inntektApi(
153156
)
154157
call.respond(HttpStatusCode.BadRequest, error)
155158
}
159+
exception<BadRequestException> { call, cause ->
160+
LOGGER.warn("Request does not match expected json", cause)
161+
val error = Problem(
162+
type = URI("urn:dp:error:inntekt:parameter"),
163+
title = "Parameteret er ikke gyldig, mangler obligatorisk felt: '${cause.message}'",
164+
status = 400,
165+
)
166+
call.respond(HttpStatusCode.BadRequest, error)
167+
}
156168
exception<IllegalArgumentException> { call, cause ->
157169
LOGGER.warn("Request does not match expected json", cause)
158170
val error = Problem(
@@ -205,7 +217,7 @@ internal fun Application.inntektApi(
205217
}
206218

207219
install(ContentNegotiation) {
208-
moshi(moshiInstance)
220+
register(ContentType.Application.Json, JacksonConverter(jacksonObjectMapper))
209221
}
210222

211223
routing {

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/InntektApiConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.natpryce.konfig.Key
88
import com.natpryce.konfig.intType
99
import com.natpryce.konfig.overriding
1010
import com.natpryce.konfig.stringType
11-
import no.finn.unleash.util.UnleashConfig
11+
import io.getunleash.util.UnleashConfig
1212
import no.nav.dagpenger.streams.Credential
1313
import no.nav.dagpenger.streams.KafkaAivenCredentials
1414
import java.net.InetAddress

0 commit comments

Comments
 (0)