diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java index 74ddff2f3..30a40bc85 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; @@ -50,17 +49,17 @@ public class FreemarkerConfigurationImpl extends Configuration { private static final Log log = LogFactory .getLog(FreemarkerConfigurationImpl.class); - private final ThreadLocal currentRequest = new ThreadLocal<>(); - private final Map rbiMap = Collections - .synchronizedMap(new WeakHashMap()); + private final ThreadLocal currentRequestHash = new ThreadLocal<>(); + private final Map rbiMap = Collections + .synchronizedMap(new HashMap()); protected void setRequestInfo(HttpServletRequest req) { - currentRequest.set(req); - rbiMap.put(req, new RequestBasedInformation(req, this)); + currentRequestHash.set(req.hashCode()); + rbiMap.put(req.hashCode(), new RequestBasedInformation(req, this)); } private RequestBasedInformation getRequestInfo() { - return rbiMap.get(currentRequest.get()); + return rbiMap.get(currentRequestHash.get()); } @Override @@ -103,7 +102,7 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public Locale getLocale() { - return currentRequest.get().getLocale(); + return getRequestInfo().getReq().getLocale(); } private String[] joinNames(Set nameSet, String[] nameArray) { @@ -235,16 +234,23 @@ public class FreemarkerConfigurationImpl extends Configuration { * custom attribute, and the locale. In the future, it could be more. */ private static class RequestBasedInformation { + private final HttpServletRequest req; private final Configuration c; private final Map customAttributes = new HashMap<>(); private final Map sharedVariables = new HashMap<>(); public RequestBasedInformation(HttpServletRequest req, Configuration c) { + this.req = req; this.c = c; + setSharedVariables(req); setCustomAttributes(req); } + public HttpServletRequest getReq() { + return req; + } + public Map getCustomAttributes() { return customAttributes; }