diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-16 13:29:48 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-16 13:29:48 +0200 |
commit | ef9a86858a5e05b4dd9bff3992c477f49b0b20f2 (patch) | |
tree | b5ca028b9df5d1b2edd0ea3979cd82138475e1d5 /src/main/java/at | |
parent | 5ee2fdd40732aa8eca29e89b14fa5238385868e8 (diff) | |
download | moa-zs-ef9a86858a5e05b4dd9bff3992c477f49b0b20f2.tar.gz moa-zs-ef9a86858a5e05b4dd9bff3992c477f49b0b20f2.tar.bz2 moa-zs-ef9a86858a5e05b4dd9bff3992c477f49b0b20f2.zip |
Add Getter for Repository + Refactor Marshalling
- mv MyMarshaller Marshaller
- Remove jaxbcontext bean
- Move Marshaller config to MarshallerConfig class
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/Marshaller.java (renamed from src/main/java/at/gv/egiz/moazs/MyMarshaller.java) | 2 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/MarshallerConfig.java (renamed from src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java) | 14 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/RedisConfig.java | 17 | ||||
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/RedisRepository.java | 20 |
4 files changed, 25 insertions, 28 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/MyMarshaller.java b/src/main/java/at/gv/egiz/moazs/Marshaller.java index ea14a0f..c126f03 100644 --- a/src/main/java/at/gv/egiz/moazs/MyMarshaller.java +++ b/src/main/java/at/gv/egiz/moazs/Marshaller.java @@ -15,7 +15,7 @@ import java.io.StringWriter; * Source: https://stackoverflow.com/questions/44676532/how-to-use-spring-to-marshal-and-unmarshal-xml */ @Component -public class MyMarshaller { +public class Marshaller { @Autowired private Jaxb2Marshaller marshaller; diff --git a/src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java b/src/main/java/at/gv/egiz/moazs/MarshallerConfig.java index 9842d49..9106dd0 100644 --- a/src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java +++ b/src/main/java/at/gv/egiz/moazs/MarshallerConfig.java @@ -2,21 +2,29 @@ package at.gv.egiz.moazs; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; +import java.util.HashMap; @Configuration -public class MyMarshallerConfig { +public class MarshallerConfig { @Bean - public JAXBContext jaxbcontext() throws JAXBException { - return JAXBContext.newInstance( + public Jaxb2Marshaller jaxb2Marshaller() { + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + marshaller.setClassesToBeBound( at.gv.e_government.reference.namespace.zustellung.mzs.persondata_.ObjectFactory.class, at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory.class, at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory.class, at.gv.e_government.reference.namespace.persondata.phase2._20181206_.ObjectFactory.class); + marshaller.setMarshallerProperties(new HashMap<String, Object>() {{ + put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true); + }}); + + return marshaller; } } diff --git a/src/main/java/at/gv/egiz/moazs/RedisConfig.java b/src/main/java/at/gv/egiz/moazs/RedisConfig.java index 3487eb5..758fbfd 100644 --- a/src/main/java/at/gv/egiz/moazs/RedisConfig.java +++ b/src/main/java/at/gv/egiz/moazs/RedisConfig.java @@ -44,21 +44,4 @@ public class RedisConfig { return template; } - @Bean - public Jaxb2Marshaller jaxb2Marshaller() { - Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); - marshaller.setClassesToBeBound( - at.gv.e_government.reference.namespace.zustellung.mzs.persondata_.ObjectFactory.class, - at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory.class, - at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory.class, - at.gv.e_government.reference.namespace.persondata.phase2._20181206_.ObjectFactory.class); //"alternatively" setContextPath(<jaxb.context>), - - marshaller.setMarshallerProperties(new HashMap<String, Object>() {{ - put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true); - }}); - - return marshaller; - } - - } diff --git a/src/main/java/at/gv/egiz/moazs/RedisRepository.java b/src/main/java/at/gv/egiz/moazs/RedisRepository.java index dfc68ea..db49b23 100644 --- a/src/main/java/at/gv/egiz/moazs/RedisRepository.java +++ b/src/main/java/at/gv/egiz/moazs/RedisRepository.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Repository; import javax.annotation.PostConstruct; import javax.xml.bind.JAXBElement; +import java.util.Optional; @Repository public class RedisRepository { @@ -22,14 +23,14 @@ public class RedisRepository { private final RedisTemplate<String, Object> redisTemplate; - private final MyMarshaller marshaller; + private final Marshaller marshaller; private HashOperations<String, String, String> hashOperations; private final ObjectFactory factory = new ObjectFactory(); @Autowired - public RedisRepository(RedisTemplate<String, Object> redisTemplate, MyMarshaller marshaller){ + public RedisRepository(RedisTemplate<String, Object> redisTemplate, Marshaller marshaller){ this.redisTemplate = redisTemplate; this.marshaller = marshaller; } @@ -43,15 +44,20 @@ public class RedisRepository { var hashKey = request.getMetaData().getAppDeliveryID(); var serializedRequest = marshaller.marshallXml(factory.createDeliveryRequest(request)); - logger.info("Adding DeliveryRequest to repository: AppDeliveryId = {}, request = {}", hashKey, serializedRequest); + logger.info("Save DeliveryRequest with AppDeliveryId = {}", hashKey); hashOperations.put(KEY, hashKey, serializedRequest); + } - var drs = (String) hashOperations.get(KEY, hashKey); - var requestFromRedis = (JAXBElement<DeliveryRequestType>) marshaller.unmarshallXml(new StringInputStream(drs)); - String appDeliveryID = requestFromRedis.getValue().getMetaData().getAppDeliveryID(); - logger.info("here's what i got out of redis: appDeliveryId = {}, request = {}", appDeliveryID, drs); + public Optional<DeliveryRequestType> getDeliveryRequest(String appDeliveryID) { + var serializedRequest = (String) hashOperations.get(KEY, appDeliveryID); + if (serializedRequest == null) { + return Optional.empty(); + } + var stream = new StringInputStream(serializedRequest); + var request = (JAXBElement<DeliveryRequestType>) marshaller.unmarshallXml(stream); + return Optional.of(request.getValue()); } } |