diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-16 11:49:56 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-04-16 12:43:06 +0200 |
commit | 5ee2fdd40732aa8eca29e89b14fa5238385868e8 (patch) | |
tree | 40d62cdb51232d07375048cd0850e0e806407b6c /src/main/java/at/gv/egiz/moazs/RedisRepository.java | |
parent | c8271e5684e26b57880de7f1b8a3b0195ad6f68e (diff) | |
download | moa-zs-5ee2fdd40732aa8eca29e89b14fa5238385868e8.tar.gz moa-zs-5ee2fdd40732aa8eca29e89b14fa5238385868e8.tar.bz2 moa-zs-5ee2fdd40732aa8eca29e89b14fa5238385868e8.zip |
Store incoming delivery request on redis server
- Connect to Redis server and implement RedisRepository
- Add redis dependencies (spring-boot-starter, jedis, apache commons
io). Latter dependencies are apparently needed and not included in
the sprint-boot-starter; See
https://github.com/spring-projects/spring-boot/issues/5718 and
https://www.concretepage.com/questions/599
- Connect DeliveryRequestHandler to RedisRepository
- Rewrote Marshalling: replace JaxbContext with spring-oxm
JaxbMarshaller
- Catch and log all exceptions in App2MZSService; Former: certain
exceptions would go unnoticed, e.g. ConnectionRefused
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/RedisRepository.java')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/RedisRepository.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/RedisRepository.java b/src/main/java/at/gv/egiz/moazs/RedisRepository.java new file mode 100644 index 0000000..dfc68ea --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/RedisRepository.java @@ -0,0 +1,57 @@ +package at.gv.egiz.moazs; + +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.DeliveryRequestType; +import at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory; +import org.apache.tools.ant.filters.StringInputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import javax.annotation.PostConstruct; +import javax.xml.bind.JAXBElement; + +@Repository +public class RedisRepository { + + private static final Logger logger = LoggerFactory.getLogger(RedisRepository.class); + + private static final String KEY = "MZS_DELIVERY_REQUEST"; + + private final RedisTemplate<String, Object> redisTemplate; + + private final MyMarshaller marshaller; + + private HashOperations<String, String, String> hashOperations; + + private final ObjectFactory factory = new ObjectFactory(); + + @Autowired + public RedisRepository(RedisTemplate<String, Object> redisTemplate, MyMarshaller marshaller){ + this.redisTemplate = redisTemplate; + this.marshaller = marshaller; + } + + @PostConstruct + private void init(){ + hashOperations = redisTemplate.opsForHash(); + } + + public void add(DeliveryRequestType request) { + var hashKey = request.getMetaData().getAppDeliveryID(); + var serializedRequest = marshaller.marshallXml(factory.createDeliveryRequest(request)); + + logger.info("Adding DeliveryRequest to repository: AppDeliveryId = {}, request = {}", hashKey, serializedRequest); + 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); + + + } + +} |