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:
parent
6b743f8b36
commit
24a5784110
9 changed files with 15 additions and 52 deletions
|
@ -49,15 +49,6 @@ public class ApplicationBean {
|
||||||
private String copyrightAnchor;
|
private String copyrightAnchor;
|
||||||
private String themeDir;
|
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() {
|
public String toString() {
|
||||||
String output = "Application Bean Contents:\n";
|
String output = "Application Bean Contents:\n";
|
||||||
output += " initialized from DB: [" + initialized + "]\n";
|
output += " initialized from DB: [" + initialized + "]\n";
|
||||||
|
|
|
@ -33,9 +33,6 @@ import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||||
public class OntologyController extends VitroHttpServlet{
|
public class OntologyController extends VitroHttpServlet{
|
||||||
private static final Log log = LogFactory.getLog(OntologyController.class.getName());
|
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)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException,IOException{
|
throws ServletException,IOException{
|
||||||
doGet(request, response);
|
doGet(request, response);
|
||||||
|
@ -242,7 +239,7 @@ public class OntologyController extends VitroHttpServlet{
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
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.
|
//set title before we do the highlighting so we don't get markup in it.
|
||||||
req.setAttribute("title","not found");
|
req.setAttribute("title","not found");
|
||||||
|
|
|
@ -283,12 +283,8 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationBean getAppBean(){
|
public ApplicationBean getAppBean(){
|
||||||
//return (ApplicationBean) getAttribute("appBean");
|
|
||||||
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
|
return getWebappDaoFactory().getApplicationDao().getApplicationBean();
|
||||||
}
|
}
|
||||||
public void setAppBean(ApplicationBean ab){
|
|
||||||
setAttribute("appBean",ab);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
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.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
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("title", "Startup Status");
|
||||||
body.put("status", StartupStatus.getBean(getServletContext()));
|
body.put("status", StartupStatus.getBean(getServletContext()));
|
||||||
body.put("contextPath", getContextPath());
|
body.put("contextPath", getContextPath());
|
||||||
body.put("applicationName", getApplicationName());
|
body.put("applicationName", getApplicationName(vreq));
|
||||||
|
|
||||||
return new TemplateResponseValues("startupStatus-display.ftl", body);
|
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 = "";
|
String name = "";
|
||||||
try {
|
try {
|
||||||
ApplicationBean app = ApplicationBean.getAppBean(getServletContext());
|
name = vreq.getAppBean().getApplicationName();
|
||||||
name = app.getApplicationName();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// deal with problems below
|
// deal with problems below
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
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 edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
import freemarker.cache.WebappTemplateLoader;
|
import freemarker.cache.WebappTemplateLoader;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
|
@ -69,34 +70,34 @@ public class StartupStatusDisplayFilter implements Filter {
|
||||||
|
|
||||||
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException,
|
private void displayStartupStatus(ServletRequest req, ServletResponse resp) throws IOException,
|
||||||
ServletException {
|
ServletException {
|
||||||
HttpServletResponse hResp = (HttpServletResponse) resp;
|
HttpServletResponse hresp = (HttpServletResponse) resp;
|
||||||
|
HttpServletRequest hreq = (HttpServletRequest) req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, Object> bodyMap = new HashMap<String, Object>();
|
Map<String, Object> bodyMap = new HashMap<String, Object>();
|
||||||
bodyMap.put("status", ss);
|
bodyMap.put("status", ss);
|
||||||
bodyMap.put("showLink", !isFatal());
|
bodyMap.put("showLink", !isFatal());
|
||||||
bodyMap.put("contextPath", getContextPath());
|
bodyMap.put("contextPath", getContextPath());
|
||||||
bodyMap.put("applicationName", getApplicationName());
|
bodyMap.put("applicationName", getApplicationName(hreq));
|
||||||
|
|
||||||
HttpServletRequest httpreq = (HttpServletRequest) req;
|
|
||||||
String url = "";
|
String url = "";
|
||||||
|
|
||||||
String path = httpreq.getRequestURI();
|
String path = hreq.getRequestURI();
|
||||||
if( path != null ){
|
if( path != null ){
|
||||||
url = path;
|
url = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
String query = httpreq.getQueryString();
|
String query = hreq.getQueryString();
|
||||||
if( !StringUtils.isEmpty( query )){
|
if( !StringUtils.isEmpty( query )){
|
||||||
url = url + "?" + query;
|
url = url + "?" + query;
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyMap.put("url", url );
|
bodyMap.put("url", url );
|
||||||
|
|
||||||
hResp.setContentType("text/html;charset=UTF-8");
|
hresp.setContentType("text/html;charset=UTF-8");
|
||||||
hResp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
hresp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||||
Template tpl = loadFreemarkerTemplate();
|
Template tpl = loadFreemarkerTemplate();
|
||||||
tpl.process(bodyMap, hResp.getWriter());
|
tpl.process(bodyMap, hresp.getWriter());
|
||||||
} catch (TemplateException e) {
|
} catch (TemplateException e) {
|
||||||
throw new ServletException("Problem with Freemarker Template", 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 = "";
|
String name = "";
|
||||||
try {
|
try {
|
||||||
ApplicationBean app = ApplicationBean.getAppBean(ctx);
|
ApplicationBean app = new VitroRequest(hreq).getAppBean();
|
||||||
name = app.getApplicationName();
|
name = app.getApplicationName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// deal with problems below
|
// deal with problems below
|
||||||
|
|
|
@ -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.permissions.SimplePermission;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList;
|
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.config.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
@ -82,19 +81,10 @@ public class VitroRequestPrep implements Filter {
|
||||||
};
|
};
|
||||||
|
|
||||||
private ServletContext _context;
|
private ServletContext _context;
|
||||||
private ApplicationBean _appbean;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
_context = filterConfig.getServletContext();
|
_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
|
@Override
|
||||||
|
@ -132,9 +122,6 @@ public class VitroRequestPrep implements Filter {
|
||||||
|
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
|
|
||||||
//-- setup appBean --//
|
|
||||||
vreq.setAppBean(_appbean);
|
|
||||||
|
|
||||||
//-- setup DAO factory --//
|
//-- setup DAO factory --//
|
||||||
WebappDaoFactory wdf = getWebappDaoFactory(vreq);
|
WebappDaoFactory wdf = getWebappDaoFactory(vreq);
|
||||||
//TODO: get accept-language from request and set as preferred languages
|
//TODO: get accept-language from request and set as preferred languages
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
request.setAttribute("bodyJsp", "/errorbody.jsp");
|
request.setAttribute("bodyJsp", "/errorbody.jsp");
|
||||||
request.setAttribute("title", "Error");
|
request.setAttribute("title", "Error");
|
||||||
request.setAttribute("css", "");
|
request.setAttribute("css", "");
|
||||||
request.setAttribute("appBean", appBean);
|
|
||||||
request.setAttribute("themeDir", themeDir);
|
request.setAttribute("themeDir", themeDir);
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,6 @@
|
||||||
if (request.getAttribute("css") == null){
|
if (request.getAttribute("css") == null){
|
||||||
e+="basicPage.jsp expects that request parameter 'css' be set to css to include in page.\n";
|
e+="basicPage.jsp expects that request parameter 'css' be set to css to include in page.\n";
|
||||||
}
|
}
|
||||||
if( request.getAttribute("appBean") == null){
|
|
||||||
e+="basicPage.jsp expects that request attribute 'appBean' be set.\n";
|
|
||||||
}
|
|
||||||
if( e.length() > 0 ){
|
if( e.length() > 0 ){
|
||||||
throw new JspException(e);
|
throw new JspException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,6 @@
|
||||||
if (request.getAttribute("css") == null){
|
if (request.getAttribute("css") == null){
|
||||||
e+="basicPage.jsp expects that request parameter 'css' be set to css to include in page.\n";
|
e+="basicPage.jsp expects that request parameter 'css' be set to css to include in page.\n";
|
||||||
}
|
}
|
||||||
if( request.getAttribute("appBean") == null){
|
|
||||||
e+="basicPage.jsp expects that request attribute 'appBean' be set.\n";
|
|
||||||
}
|
|
||||||
if( e.length() > 0 ){
|
if( e.length() > 0 ){
|
||||||
throw new JspException(e);
|
throw new JspException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue