NIHVIVO-4017 Always get the ApplicationBean from the DAO.

Don't store the ApplicationBean in the request or in the context, and
don't look for it there.
This commit is contained in:
j2blake 2012-11-15 11:43:19 -05:00
parent 6b743f8b36
commit 24a5784110
9 changed files with 15 additions and 52 deletions

View file

@ -49,15 +49,6 @@ public class ApplicationBean {
private String copyrightAnchor;
private String themeDir;
public static ApplicationBean getAppBean(ServletContext sc){
if( sc != null ){
Object obj = sc.getAttribute("applicationBean");
if( obj != null )
return (ApplicationBean)obj;
}
return new ApplicationBean();
}
public String toString() {
String output = "Application Bean Contents:\n";
output += " initialized from DB: [" + initialized + "]\n";

View file

@ -33,9 +33,6 @@ import edu.cornell.mannlib.vitro.webapp.web.ContentType;
public class OntologyController extends VitroHttpServlet{
private static final Log log = LogFactory.getLog(OntologyController.class.getName());
private String default_jsp = Controllers.BASIC_JSP;
private ApplicationBean appBean;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
doGet(request, response);
@ -242,7 +239,7 @@ public class OntologyController extends VitroHttpServlet{
throws IOException, ServletException {
VitroRequest vreq = new VitroRequest(req);
ApplicationBean appBean = ApplicationBean.getAppBean(getServletContext());
ApplicationBean appBean = vreq.getAppBean();
//set title before we do the highlighting so we don't get markup in it.
req.setAttribute("title","not found");

View file

@ -283,12 +283,8 @@ public class VitroRequest extends HttpServletRequestWrapper {
}
public ApplicationBean getAppBean(){
//return (ApplicationBean) getAttribute("appBean");
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
}
public void setAppBean(ApplicationBean ab){
setAttribute("appBean",ab);
}
@SuppressWarnings("unchecked")
@Override

View file

@ -7,7 +7,6 @@ import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -31,7 +30,7 @@ public class StartupStatusController extends FreemarkerHttpServlet {
body.put("title", "Startup Status");
body.put("status", StartupStatus.getBean(getServletContext()));
body.put("contextPath", getContextPath());
body.put("applicationName", getApplicationName());
body.put("applicationName", getApplicationName(vreq));
return new TemplateResponseValues("startupStatus-display.ftl", body);
}
@ -45,11 +44,10 @@ public class StartupStatusController extends FreemarkerHttpServlet {
}
}
private Object getApplicationName() {
private Object getApplicationName(VitroRequest vreq) {
String name = "";
try {
ApplicationBean app = ApplicationBean.getAppBean(getServletContext());
name = app.getApplicationName();
name = vreq.getAppBean().getApplicationName();
} catch (Exception e) {
// deal with problems below
}

View file

@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import freemarker.cache.WebappTemplateLoader;
import freemarker.template.Configuration;
@ -69,34 +70,34 @@ public class StartupStatusDisplayFilter implements Filter {
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException,
ServletException {
HttpServletResponse hResp = (HttpServletResponse) resp;
HttpServletResponse hresp = (HttpServletResponse) resp;
HttpServletRequest hreq = (HttpServletRequest) req;
try {
Map<String, Object> bodyMap = new HashMap<String, Object>();
bodyMap.put("status", ss);
bodyMap.put("showLink", !isFatal());
bodyMap.put("contextPath", getContextPath());
bodyMap.put("applicationName", getApplicationName());
bodyMap.put("applicationName", getApplicationName(hreq));
HttpServletRequest httpreq = (HttpServletRequest) req;
String url = "";
String path = httpreq.getRequestURI();
String path = hreq.getRequestURI();
if( path != null ){
url = path;
}
String query = httpreq.getQueryString();
String query = hreq.getQueryString();
if( !StringUtils.isEmpty( query )){
url = url + "?" + query;
}
bodyMap.put("url", url );
hResp.setContentType("text/html;charset=UTF-8");
hResp.setStatus(SC_INTERNAL_SERVER_ERROR);
hresp.setContentType("text/html;charset=UTF-8");
hresp.setStatus(SC_INTERNAL_SERVER_ERROR);
Template tpl = loadFreemarkerTemplate();
tpl.process(bodyMap, hResp.getWriter());
tpl.process(bodyMap, hresp.getWriter());
} catch (TemplateException e) {
throw new ServletException("Problem with Freemarker Template", e);
}
@ -111,10 +112,10 @@ public class StartupStatusDisplayFilter implements Filter {
}
}
private Object getApplicationName() {
private Object getApplicationName(HttpServletRequest hreq) {
String name = "";
try {
ApplicationBean app = ApplicationBean.getAppBean(ctx);
ApplicationBean app = new VitroRequest(hreq).getAppBean();
name = app.getApplicationName();
} catch (Exception e) {
// deal with problems below

View file

@ -38,7 +38,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -82,19 +81,10 @@ public class VitroRequestPrep implements Filter {
};
private ServletContext _context;
private ApplicationBean _appbean;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
_context = filterConfig.getServletContext();
Object o = _context.getAttribute("applicationBean");
if (o instanceof ApplicationBean) {
_appbean = (ApplicationBean) o;
} else {
_appbean = new ApplicationBean();
}
log.debug("VitroRequestPrep: AppBean theme " + _appbean.getThemeDir());
}
@Override
@ -132,9 +122,6 @@ public class VitroRequestPrep implements Filter {
VitroRequest vreq = new VitroRequest(req);
//-- setup appBean --//
vreq.setAppBean(_appbean);
//-- setup DAO factory --//
WebappDaoFactory wdf = getWebappDaoFactory(vreq);
//TODO: get accept-language from request and set as preferred languages