Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS-1748: Fix concurrency conflict #225

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/no/nav/syfo/client/ArenaDialogNotat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fun sendArenaDialogNotat(
loggingMeta: LoggingMeta
) {
mqSender.sendArena(
payload = arenaDialogNotatMarshaller.toString(arenaDialogNotat)
payload = getArenaDialogNotatMarshaller().toString(arenaDialogNotat)
)
logger.info("Message is sent to arena {}", fields(loggingMeta))
}
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/syfo/client/SmgcpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import no.nav.helse.msgHead.XMLSender
import no.nav.syfo.client.azuread.v2.AzureAdV2Client
import no.nav.syfo.logger
import no.nav.syfo.util.bearerHeader
import no.nav.syfo.util.senderMarshaller
import no.nav.syfo.util.getSenderMarshaller
import java.io.ByteArrayOutputStream
import java.io.IOException

Expand Down Expand Up @@ -50,7 +50,7 @@ class SmgcpClient(

private fun convertSenderToBase64(sender: XMLSender): ByteArray =
ByteArrayOutputStream().use {
senderMarshaller.marshal(sender, it)
getSenderMarshaller().marshal(sender, it)
it
}.toByteArray()
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nav/syfo/services/ApprecService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import no.nav.syfo.apprec.ApprecStatus
import no.nav.syfo.apprec.createApprec
import no.nav.syfo.logger
import no.nav.syfo.metrics.APPREC_COUNTER
import no.nav.syfo.util.apprecMarshaller
import no.nav.syfo.util.get
import no.nav.syfo.util.getApprecMarshaller
import no.nav.syfo.util.toString

fun sendReceipt(
Expand All @@ -27,7 +27,7 @@ fun sendReceipt(
val apprec = createApprec(fellesformat, apprecStatus)
apprec.get<XMLAppRec>().error.addAll(apprecErrors)
mqSender.sendReceipt(
payload = apprecMarshaller.toString(apprec)
payload = getApprecMarshaller().toString(apprec)
)
APPREC_COUNTER.increment()
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/kotlin/no/nav/syfo/util/JaxBUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@ val fellesformatJaxBContext: JAXBContext = JAXBContext.newInstance(
XMLAppRec::class.java,
)

val senderMarshaller: Marshaller = JAXBContext.newInstance(XMLSender::class.java).createMarshaller()
fun getSenderMarshaller(): Marshaller = JAXBContext.newInstance(XMLSender::class.java).createMarshaller()
.apply { setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1") }

val apprecJaxBContext: JAXBContext = JAXBContext.newInstance(XMLEIFellesformat::class.java, XMLAppRec::class.java)
val apprecMarshaller: Marshaller = apprecJaxBContext.createMarshaller()
fun getApprecMarshaller(): Marshaller = apprecJaxBContext.createMarshaller()

val arenaDialogNotatJaxBContext: JAXBContext = JAXBContext.newInstance(ArenaDialogNotat::class.java)
val arenaDialogNotatMarshaller: Marshaller = arenaDialogNotatJaxBContext.createMarshaller()

private val fellesformatUnmarshaller: Unmarshaller = fellesformatJaxBContext.createUnmarshaller().apply {
setAdapter(LocalDateTimeXmlAdapter::class.java, XMLDateTimeAdapter())
setAdapter(LocalDateXmlAdapter::class.java, XMLDateAdapter())
}
fun getArenaDialogNotatMarshaller(): Marshaller = arenaDialogNotatJaxBContext.createMarshaller()

fun Marshaller.toString(input: Any): String = StringWriter().use {
marshal(input, it)
Expand All @@ -59,5 +54,11 @@ fun safeUnmarshal(inputMessageText: String): XMLEIFellesformat {
spf.newSAXParser().xmlReader,
InputSource(StringReader(inputMessageText)),
)
return fellesformatUnmarshaller.unmarshal(xmlSource) as XMLEIFellesformat
return getFellesformatUnmarshaller().unmarshal(xmlSource) as XMLEIFellesformat
}

// Unmarshaller is not thread safe - do not "optimize"
private fun getFellesformatUnmarshaller(): Unmarshaller = fellesformatJaxBContext.createUnmarshaller().apply {
setAdapter(LocalDateTimeXmlAdapter::class.java, XMLDateTimeAdapter())
setAdapter(LocalDateXmlAdapter::class.java, XMLDateAdapter())
}