1
1
package no.nav.hjelpemidler
2
2
3
3
import com.fasterxml.jackson.annotation.JsonFormat
4
+ import com.fasterxml.jackson.dataformat.xml.XmlMapper
4
5
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
5
6
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
6
7
import com.fasterxml.jackson.module.kotlin.readValue
@@ -26,7 +27,8 @@ import java.util.UUID
26
27
27
28
private val logg = KotlinLogging .logger {}
28
29
private val sikkerlogg = KotlinLogging .logger(" tjenestekall" )
29
- private val mapper = jacksonObjectMapper().registerModule(JavaTimeModule ())
30
+ private val mapperJson = jacksonObjectMapper().registerModule(JavaTimeModule ())
31
+ private val mapperXml = XmlMapper ().registerModule(JavaTimeModule ())
30
32
31
33
// Unngå "inappropriate blocking method call" for objectmapper.writeValueAsString
32
34
@Suppress(" BlockingMethodInNonBlockingContext" )
@@ -68,36 +70,45 @@ fun main() {
68
70
return @post
69
71
}
70
72
71
- val rawJson: String = call.receiveText()
73
+ var incomingFormatType = " JSON"
74
+ if (call.request.header(" Content-Type" ).toString().contains(" application/xml" )) {
75
+ incomingFormatType = " XML"
76
+ }
77
+
78
+ val requestBody: String = call.receiveText()
72
79
SensuMetrics ().meldingFraOebs()
73
80
if (Configuration .application[" APP_PROFILE" ] != " prod" ) {
74
- sikkerlogg.info(" Received JSON push request from OEBS: $rawJson " )
81
+ sikkerlogg.info(" Received $incomingFormatType push request from OEBS: $requestBody " )
75
82
}
76
83
77
84
// Check for valid json request
78
85
val ordrelinje: OrdrelinjeOebs ?
79
86
try {
80
- ordrelinje = mapper.readValue(rawJson)
87
+ if (incomingFormatType == " XML" ){
88
+ ordrelinje = mapperXml.readValue(requestBody)
89
+ } else {
90
+ ordrelinje = mapperJson.readValue(requestBody)
91
+ }
81
92
if (Configuration .application[" APP_PROFILE" ] != " prod" ) {
82
93
sikkerlogg.info(
83
- " Parsing incoming json request successful: ${
84
- mapper .writeValueAsString(
94
+ " Parsing incoming $incomingFormatType request successful: ${
95
+ mapperJson .writeValueAsString(
85
96
ordrelinje
86
97
)
87
98
} "
88
99
)
89
100
}
90
101
SensuMetrics ().oebsParsingOk()
91
102
} catch (e: Exception ) {
92
- // Deal with invalid json in request
93
- sikkerlogg.info(" Parsing incoming json request failed with exception (responding 4xx): $e " )
103
+ // Deal with invalid json/xml in request
104
+ sikkerlogg.info(" Parsing incoming $incomingFormatType request failed with exception (responding 4xx): $e " )
94
105
if (Configuration .application[" APP_PROFILE" ] != " prod" ) {
95
106
sikkerlogg.info(
96
- " JSON in failed parsing: ${mapper .writeValueAsString(rawJson )} "
107
+ " $incomingFormatType in failed parsing: ${mapperJson .writeValueAsString(requestBody )} "
97
108
)
98
109
}
99
110
SensuMetrics ().oebsParsingFeilet()
100
- call.respond(HttpStatusCode .BadRequest , " bad request: json not valid" )
111
+ call.respond(HttpStatusCode .BadRequest , " bad request: $incomingFormatType not valid" )
101
112
return @post
102
113
}
103
114
@@ -136,15 +147,15 @@ fun main() {
136
147
data = ordrelinje.toOrdrelinje()
137
148
)
138
149
139
- // Publish the received json to our rapid
150
+ // Publish the received json/xml to our rapid as json
140
151
try {
141
152
if (Configuration .application[" APP_PROFILE" ] != " prod" ) {
142
153
logg.info { " Publiserer ordrelinje til rapid i miljø ${Configuration .application[" APP_PROFILE" ]} " }
143
- rapidApp!! .publish(ordrelinje.fnrBruker, mapper .writeValueAsString(melding))
154
+ rapidApp!! .publish(ordrelinje.fnrBruker, mapperJson .writeValueAsString(melding))
144
155
SensuMetrics ().meldingTilRapidSuksess()
145
156
} else {
146
157
ordrelinje.fnrBruker = " MASKERT"
147
- sikkerlogg.info { " Ordrelinje mottatt i prod som ikkje blir sendt til rapid: ${mapper .writeValueAsString(ordrelinje)} " }
158
+ sikkerlogg.info { " Ordrelinje mottatt i prod som ikkje blir sendt til rapid: ${mapperJson .writeValueAsString(ordrelinje)} " }
148
159
}
149
160
} catch (e: Exception ) {
150
161
if (Configuration .application[" APP_PROFILE" ] != " prod" ) {
0 commit comments