From acb9da6d0fdb2eb5706868ed17abc932c2a20fda Mon Sep 17 00:00:00 2001 From: stigus Date: Tue, 16 Jan 2024 11:08:20 +0100 Subject: [PATCH 1/2] Tester bugfix for xml marshalling #deploy-tps-messaging-service --- .../service/IdentService.java | 25 +++++++++++-------- .../service/SpraakService.java | 4 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java index 460e6f249f9..093c24da889 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBException; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -17,6 +18,7 @@ import no.nav.tps.ctg.m201.domain.TpsServiceRutineType; import org.springframework.stereotype.Service; +import javax.xml.namespace.QName; import java.io.StringWriter; import java.util.HashMap; import java.util.List; @@ -50,17 +52,6 @@ public IdentService(ServicerutineConsumer servicerutineConsumer, this.objectMapper = objectMapper; } - @SneakyThrows - public static String marshallToXML(JAXBContext requestContext, TpsPersonData endringsmelding) { - - var marshaller = requestContext.createMarshaller(); - - var writer = new StringWriter(); - marshaller.marshal(endringsmelding, writer); - - return writer.toString(); - } - public List getIdenter(List identer, List miljoer, Boolean includeProd) { if (identer.size() > MAX_LIMIT) { @@ -89,6 +80,18 @@ public List getIdenter(List identer, List mil .toList(); } + @SneakyThrows + public static String marshallToXML(JAXBContext requestContext, TpsPersonData endringsmelding) { + + var marshaller = requestContext.createMarshaller(); + + var writer = new StringWriter(); + JAXBElement element = new JAXBElement<>(new QName("", "tpsPersonData"), TpsPersonData.class, endringsmelding); + marshaller.marshal(element, writer); + + return writer.toString(); + } + private boolean exists(String ident, TpsServicerutineM201Response response) { return nonNull(response.getTpsSvar()) && diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/SpraakService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/SpraakService.java index b53f2dd627d..60054cfe769 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/SpraakService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/SpraakService.java @@ -1,5 +1,7 @@ package no.nav.testnav.apps.tpsmessagingservice.service; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; import lombok.extern.slf4j.Slf4j; import ma.glasnost.orika.MapperFacade; import ma.glasnost.orika.MappingContext; @@ -12,8 +14,6 @@ import no.nav.testnav.libs.data.tpsmessagingservice.v1.SpraakDTO; import org.springframework.stereotype.Service; -import jakarta.xml.bind.JAXBContext; -import jakarta.xml.bind.JAXBException; import java.util.List; import java.util.Map; import java.util.stream.Collectors; From d50c553cc12e0c24de8de2e786648087200ec3b5 Mon Sep 17 00:00:00 2001 From: stigus Date: Tue, 16 Jan 2024 11:23:31 +0100 Subject: [PATCH 2/2] Tester bugfix for xml marshalling #deploy-tps-messaging-service --- .../service/IdentService.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java index 093c24da889..e162d75ff61 100644 --- a/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java +++ b/apps/tps-messaging-service/src/main/java/no/nav/testnav/apps/tpsmessagingservice/service/IdentService.java @@ -1,6 +1,9 @@ package no.nav.testnav.apps.tpsmessagingservice.service; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBException; @@ -41,15 +44,24 @@ public class IdentService { private final ServicerutineConsumer servicerutineConsumer; private final JAXBContext requestContext; private final TestmiljoerServiceConsumer testmiljoerServiceConsumer; - private final ObjectMapper objectMapper; + private final XmlMapper xmlMapper; public IdentService(ServicerutineConsumer servicerutineConsumer, - TestmiljoerServiceConsumer testmiljoerServiceConsumer, - ObjectMapper objectMapper) throws JAXBException { + TestmiljoerServiceConsumer testmiljoerServiceConsumer) + throws JAXBException { this.servicerutineConsumer = servicerutineConsumer; this.testmiljoerServiceConsumer = testmiljoerServiceConsumer; this.requestContext = JAXBContext.newInstance(TpsPersonData.class); - this.objectMapper = objectMapper; + this.xmlMapper = XmlMapper + .builder() + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true) + .configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true) + .enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .build(); + ; } public List getIdenter(List identer, List miljoer, Boolean includeProd) { @@ -128,7 +140,7 @@ private TpsServicerutineM201Response unmarshallFromXml(String endringsmeldingRes .build(); } else { - return objectMapper.readValue(endringsmeldingResponse, TpsServicerutineM201Response.class); + return xmlMapper.readValue(endringsmeldingResponse, TpsServicerutineM201Response.class); } }