/**
   * @see wicket.request.compound.IExceptionResponseStrategy#respond(wicket.RequestCycle,
   *     java.lang.RuntimeException)
   */
  public final void respond(final RequestCycle requestCycle, final RuntimeException e) {
    // If application doesn't want debug info showing up for users
    final Session session = requestCycle.getSession();
    final Application application = session.getApplication();
    final IExceptionSettings settings = application.getExceptionSettings();
    final Page responsePage = requestCycle.getResponsePage();

    Page override = onRuntimeException(responsePage, e);
    if (override != null) {
      // we do not want to redirect - we want to inline the error output
      // and preserve the url so when the refresh button is pressed we
      // rerun the code that caused the error
      requestCycle.setRedirect(false);

      throw new RestartResponseException(override);
    } else if (e instanceof AuthorizationException) {
      // are authorization exceptions always thrown before the real render?
      // else we need to make a page (see below) or set it hard to a redirect.
      Class<? extends Page> accessDeniedPageClass =
          application.getApplicationSettings().getAccessDeniedPage();

      throw new RestartResponseAtInterceptPageException(accessDeniedPageClass);
    } else if (settings.getUnexpectedExceptionDisplay()
        != UnexpectedExceptionDisplay.SHOW_NO_EXCEPTION_PAGE) {
      // we do not want to redirect - we want to inline the error output
      // and preserve the url so when the refresh button is pressed we
      // rerun the code that caused the error
      requestCycle.setRedirect(false);

      // figure out which error page to show
      Class<? extends Page> internalErrorPageClass =
          application.getApplicationSettings().getInternalErrorPage();
      Class responseClass = responsePage != null ? responsePage.getClass() : null;

      if (responseClass != internalErrorPageClass
          && settings.getUnexpectedExceptionDisplay()
              == UnexpectedExceptionDisplay.SHOW_INTERNAL_ERROR_PAGE) {
        throw new RestartResponseException(internalErrorPageClass);
      } else if (responseClass != ExceptionErrorPortletPage.class) {
        // Show full details
        throw new RestartResponseException(new ExceptionErrorPortletPage(e, responsePage));
      } else {
        // give up while we're ahead!
        throw new WicketRuntimeException(
            "Internal Error: Could not render error page " + internalErrorPageClass, e);
      }
    }
  }