From 47994f2f0d21a74d39e628e5653aa652aa64ea8c Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Mon, 21 Jan 2013 09:11:30 +0100
Subject: [PATCH] OO-449: with the whole caching refactoring, make the HTTP
 session partially serializable without (too much) exceptions

---
 .../id/context/BusinessControlFactory.java    |  5 +++-
 .../org/olat/core/id/context/StateEntry.java  |  4 ++-
 .../org/olat/core/id/context/StateMapped.java |  3 +-
 .../org/olat/core/id/context/StateSite.java   |  3 +-
 .../java/org/olat/core/util/UserSession.java  | 29 ++++++++++++++-----
 ...HomePageContextEntryControllerCreator.java |  3 +-
 6 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/olat/core/id/context/BusinessControlFactory.java b/src/main/java/org/olat/core/id/context/BusinessControlFactory.java
index d999293c283..af968d42050 100644
--- a/src/main/java/org/olat/core/id/context/BusinessControlFactory.java
+++ b/src/main/java/org/olat/core/id/context/BusinessControlFactory.java
@@ -28,6 +28,7 @@
 */
 package org.olat.core.id.context;
 
+import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.text.DateFormat;
@@ -523,7 +524,9 @@ public class BusinessControlFactory {
 	}
 }	
 
-class MyContextEntry implements ContextEntry {
+class MyContextEntry implements ContextEntry, Serializable {
+
+	private static final long serialVersionUID = 949522581806327579L;
 	private final OLATResourceable olatResourceable;
 
 	//fxdiff BAKS-7 Resume function
diff --git a/src/main/java/org/olat/core/id/context/StateEntry.java b/src/main/java/org/olat/core/id/context/StateEntry.java
index 8e48e4f2ced..d1d1cfc58c8 100644
--- a/src/main/java/org/olat/core/id/context/StateEntry.java
+++ b/src/main/java/org/olat/core/id/context/StateEntry.java
@@ -19,6 +19,8 @@
  */
 package org.olat.core.id.context;
 
+import java.io.Serializable;
+
 /**
  * 
  * <h3>Description:</h3>
@@ -27,7 +29,7 @@ package org.olat.core.id.context;
  * Initial Date:  18 jan. 2011 <br>
  * @author srosse, stephane.rosse@frentix.com, www.frentix.com
  */
-public interface StateEntry extends Cloneable {
+public interface StateEntry extends Cloneable, Serializable {
 	
 	public StateEntry clone();
 }
diff --git a/src/main/java/org/olat/core/id/context/StateMapped.java b/src/main/java/org/olat/core/id/context/StateMapped.java
index 8cf89b15818..92fcf92f5a6 100644
--- a/src/main/java/org/olat/core/id/context/StateMapped.java
+++ b/src/main/java/org/olat/core/id/context/StateMapped.java
@@ -31,7 +31,8 @@ import java.util.Map;
  * @author srosse, stephane.rosse@frentix.com, www.frentix.com
  */
 public class StateMapped implements StateEntry{
-	
+
+	private static final long serialVersionUID = -164313132644246934L;
 	private Map<String,String> delegate = new HashMap<String,String>();
 	
 	public StateMapped() {
diff --git a/src/main/java/org/olat/core/id/context/StateSite.java b/src/main/java/org/olat/core/id/context/StateSite.java
index dbf8e1bbe96..649b9625a8a 100644
--- a/src/main/java/org/olat/core/id/context/StateSite.java
+++ b/src/main/java/org/olat/core/id/context/StateSite.java
@@ -29,8 +29,9 @@ import org.olat.core.gui.control.navigation.SiteInstance;
  * Initial Date:  18 jan. 2011 <br>
  * @author srosse, stephane.rosse@frentix.com, www.frentix.com
  */
-public class StateSite implements StateEntry{
+public class StateSite implements StateEntry {
 	
+	private static final long serialVersionUID = 963711681410259249L;
 	private transient SiteInstance site;
 	
 	public StateSite() {
diff --git a/src/main/java/org/olat/core/util/UserSession.java b/src/main/java/org/olat/core/util/UserSession.java
index f6f9ca25ca7..659ffb87f76 100644
--- a/src/main/java/org/olat/core/util/UserSession.java
+++ b/src/main/java/org/olat/core/util/UserSession.java
@@ -74,7 +74,7 @@ public class UserSession implements HttpSessionBindingListener, GenericEventList
 	private static final long serialVersionUID = 1975177605776990868L;
 
 	// the environment (identity, locale, ..) of the identity
-	private transient IdentityEnvironment identityEnvironment;
+	private IdentityEnvironment identityEnvironment;
 	private transient SessionInfo sessionInfo;
 	private transient Map<String,Object> store;
 	/**
@@ -82,10 +82,10 @@ public class UserSession implements HttpSessionBindingListener, GenericEventList
 	 */
 	private transient Map<String,Object> nonClearedStore = new HashMap<String,Object>();
 	private boolean authenticated = false;
-	private transient  Preferences guiPreferences;
-	private transient  EventBus singleUserSystemBus;
+	private transient Preferences guiPreferences;
+	private transient EventBus singleUserSystemBus;
 	private List<String> chats;
-	private transient Stack<HistoryPoint> history = new Stack<HistoryPoint>();
+	private Stack<HistoryPoint> history = new Stack<HistoryPoint>();
 
 	public UserSession() {
 		init();
@@ -98,6 +98,15 @@ public class UserSession implements HttpSessionBindingListener, GenericEventList
 		authenticated = false;
 		sessionInfo = null;
 	}
+	
+	private Object readResolve() {
+		store = new HashMap<String,Object>(4);
+		nonClearedStore = new HashMap<String,Object>();
+		singleUserSystemBus = CoordinatorManager.getInstance().getCoordinator().createSingleUserInstance();
+		sessionInfo = null;
+		System.out.println("readResolve 2");
+		return this;
+	}
 
 	/**
 	 * @return true if is authenticated
@@ -127,9 +136,15 @@ public class UserSession implements HttpSessionBindingListener, GenericEventList
 	 * @return entry
 	 */
 	public Object getEntry(String key) {
-		if (key == null) return null;
-		if (store.get(key) != null) return store.get(key);
-		if (nonClearedStore.get(key) != null) return nonClearedStore.get(key);
+		if (key == null) {
+			return null;
+		}
+		if (store.get(key) != null) {
+			return store.get(key);
+		}
+		if (nonClearedStore.get(key) != null) {
+			return nonClearedStore.get(key);
+		}
 		else return null;
 	}
 
diff --git a/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java b/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java
index 1859daae45a..0e8468736fe 100644
--- a/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java
+++ b/src/main/java/org/olat/user/HomePageContextEntryControllerCreator.java
@@ -105,7 +105,8 @@ public class HomePageContextEntryControllerCreator extends DefaultContextEntryCo
 		return identity != null;
 	}
 	
-	private class HomePageStateEntry implements StateEntry {
+	public static class HomePageStateEntry implements StateEntry {
+		private static final long serialVersionUID = -8949620136046652588L;
 		private final Identity identity;
 		
 		public HomePageStateEntry(Identity identity) {
-- 
GitLab