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;
@ -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));

View file

@ -25,7 +25,7 @@
<ul class="item-spec" role="navigation">
<li role="listitem">${item.message}</li>
<li role="listitem">${item.sourceName}</li>
<#if item.cause??>
<#if item.cause?has_content>
<li role="listitem"><pre>${item.cause}</pre></li>
</#if>
</ul>
@ -37,7 +37,7 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/startupStatus.c
<#if status.errorItems?has_content>
<h2>Fatal error</h2>
<p>VIVO detected a fatal error during startup.</p>
<p>${applicationName} detected a fatal error during startup.</p>
<ul id="startup-trace" cellspacing="0" class="trace" role="navigation">
<#list status.errorItems as item>
@ -49,7 +49,7 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/startupStatus.c
<#if status.warningItems?has_content>
<h2>Warning</h2>
<p>VIVO issued warnings during startup.</p>
<p>${applicationName} issued warnings during startup.</p>
<ul id="startup-trace" cellspacing="0" class="trace" role="navigation"><#list status.warningItems as item>
<@statusItem item=item />

View file

@ -29,7 +29,7 @@
<ul class="item-spec" role="navigation">
<li role="listitem">${item.message}</li>
<li role="listitem">${item.sourceName}</li>
<#if item.cause??>
<#if item.cause?has_content>
<li role="listitem"><pre>${item.cause}</pre></li>
</#if>
</ul>
@ -79,7 +79,7 @@
<#if status.errorItems?has_content>
<h2>Fatal error</h2>
<p>VIVO detected a fatal error during startup.</p>
<p>${applicationName} detected a fatal error during startup.</p>
<ul id="startup-trace" cellspacing="0" class="trace" role="navigation">
<#list status.errorItems as item>
@ -91,12 +91,18 @@
<#if status.warningItems?has_content>
<h2>Warning</h2>
<p>VIVO issued warnings during startup.</p>
<p>${applicationName} issued warnings during startup.</p>
<ul id="startup-trace" cellspacing="0" class="trace" role="navigation"><#list status.warningItems as item>
<@statusItem item=item />
</#list>
</ul>
<#-- If there were no fatal errors, let them go forward from here. -->
<#if showLink>
<p><a href=".">Continue</a></p>
</#if>
</#if>
<h2>Startup trace</h2>