diff --git a/src/main/java/org/redisson/tomcat/RedissonSession.java b/src/main/java/org/redisson/tomcat/RedissonSession.java index 8381164..c7b2b23 100644 --- a/src/main/java/org/redisson/tomcat/RedissonSession.java +++ b/src/main/java/org/redisson/tomcat/RedissonSession.java @@ -25,6 +25,8 @@ import java.util.concurrent.TimeUnit; import org.apache.catalina.session.StandardSession; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; import org.redisson.api.RMap; import org.redisson.api.RTopic; import org.redisson.tomcat.RedissonSessionManager.ReadMode; @@ -48,6 +50,8 @@ public class RedissonSession extends StandardSession { public static final Set ATTRS = new HashSet(Arrays.asList(IS_NEW_ATTR, IS_VALID_ATTR, THIS_ACCESSED_TIME_ATTR, MAX_INACTIVE_INTERVAL_ATTR, LAST_ACCESSED_TIME_ATTR, CREATION_TIME_ATTR)); + private final Log log = LogFactory.getLog(RedissonSession.class); + private final RedissonSessionManager redissonManager; private final Map attrs; private RMap map; @@ -218,27 +222,32 @@ protected void removeAttributeInternal(String name, boolean notify) { } public void save() { - Map newMap = new HashMap(); - newMap.put(CREATION_TIME_ATTR, creationTime); - newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime); - newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime); - newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); - newMap.put(IS_VALID_ATTR, isValid); - newMap.put(IS_NEW_ATTR, isNew); - - if (attrs != null) { - for (Entry entry : attrs.entrySet()) { - newMap.put(entry.getKey(), entry.getValue()); + try { + Map newMap = new HashMap(); + newMap.put(CREATION_TIME_ATTR, creationTime); + newMap.put(LAST_ACCESSED_TIME_ATTR, lastAccessedTime); + newMap.put(THIS_ACCESSED_TIME_ATTR, thisAccessedTime); + newMap.put(MAX_INACTIVE_INTERVAL_ATTR, maxInactiveInterval); + newMap.put(IS_VALID_ATTR, isValid); + newMap.put(IS_NEW_ATTR, isNew); + + if (attrs != null) { + for (Entry entry : attrs.entrySet()) { + newMap.put(entry.getKey(), entry.getValue()); + } } - } - - map.putAll(newMap); - if (readMode == ReadMode.MEMORY) { - topic.publish(createPutAllMessage(newMap)); - } - - if (maxInactiveInterval >= 0) { - map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); + + map.putAll(newMap); + if (readMode == ReadMode.MEMORY) { + topic.publish(createPutAllMessage(newMap)); + } + + if (maxInactiveInterval >= 0) { + map.expire(getMaxInactiveInterval(), TimeUnit.SECONDS); + } + } catch (Exception e) { + log.error("Failed to save to session", e); + e.printStackTrace(); } }