use of com.github.bordertech.wcomponents.FatalErrorPageFactory in project wcomponents by BorderTech.
the class AbstractContainerHelper method handleError.
/**
* Last resort error handling.
*
* @param error the error to handle.
* @throws IOException if there is an error writing the error HTML.
*/
public void handleError(final Throwable error) throws IOException {
LOG.debug("Start handleError...");
// Should the session be removed upon error?
boolean terminate = ConfigurationProperties.getTerminateSessionOnError();
// If we are unfriendly, terminate the session
if (terminate) {
invalidateSession();
}
// Are we in developer friendly error mode?
boolean friendly = ConfigurationProperties.getDeveloperErrorHandling();
FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class);
WComponent errorPage = factory.createErrorPage(friendly, error);
String html = renderErrorPageToHTML(errorPage);
// Setup the response
Response response = getResponse();
response.setContentType(WebUtilities.CONTENT_TYPE_HTML);
// Make sure not cached
getResponse().setHeader("Cache-Control", CacheType.NO_CACHE.getSettings());
getResponse().setHeader("Pragma", "no-cache");
getResponse().setHeader("Expires", "-1");
getPrintWriter().println(html);
LOG.debug("End handleError");
}
use of com.github.bordertech.wcomponents.FatalErrorPageFactory in project wcomponents by BorderTech.
the class UIRegistryAmicableImpl method loadUI.
/**
* Attempts to load a UI using the key as a class name.
*
* @param key The registration key.
* @return A WComponent if one could be loaded from the classpath, else an ErrorPage WComponent containing the
* problem.
*/
private static WComponent loadUI(final String key) {
String classname = key.trim();
try {
Class<?> clas = Class.forName(classname);
if (WComponent.class.isAssignableFrom(clas)) {
WComponent instance = (WComponent) clas.newInstance();
LOG.debug("WComponent successfully loaded with class name \"" + classname + "\".");
return instance;
} else {
throw new SystemException("The resource with the name \"" + classname + "\" is not a WComponent.");
}
} catch (Exception ex) {
LOG.error("Unable to load a WComponent using the resource name \"" + classname + "\"", ex);
// Are we in developer friendly error mode?
boolean friendly = ConfigurationProperties.getDeveloperErrorHandling();
FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class);
WComponent errorPage = factory.createErrorPage(friendly, ex);
return errorPage;
}
}
Aggregations