NIHVIVO-3345 test "cause" properly to eliminate extraneous bullets ("cause" might be an empty string). Show the application name in "____ detected a fatal error" instead of hardcoded VIVO. Restore the "Continue" link if only warnings are present.

This commit is contained in:
j2blake 2011-11-22 22:10:46 +00:00
parent e868d4a65f
commit d4adfa2210
4 changed files with 60 additions and 7 deletions

View file

@ -7,6 +7,7 @@ import java.util.Map;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.SeeStartupStatus;
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;
@ -29,8 +30,36 @@ public class StartupStatusController extends FreemarkerHttpServlet {
body.put("title", "Startup Status");
body.put("status", StartupStatus.getBean(getServletContext()));
body.put("contextPath", getContextPath());
body.put("applicationName", getApplicationName());
return new TemplateResponseValues("startupStatus-display.ftl", body);
}
private String getContextPath() {
String cp = getServletContext().getContextPath();
if ((cp == null) || cp.isEmpty()) {
return "The application";
} else {
return cp;
}
}
private Object getApplicationName() {
String name = "";
try {
ApplicationBean app = ApplicationBean.getAppBean(getServletContext());
name = app.getApplicationName();
} catch (Exception e) {
// deal with problems below
}
if ((name != null) && (!name.isEmpty())) {
return name;
} else {
return getContextPath();
}
}
}

View file

@ -17,6 +17,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import freemarker.cache.WebappTemplateLoader;
import freemarker.template.Configuration;
@ -29,7 +30,7 @@ import freemarker.template.TemplateException;
* StartupStatus display page.
*
* If the status only contains warnings, this only happens once. Subsequent
* requests will display normally. However, if the status contains a fatal
* requests will display normally. However, if the status contains a fatal
* error, this filter will hijack every request, and will not let you proceed.
*/
public class StartupStatusDisplayFilter implements Filter {
@ -72,6 +73,7 @@ public class StartupStatusDisplayFilter implements Filter {
bodyMap.put("status", ss);
bodyMap.put("showLink", !isFatal());
bodyMap.put("contextPath", getContextPath());
bodyMap.put("applicationName", getApplicationName());
hResp.setStatus(SC_INTERNAL_SERVER_ERROR);
Template tpl = loadFreemarkerTemplate();
@ -90,6 +92,22 @@ public class StartupStatusDisplayFilter implements Filter {
}
}
private Object getApplicationName() {
String name = "";
try {
ApplicationBean app = ApplicationBean.getAppBean(ctx);
name = app.getApplicationName();
} catch (Exception e) {
// deal with problems below
}
if ((name != null) && (!name.isEmpty())) {
return name;
} else {
return getContextPath();
}
}
private Template loadFreemarkerTemplate() throws IOException {
Configuration cfg = new Configuration();
cfg.setTemplateLoader(new WebappTemplateLoader(ctx));