Exemple #1
0
  public static void printSanitizedStackTrace(
      Throwable t, PrintWriter p, StackTraceFilterer stackTraceFilterer) {
    t = stackTraceFilterer.filter(t);

    StackTraceElement[] trace = t.getStackTrace();
    for (StackTraceElement stackTraceElement : trace) {
      p.println(
          "at "
              + stackTraceElement.getClassName()
              + "("
              + stackTraceElement.getMethodName()
              + ":"
              + stackTraceElement.getLineNumber()
              + ")");
    }
  }
  @Override
  public void fireTestFailure(Failure failure) {
    console.error("Failure: ", failure.getDescription().getDisplayName());
    Throwable exception = failure.getException();
    if (exception == null) {
      console.error(failure.getMessage());
    } else {
      StackTraceFilterer filterer = new DefaultStackTraceFilterer();
      filterer.setCutOffPackage("org.junit");
      filterer.filter(exception, true);

      StringWriter sw = new StringWriter();
      PrintWriter ps = new PrintWriter(sw);
      exception.printStackTrace(ps);

      console.error("", sw.toString());
    }
    super.fireTestFailure(failure);
  }
  /**
   * Trigger afterCompletion callbacks on the mapped HandlerInterceptors. Will just invoke
   * afterCompletion for all interceptors whose preHandle invocation has successfully completed and
   * returned true.
   *
   * @param mappedHandler the mapped HandlerExecutionChain
   * @param interceptorIndex index of last interceptor that successfully completed
   * @param ex Exception thrown on handler execution, or <code>null</code> if none
   * @see HandlerInterceptor#afterCompletion
   */
  protected void triggerAfterCompletion(
      HandlerExecutionChain mappedHandler,
      int interceptorIndex,
      HttpServletRequest request,
      HttpServletResponse response,
      Exception ex)
      throws Exception {

    if (mappedHandler == null || mappedHandler.getInterceptors() == null) {
      return;
    }

    // Apply afterCompletion methods of registered interceptors.
    for (int i = interceptorIndex; i >= 0; i--) {
      HandlerInterceptor interceptor = mappedHandler.getInterceptors()[i];
      try {
        interceptor.afterCompletion(request, response, mappedHandler.getHandler(), ex);
      } catch (Throwable e) {
        stackFilterer.filter(e, true);
        logger.error("HandlerInterceptor.afterCompletion threw exception", e);
      }
    }
  }
Exemple #4
0
 /**
  * Sanitize the exception and ALL nested causes
  *
  * <p>This will MODIFY the stacktrace of the exception instance and all its causes irreversibly
  *
  * @param t
  * @return The root cause exception instances, with stack trace modified to filter out grails
  *     runtime classes
  */
 public static Throwable deepSanitize(Throwable t) {
   return stackFilterer.filter(t, true);
 }
Exemple #5
0
 /**
  * Get the root cause of an exception and sanitize it for display to the user
  *
  * <p>This will MODIFY the stacktrace of the root cause exception object and return it
  *
  * @param t
  * @return The root cause exception instance, with its stace trace modified to filter out grails
  *     runtime classes
  */
 public static Throwable sanitizeRootCause(Throwable t) {
   return stackFilterer.filter(extractRootCause(t));
 }
Exemple #6
0
 /**
  * Remove all apparently Grails-internal trace entries from the exception instance
  *
  * <p>
  *
  * <p>This modifies the original instance and returns it, it does not clone
  *
  * @param t The exception
  * @return The exception passed in, after cleaning the stack trace
  * @deprecated Use {@link StackTraceFilterer} instead
  */
 @Deprecated
 public static Throwable sanitize(Throwable t) {
   return stackFilterer.filter(t);
 }