Skip to content

Commit

Permalink
ContentNegotiaton og json serializable SignatureDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Oct 23, 2023
1 parent c831733 commit d81825d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cpa-repo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dependencies {
api(project(":felles"))
implementation(libs.ktor.server.core)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.labai.jsr305x.annotations)
implementation(libs.jakarta.xml.bind.api)
implementation(libs.jaxb.runtime)
Expand Down
8 changes: 7 additions & 1 deletion cpa-repo/src/main/kotlin/no/nav/emottak/cpa/App.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package no.nav.emottak.cpa

import io.ktor.http.*
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.BadRequestException
import io.ktor.server.plugins.NotFoundException
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.request.*
import io.ktor.server.response.respond
import io.ktor.server.routing.*
Expand All @@ -26,6 +29,9 @@ fun main() {
}

fun Application.myApplicationModule() {
install(ContentNegotiation) {
json()
}
routing {
get("/cpa/{$CPA_ID}") {
val cpaId = call.parameters[CPA_ID] ?: throw BadRequestException("Mangler $CPA_ID")
Expand All @@ -39,7 +45,7 @@ fun Application.myApplicationModule() {
call.respond(HttpStatusCode.OK,ValidationResult(true))
}

get("/cpa/{$CPA_ID}/party/{$PARTY_TYPE}/{$PARTY_ID}encryption/certificate") {
get("/cpa/{$CPA_ID}/party/{$PARTY_TYPE}/{$PARTY_ID}/encryption/certificate") {
val cpaId = call.parameters[CPA_ID] ?: throw BadRequestException("Mangler $CPA_ID")
val partyType = call.parameters[PARTY_TYPE] ?: throw BadRequestException("Mangler $PARTY_TYPE")
val partyId = call.parameters[PARTY_ID] ?: throw BadRequestException("Mangler $PARTY_ID")
Expand Down
2 changes: 2 additions & 0 deletions ebms-provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies {
implementation(libs.ktor.server.netty)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.labai.jsr305x.annotations)
implementation(libs.jakarta.xml.bind.api)
implementation(libs.jaxb.runtime)
Expand Down
10 changes: 8 additions & 2 deletions ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package no.nav.emottak.ebms

import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.contentnegotiation.ContentNegotiation
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down Expand Up @@ -42,6 +44,10 @@ fun PartData.payload() : ByteArray {


fun Application.myApplicationModule() {
install(ContentNegotiation) {
json()
}

routing {
get("/") {
call.application.environment.log.info("TESTEST")
Expand All @@ -60,7 +66,7 @@ fun Application.myApplicationModule() {

val ebMSDocument: EbMSDocument
try {
ebMSDocument = call.recieveEbmsDokument()
ebMSDocument = call.receiveEbmsDokument()
} catch (ex: MimeValidationException) {
call.respond(HttpStatusCode.InternalServerError, ex.asParseAsSoapFault())
return@post
Expand Down Expand Up @@ -99,7 +105,7 @@ fun Application.myApplicationModule() {
}

@Throws(MimeValidationException::class)
suspend fun ApplicationCall.recieveEbmsDokument() : EbMSDocument {
suspend fun ApplicationCall.receiveEbmsDokument() : EbMSDocument {

return when (val contentType = this.request.contentType().withoutParameters()) {
ContentType.parse("multipart/related") -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package no.nav.emottak.melding.model

import kotlinx.serialization.Serializable

@Serializable
data class SignatureDetails(
val certificate: ByteArray,
val signatureAlgorithm: String,
val hashFunction: String
)


@Serializable
data class SignatureDetailsRequest(
val cpaId: String,
val partyType: String,
Expand Down

0 comments on commit d81825d

Please sign in to comment.