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 617a09f6c..74ddff2f3 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 @@ -3,12 +3,14 @@ package edu.cornell.mannlib.vitro.webapp.freemarker.config; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; 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; @@ -48,15 +50,22 @@ public class FreemarkerConfigurationImpl extends Configuration { private static final Log log = LogFactory .getLog(FreemarkerConfigurationImpl.class); - private final ThreadLocal rbiRef = new ThreadLocal<>(); + private final ThreadLocal currentRequest = new ThreadLocal<>(); + private final Map rbiMap = Collections + .synchronizedMap(new WeakHashMap()); - void setRequestInfo(HttpServletRequest req) { - rbiRef.set(new RequestBasedInformation(req, this)); + protected void setRequestInfo(HttpServletRequest req) { + currentRequest.set(req); + rbiMap.put(req, new RequestBasedInformation(req, this)); + } + + private RequestBasedInformation getRequestInfo() { + return rbiMap.get(currentRequest.get()); } @Override public Object getCustomAttribute(String name) { - Map attribs = rbiRef.get().getCustomAttributes(); + Map attribs = getRequestInfo().getCustomAttributes(); if (attribs.containsKey(name)) { return attribs.get(name); } else { @@ -66,13 +75,13 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public String[] getCustomAttributeNames() { - Set rbiNames = rbiRef.get().getCustomAttributes().keySet(); + Set rbiNames = getRequestInfo().getCustomAttributes().keySet(); return joinNames(rbiNames, super.getCustomAttributeNames()); } @Override public TemplateModel getSharedVariable(String name) { - Map vars = rbiRef.get().getSharedVariables(); + Map vars = getRequestInfo().getSharedVariables(); if (vars.containsKey(name)) { return vars.get(name); } else { @@ -82,7 +91,7 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public Set getSharedVariableNames() { - Set rbiNames = rbiRef.get().getSharedVariables().keySet(); + Set rbiNames = getRequestInfo().getSharedVariables().keySet(); @SuppressWarnings("unchecked") Set superNames = super.getSharedVariableNames(); @@ -94,7 +103,7 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public Locale getLocale() { - return rbiRef.get().getReq().getLocale(); + return currentRequest.get().getLocale(); } private String[] joinNames(Set nameSet, String[] nameArray) { @@ -226,23 +235,16 @@ 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; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java index b882faba1..193cae0e5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/FileGraphSetup.java @@ -187,8 +187,7 @@ public class FileGraphSetup implements ServletContextListener { } else { baseModel.add(model); } - log.info("Attached file graph as " + type + " submodel " + p.getFileName()); - + log.debug("Attached file graph as " + type + " submodel " + p.getFileName()); } modelChanged = modelChanged | updateGraphInDB(dataset, model, type, p);