Skip to content

Commit

Permalink
IS-2720: Ktor 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe committed Dec 10, 2024
1 parent 74fb7db commit 26552fe
Show file tree
Hide file tree
Showing 31 changed files with 1,112 additions and 1,093 deletions.
59 changes: 29 additions & 30 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
import org.apache.tools.ant.taskdefs.condition.Os

group = "no.nav.syfo"
version = "1.0.0"

val arenaDialogNotatVersion = "1.e1999cf"
val base64containerVersion = "1.5ac2176"
val dialogmeldingVersion = "1.5d21db9"
val fellesformat2Version = "1.0329dd1"
val flywayVersion = "9.22.3"
val flywayVersion = "10.17.2"
val hikariVersion = "5.1.0"
val ibmMqVersion = "9.3.4.1"
val jacksonVersion = "2.16.0"
val jacksonVersion = "2.18.0"
val javaTimeAdapterVersion = "1.1.3"
val kafkaVersion = "3.6.1"
val kafkaVersion = "3.9.0"
val kithApprecVersion = "2019.07.30-04-23-2a0d1388209441ec05d2e92a821eed4f796a3ae2"
val kithHodemeldingVersion = "2019.07.30-12-26-5c924ef4f04022bbb850aaf299eb8e4464c1ca6a"
val kluentVersion = "1.73"
val ktorVersion = "2.3.8"
val logbackVersion = "1.4.14"
val ktorVersion = "3.0.2"
val logbackVersion = "1.5.12"
val logstashEncoderVersion = "7.4"
val javaxAnnotationApiVersion = "1.3.2"
val javaxActivationVersion = "1.2.0"
val jaxbApiVersion = "2.4.0-b180830.0359"
val jaxbRuntimeVersion = "2.4.0-b180830.0438"
val jaxwsApiVersion = "2.3.1"
val jaxwsToolsVersion = "2.3.7"
val junitJupiterVersion = "5.8.2"
val micrometerRegistry = "1.12.2"
val mockkVersion = "1.13.8"
val nimbusJoseJwt = "9.37.2"
val junitJupiterVersion = "5.11.3"
val micrometerRegistry = "1.12.8"
val mockkVersion = "1.13.12"
val nimbusJoseJwt = "9.47"
val pdfboxVersion = "2.0.24"
val postgresEmbedded = if (Os.isFamily(Os.FAMILY_MAC)) "1.0.0" else "0.13.4"
val postgresVersion = "42.7.2"
val scala = "2.13.9"
val postgresEmbedded = "2.0.7"
val postgresVersion = "42.7.4"
val spek = "2.0.19"
val commonsCompressVersion = "1.27.0"
val commonsCompressVersion = "1.27.1"

plugins {
java
kotlin("jvm") version "2.0.10"
id("com.gradleup.shadow") version "8.3.0"
id("org.jlleitschuh.gradle.ktlint") version "11.4.2"
kotlin("jvm") version "2.0.21"
id("com.gradleup.shadow") version "8.3.2"
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
}

repositories {
Expand Down Expand Up @@ -86,7 +83,7 @@ dependencies {

implementation("org.postgresql:postgresql:$postgresVersion")
implementation("com.zaxxer:HikariCP:$hikariVersion")
implementation("org.flywaydb:flyway-core:$flywayVersion")
implementation("org.flywaydb:flyway-database-postgresql:$flywayVersion")

implementation("javax.xml.ws:jaxws-api:$jaxwsApiVersion")
implementation("javax.annotation:javax.annotation-api:$javaxAnnotationApiVersion")
Expand All @@ -108,13 +105,19 @@ dependencies {
implementation("org.apache.zookeeper:zookeeper") {
because("org.apache.kafka:kafka_2.13:$kafkaVersion -> https://www.cve.org/CVERecord?id=CVE-2023-44981")
version {
require("3.8.3")
require("3.9.3")
}
}
implementation("org.bitbucket.b_c:jose4j") {
because("org.apache.kafka:kafka_2.13:$kafkaVersion -> https://github.com/advisories/GHSA-6qvw-249j-h44c")
version {
require("0.9.6")
}
}
implementation("org.scala-lang:scala-library") {
because("org.apache.kafka:kafka_2.13:$kafkaVersion -> https://www.cve.org/CVERecord?id=CVE-2022-36944")
implementation("org.apache.commons:commons-compress") {
because("org.apache.commons:commons-compress:1.22 -> https://www.cve.org/CVERecord?id=CVE-2012-2098")
version {
require(scala)
require(commonsCompressVersion)
}
}
}
Expand All @@ -127,12 +130,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("com.opentable.components:otj-pg-embedded:$postgresEmbedded")
constraints {
testImplementation("org.apache.commons:commons-compress:$commonsCompressVersion") {
because("overrides vulnerable dependency from com.opentable.components:otj-pg-embedded")
}
}
testImplementation("io.zonky.test:embedded-postgres:$postgresEmbedded")
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spek") {
exclude(group = "org.jetbrains.kotlin")
Expand All @@ -154,14 +152,15 @@ tasks {
}

shadowJar {
mergeServiceFiles()
archiveBaseName.set("app")
archiveClassifier.set("")
archiveVersion.set("")
}

test {
useJUnitPlatform {
includeEngines("spek2", "junit-vintage")
includeEngines("spek2", "junit-jupiter")
}
testLogging {
showStandardStreams = true
Expand Down
57 changes: 31 additions & 26 deletions src/main/kotlin/no/nav/syfo/Bootstrap.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.nav.syfo

import com.typesafe.config.ConfigFactory
import io.ktor.server.application.*
import io.ktor.server.config.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import no.nav.syfo.application.*
Expand All @@ -26,6 +28,8 @@ import javax.jms.Session

val logger: Logger = LoggerFactory.getLogger("no.nav.syfo.padm2")

const val applicationPort = 8080

fun main() {
logger.info("Padm2 starting with java version: " + Runtime.version())
val env = Environment()
Expand All @@ -42,40 +46,41 @@ fun main() {
env = env,
)

val applicationEngineEnvironment = applicationEngineEnvironment {
val applicationEnvironment = applicationEnvironment {
log = logger
connector {
port = env.applicationPort
}
module {
config = HoconApplicationConfig(ConfigFactory.load())
}
val server = embeddedServer(
Netty,
environment = applicationEnvironment,
configure = {
connector {
port = applicationPort
}
connectionGroupSize = 8
workerGroupSize = 8
callGroupSize = 16
},

module = {
apiModule(
applicationState = applicationState,
database = database,
environment = env,
wellKnownInternalAzureAD = wellKnownInternalAzureAD,
)
monitor.subscribe(ApplicationStarted) {
applicationState.ready = true
logger.info("Application is ready, running Java VM ${Runtime.version()}")

launchListeners(
applicationState = applicationState,
env = env,
database = database,
)
}
}
}

applicationEngineEnvironment.monitor.subscribe(ApplicationStarted) {
applicationState.ready = true
logger.info("Application is ready")

launchListeners(
applicationState = applicationState,
env = env,
database = database,
)
}

val server = embeddedServer(
factory = Netty,
environment = applicationEngineEnvironment,
) {
connectionGroupSize = 8
workerGroupSize = 8
callGroupSize = 16
}
)

Runtime.getRuntime().addShutdownHook(
Thread {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/syfo/util/PipelineUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package no.nav.syfo.util
import com.auth0.jwt.JWT
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.util.pipeline.*
import io.ktor.server.routing.*

const val JWT_CLAIM_AZP = "azp"

fun PipelineContext<out Unit, ApplicationCall>.getBearerHeader(): String? {
fun RoutingContext.getBearerHeader(): String? {
return this.call.getBearerHeader()
}

fun PipelineContext<out Unit, ApplicationCall>.getCallId(): String {
fun RoutingContext.getCallId(): String {
return this.call.getCallId()
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/ApprecMapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import no.nav.syfo.util.get
import no.nav.syfo.util.getFileAsStringISO88591
import no.nav.syfo.util.safeUnmarshal
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.junit.jupiter.api.Test

internal class ApprecMapperTest {
@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/CreateArenaDialogNotatTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import no.nav.syfo.model.findDialogmeldingType
import no.nav.syfo.model.toDialogmelding
import no.nav.syfo.util.*
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger

internal class CreateArenaDialogNotatTest {
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/DialogmeldingMapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import no.nav.syfo.model.*
import no.nav.syfo.util.*
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.junit.jupiter.api.Test

internal class DialogmeldingMapperTest {

Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/no/nav/syfo/ExternalMockEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ fun wellKnownInternalAzureAD(): WellKnown {
}

fun ExternalMockEnvironment.startExternalMocks() {
this.externalApplicationMockMap.start()
this.externalApplicationMockMap.forEach { it.value.start() }
this.database.start()
}

fun ExternalMockEnvironment.stopExternalMocks() {
this.externalApplicationMockMap.stop()
this.externalApplicationMockMap.forEach { it.value.stop() }
this.database.stop()
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/ExtractFromFellesFormatTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import no.nav.syfo.util.get
import no.nav.syfo.util.getFileAsString
import no.nav.syfo.util.safeUnmarshal
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.junit.jupiter.api.Test
import java.time.LocalDateTime

class ExtractFromFellesFormatTest {
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/FromKiropraktorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import no.nav.syfo.model.findDialogmeldingType
import no.nav.syfo.model.toDialogmelding
import no.nav.syfo.util.*
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.junit.jupiter.api.Test
import java.math.BigInteger
import java.time.LocalDateTime
import java.util.*
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/no/nav/syfo/PdfModelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package no.nav.syfo
import no.nav.syfo.model.*
import no.nav.syfo.util.objectMapper
import org.amshove.kluent.shouldBeEqualTo
import org.junit.jupiter.api.Test
import java.time.LocalDateTime
import java.util.UUID
import org.junit.Test

internal class PdfModelTest {

Expand Down
Loading

0 comments on commit 26552fe

Please sign in to comment.