Skip to content

Commit

Permalink
Serializable json on endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Sep 14, 2023
1 parent ac0f73e commit 017019c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion payload-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ val githubPassword: String by project

plugins {
kotlin("jvm") version "1.9.0"
kotlin("plugin.serialization") version "1.9.0"
application
id("io.ktor.plugin") version "2.3.4"
}
Expand All @@ -31,13 +32,15 @@ tasks {
dependencies {
implementation("io.ktor:ktor-server-core:2.3.4")
implementation("io.ktor:ktor-server-netty:2.3.4")
implementation("io.ktor:ktor-server-call-logging-jvm:2.3.4")
implementation("io.ktor:ktor-server-content-negotiation:2.3.4")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.4")
implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.0", )
implementation("org.glassfish.jaxb:jaxb-runtime:4.0.3")
implementation("org.bouncycastle:bcprov-jdk18on:1.76")
implementation("org.bouncycastle:bcpkix-jdk18on:1.76")
implementation("ch.qos.logback:logback-classic:1.4.11")
implementation("io.micrometer:micrometer-registry-prometheus:1.11.3")
implementation("io.ktor:ktor-server-call-logging-jvm:2.3.4")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
Expand Down
9 changes: 8 additions & 1 deletion payload-processor/src/main/kotlin/no/nav/emottak/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package no.nav.emottak;

import io.ktor.http.content.PartData
import io.ktor.http.content.forEachPart
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.Application
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.plugins.callloging.CallLogging
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.request.path
import io.ktor.server.request.receiveMultipart
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.get
import io.ktor.server.routing.post
Expand All @@ -34,6 +37,10 @@ private fun Application.serverSetup() {
level = Level.INFO
filter { call -> call.request.path().startsWith("/") }
}

install(ContentNegotiation) {
json()
}
routing {
registerHealthEndpoints()

Expand Down Expand Up @@ -63,7 +70,7 @@ private fun Application.serverSetup() {
processedPayload = testByteArray
)
val prosessertMelding = processor.processOutgoing(melding)
call.respondText(prosessertMelding.toString())
call.respond(prosessertMelding)
}

post("/payload") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package no.nav.emottak.melding.model

import kotlinx.serialization.Serializable

@Serializable
data class Melding(
val header: Header,
val originalPayload: ByteArray,
val processedPayload: ByteArray
)

@Serializable
data class Header(
val messageId: String,
val conversationId: String,
Expand All @@ -16,6 +20,7 @@ data class Header(
val action: String
)

@Serializable
data class Part(
val krypteringSertifikat: ByteArray,
val signeringSertifikat: ByteArray,
Expand Down

0 comments on commit 017019c

Please sign in to comment.