From afd82390e928050402e337ed04c28a873a0bc1b1 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 19 Sep 2024 09:39:01 -0600 Subject: [PATCH] This should be rolled back --- .../core/utils/cache/redis/RedisClient.java | 37 ++++++++++++++++++- .../OrcidBeanClassLoaderAware.java | 35 ++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 orcid-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidBeanClassLoaderAware.java diff --git a/orcid-core/src/main/java/org/orcid/core/utils/cache/redis/RedisClient.java b/orcid-core/src/main/java/org/orcid/core/utils/cache/redis/RedisClient.java index 4d62057301b..af240865262 100644 --- a/orcid-core/src/main/java/org/orcid/core/utils/cache/redis/RedisClient.java +++ b/orcid-core/src/main/java/org/orcid/core/utils/cache/redis/RedisClient.java @@ -4,6 +4,10 @@ import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; import javax.annotation.PostConstruct; import javax.annotation.Resource; @@ -31,7 +35,7 @@ public class RedisClient { private final String redisPassword; private final int cacheExpiryInSecs; private final int clientTimeoutInMillis; - private JedisPool pool; + public JedisPool pool; private SetParams defaultSetParams; @Resource @@ -67,7 +71,7 @@ public RedisClient(String redisHost, int redisPort, String password, int cacheEx @PostConstruct private void init() { try { - JedisClientConfig config = DefaultJedisClientConfig.builder().connectionTimeoutMillis(this.clientTimeoutInMillis).timeoutMillis(this.clientTimeoutInMillis) + JedisClientConfig config = DefaultJedisClientConfig.builder().connectionTimeoutMillis(this.clientTimeoutInMillis) .socketTimeoutMillis(this.clientTimeoutInMillis).password(this.redisPassword).ssl(true).build(); pool = new JedisPool(new HostAndPort(this.redisHost, this.redisPort), config); defaultSetParams = new SetParams().ex(this.cacheExpiryInSecs); @@ -141,4 +145,33 @@ public boolean remove(String key) { } return true; } + + public static void main(String [] args) { + RedisClient client = new RedisClient("reg-qa-redis-001.reg-qa-redis.3zksuc.use2.cache.amazonaws.com", 6379, "aVerySimpleToken"); + client.init(); + System.out.println("Connected"); + Jedis r = client.pool.getResource(); + + Set keys = r.keys("spring:session:sessions:*"); + + for(String key : keys) { + System.out.println("----------------------------------------------"); + System.out.println(key); + String keyType = r.type(key); + System.out.println(keyType); + if("hash".equals(keyType)) { + Map myMap = r.hgetAll(key); + for(String tkey : myMap.keySet()) { + System.out.println(tkey + ": " + myMap.get(tkey)); + } + } + if("string".equals(keyType)) { + System.out.println(key + ": " + r.get("key")); + } + System.out.println("----------------------------------------------"); + } + + + + } } diff --git a/orcid-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidBeanClassLoaderAware.java b/orcid-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidBeanClassLoaderAware.java new file mode 100644 index 00000000000..4416b66085c --- /dev/null +++ b/orcid-web/src/main/java/org/orcid/frontend/spring/configuration/OrcidBeanClassLoaderAware.java @@ -0,0 +1,35 @@ +package org.orcid.frontend.spring.configuration; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.security.jackson2.SecurityJackson2Modules; + +@Configuration +public class OrcidBeanClassLoaderAware implements BeanClassLoaderAware { + private ClassLoader loader; + + @Bean + public RedisSerializer springSessionDefaultRedisSerializer() { + return new GenericJackson2JsonRedisSerializer(objectMapper()); + } + + /** + * Customized {@link ObjectMapper} to add mix-in for class that doesn't have default + * constructors + * @return the {@link ObjectMapper} to use + */ + private ObjectMapper objectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModules(SecurityJackson2Modules.getModules(this.loader)); + return mapper; + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.loader = classLoader; + } +}