NIHVIVO-336 Give the error/warning page a 500 status; make it persistent on errors; dont't show the continue link on errors.

This commit is contained in:
j2blake 2011-09-26 18:24:12 +00:00
parent 17334653cf
commit c7899805e8
2 changed files with 33 additions and 17 deletions

View file

@ -2,8 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.filters; package edu.cornell.mannlib.vitro.webapp.filters;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -14,6 +15,7 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import freemarker.cache.WebappTemplateLoader; import freemarker.cache.WebappTemplateLoader;
@ -33,11 +35,13 @@ public class StartupStatusDisplayFilter implements Filter {
private static final String TEMPLATE_PATH = "/templates/freemarker/body/admin/startupStatus-displayRaw.ftl"; private static final String TEMPLATE_PATH = "/templates/freemarker/body/admin/startupStatus-displayRaw.ftl";
private ServletContext ctx; private ServletContext ctx;
private StartupStatus ss;
private boolean statusAlreadyDisplayed; private boolean statusAlreadyDisplayed;
@Override @Override
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) throws ServletException {
ctx = filterConfig.getServletContext(); ctx = filterConfig.getServletContext();
ss = StartupStatus.getBean(ctx);
statusAlreadyDisplayed = false; statusAlreadyDisplayed = false;
} }
@ -49,31 +53,39 @@ public class StartupStatusDisplayFilter implements Filter {
@Override @Override
public void doFilter(ServletRequest req, ServletResponse resp, public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException { FilterChain chain) throws IOException, ServletException {
StartupStatus ss = StartupStatus.getBean(ctx); if (ss.allClear() || (!isFatal() && statusAlreadyDisplayed)) {
if (ss.allClear() || statusAlreadyDisplayed) {
chain.doFilter(req, resp); chain.doFilter(req, resp);
return; return;
} }
displayStartupStatus(req, resp); displayStartupStatus(resp);
statusAlreadyDisplayed = true; statusAlreadyDisplayed = true;
} }
private void displayStartupStatus(ServletRequest req, ServletResponse resp) private void displayStartupStatus(ServletResponse resp) throws IOException,
throws IOException, ServletException { ServletException {
Configuration cfg = new Configuration(); HttpServletResponse hResp = (HttpServletResponse) resp;
cfg.setTemplateLoader(new WebappTemplateLoader(ctx));
Template tpl = cfg.getTemplate(TEMPLATE_PATH);
Map<String, Object> bodyMap = new HashMap<String, Object>();
bodyMap.put("status", StartupStatus.getBean(ctx));
try { try {
PrintWriter out = resp.getWriter(); Map<String, Object> bodyMap = new HashMap<String, Object>();
tpl.process(bodyMap, out); bodyMap.put("status", StartupStatus.getBean(ctx));
out.flush(); bodyMap.put("showLink", !isFatal());
hResp.setStatus(SC_INTERNAL_SERVER_ERROR);
Template tpl = loadFreemarkerTemplate();
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);
} }
} }
private Template loadFreemarkerTemplate() throws IOException {
Configuration cfg = new Configuration();
cfg.setTemplateLoader(new WebappTemplateLoader(ctx));
return cfg.getTemplate(TEMPLATE_PATH);
}
private boolean isFatal() {
return !ss.getErrorItems().isEmpty();
}
} }

View file

@ -80,7 +80,9 @@
<#if status.errorItems?has_content> <#if status.errorItems?has_content>
<h2>Fatal error</h2> <h2>Fatal error</h2>
<p>VIVO detected a fatal error during startup.</p> <p>VIVO detected a fatal error during startup.</p>
<#if showLink>
<p><a href=".">Continue</a></p> <p><a href=".">Continue</a></p>
</#if>
<#list status.errorItems as item> <#list status.errorItems as item>
<@statusItem item=item /> <@statusItem item=item />
</#list> </#list>
@ -89,7 +91,9 @@
<#if status.warningItems?has_content> <#if status.warningItems?has_content>
<h2>Warning</h2> <h2>Warning</h2>
<p>VIVO issued warnings during startup.</p> <p>VIVO issued warnings during startup.</p>
<#if showLink>
<p><a href=".">Continue</a></p> <p><a href=".">Continue</a></p>
</#if>
<#list status.warningItems as item> <#list status.warningItems as item>
<@statusItem item=item /> <@statusItem item=item />
</#list> </#list>