Ejemplo n.º 1
0
  /** @see javax.faces.context.ExceptionHandler#handle() */
  @SuppressWarnings({"ThrowableInstanceNeverThrown"})
  public void handle() throws FacesException {

    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
        i.hasNext(); ) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
      try {
        Throwable t = context.getException();
        if (isRethrown(t)) {
          handled = event;
          Throwable unwrapped = getRootCause(t);
          if (unwrapped != null) {
            throwIt(context.getContext(), new FacesException(unwrapped.getMessage(), unwrapped));
          } else {
            if (t instanceof FacesException) {
              throwIt(context.getContext(), (FacesException) t);
            } else {
              throwIt(context.getContext(), new FacesException(t.getMessage(), t));
            }
          }
        } else {
          log(context);
        }

      } finally {
        if (handledExceptions == null) {
          handledExceptions = new LinkedList<ExceptionQueuedEvent>();
        }
        handledExceptions.add(event);
        i.remove();
      }
    }
  }
  /** @see javax.faces.context.ExceptionHandlerWrapper#handle() */
  @Override
  public void handle() throws FacesException {

    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
        i.hasNext(); ) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
      try {
        Throwable t = context.getException();
        if (isRethrown(t)) {
          handled = event;
          Throwable unwrapped = getRootCause(t);

          if (unwrapped != null) {
            handlePartialResponseError(context.getContext(), unwrapped);
          } else {
            if (t instanceof FacesException) {
              handlePartialResponseError(context.getContext(), t);
            } else {
              handlePartialResponseError(
                  context.getContext(), new FacesException(t.getMessage(), t));
            }
          }
        } else {
          log(context);
        }

      } finally {
        if (handledExceptions == null) {
          handledExceptions = new LinkedList<>();
        }
        handledExceptions.add(event);
        i.remove();
      }
    }
  }
Ejemplo n.º 3
0
  private void log(ExceptionQueuedEventContext exceptionContext) {

    UIComponent c = exceptionContext.getComponent();
    boolean beforePhase = exceptionContext.inBeforePhase();
    boolean afterPhase = exceptionContext.inAfterPhase();
    PhaseId phaseId = exceptionContext.getPhaseId();
    Throwable t = exceptionContext.getException();
    String key = getLoggingKey(beforePhase, afterPhase);
    if (LOGGER.isLoggable(Level.SEVERE)) {
      LOGGER.log(
          Level.SEVERE,
          key,
          new Object[] {
            t.getClass().getName(),
            phaseId.toString(),
            ((c != null) ? c.getClientId(exceptionContext.getContext()) : ""),
            t.getMessage()
          });
      LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
  }