diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/StartupStatusDisplayFilter.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/StartupStatusDisplayFilter.java new file mode 100644 index 000000000..8b7a91cd9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/StartupStatusDisplayFilter.java @@ -0,0 +1,79 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.filters; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; +import freemarker.cache.WebappTemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +/** + * No matter what URL is requested, check to see whether the StartupStatus + * contains errors or warnings. If it does, hijack the request to show the + * StartupStatus display page. + * + * This only happens once. This filter does nothing after displaying the startup + * status page one time. + */ +public class StartupStatusDisplayFilter implements Filter { + private static final String TEMPLATE_PATH = "/templates/freemarker/body/admin/startupStatus-displayRaw.ftl"; + + private ServletContext ctx; + private boolean statusAlreadyDisplayed; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + ctx = filterConfig.getServletContext(); + statusAlreadyDisplayed = false; + } + + @Override + public void destroy() { + // nothing to do. + } + + @Override + public void doFilter(ServletRequest req, ServletResponse resp, + FilterChain chain) throws IOException, ServletException { + StartupStatus ss = StartupStatus.getBean(ctx); + if (ss.allClear() || statusAlreadyDisplayed) { + chain.doFilter(req, resp); + return; + } + + displayStartupStatus(req, resp); + statusAlreadyDisplayed = true; + } + + private void displayStartupStatus(ServletRequest req, ServletResponse resp) + throws IOException, ServletException { + Configuration cfg = new Configuration(); + cfg.setTemplateLoader(new WebappTemplateLoader(ctx)); + Template tpl = cfg.getTemplate(TEMPLATE_PATH); + + Map bodyMap = new HashMap(); + bodyMap.put("status", StartupStatus.getBean(ctx)); + + try { + PrintWriter out = resp.getWriter(); + tpl.process(bodyMap, out); + out.flush(); + } catch (TemplateException e) { + throw new ServletException("Problem with Freemarker Template", e); + } + } +} diff --git a/webapp/web/css/startupStatus.css b/webapp/web/css/startupStatus.css new file mode 100644 index 000000000..58a8176e7 --- /dev/null +++ b/webapp/web/css/startupStatus.css @@ -0,0 +1,28 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +/* Styles for Freemarker template startupStatus-display and startupStatus-displayRaw */ + +table.item { + border: thin solid black; + font-family: monospace; + width: 100%; +} +table.item tr.top { + font-size: larger; +} +table.item td { + border: thin solid black; +} +.error td { + background: #FFDDDD; + font-weight: bolder; +} +.warning td { + background: #FFFFDD; +} +.info td { + background: #DDFFDD; +} +.not_executed td { + color: #444444; +} diff --git a/webapp/web/templates/freemarker/body/admin/startupStatus-displayRaw.ftl b/webapp/web/templates/freemarker/body/admin/startupStatus-displayRaw.ftl new file mode 100644 index 000000000..8ccc2e614 --- /dev/null +++ b/webapp/web/templates/freemarker/body/admin/startupStatus-displayRaw.ftl @@ -0,0 +1,77 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#-- + Template for the raw page that displays the StartupStatus if there + are warnings or errors. + + "raw" because this template works outside of the usual framework, in + case the Freemarker context didn't initialize properly. +--> + +<#macro statusItem item> + <#if item.level = "FATAL"> + <#assign color = "error" > + <#elseif item.level = "WARNING"> + <#assign color = "warning" > + <#elseif item.level = "INFO"> + <#assign color = "info" > + <#elseif item.level = "NOT_EXECUTED"> + <#assign color = "not_executed" > + <#else> + <#assign color = "" > + + + + + + + + + + + + + + <#if item.cause??> + + + + +
${item.level}${item.shortSourceName}
${item.message}
${item.sourceName}
${item.cause}
+ + + + + + Startup Status + + + + + <#if status.errorItems?has_content> +

Fatal error

+

VIVO detected a fatal error during startup.

+

Continue

+ <#list status.errorItems as item> + <@statusItem item=item /> + + + + <#if status.warningItems?has_content> +

Warning

+

VIVO issued warnings during startup.

+

Continue

+ <#list status.warningItems as item> + <@statusItem item=item /> + + + +

Startup trace

+

The full list of startup events and messages.

+ + <#list status.statusItems as item> + <@statusItem item=item /> + +
+ +