Search in sources :

Example 1 with FatalErrorPageFactory

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");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Response(com.github.bordertech.wcomponents.Response) FatalErrorPageFactory(com.github.bordertech.wcomponents.FatalErrorPageFactory)

Example 2 with FatalErrorPageFactory

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;
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) FatalErrorPageFactory(com.github.bordertech.wcomponents.FatalErrorPageFactory) SystemException(com.github.bordertech.wcomponents.util.SystemException)

Aggregations

FatalErrorPageFactory (com.github.bordertech.wcomponents.FatalErrorPageFactory)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 Response (com.github.bordertech.wcomponents.Response)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1