aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-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.java17
-rw-r--r--src/main/java/at/gv/egiz/moazs/RedisRepository.java20
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());
}
}