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/RedisConfig.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/RedisConfig.java')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/RedisConfig.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/RedisConfig.java b/src/main/java/at/gv/egiz/moazs/RedisConfig.java new file mode 100644 index 0000000..3487eb5 --- /dev/null +++ b/src/main/java/at/gv/egiz/moazs/RedisConfig.java @@ -0,0 +1,64 @@ +package at.gv.egiz.moazs; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericToStringSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +import java.util.HashMap; + +@Configuration +@PropertySource("classpath:application.properties") +public class RedisConfig { + + @Value("${spring.redis.host}") + private String host; + + @Value("${spring.redis.port}") + private int port; + + @Bean + JedisConnectionFactory jedisConnectionFactory() { + RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); + config.setHostName(host); + config.setPort(port); + return new JedisConnectionFactory(config); + } + + @Bean + public StringRedisSerializer stringRedisSerializer() { + return new StringRedisSerializer(); + } + + @Bean + public RedisTemplate<String, Object> redisTemplate() { + final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); + template.setConnectionFactory(jedisConnectionFactory()); + template.setDefaultSerializer(stringRedisSerializer()); + 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; + } + + +} |