@Override
  public void handle() throws FacesException {
    for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
        i.hasNext(); ) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      Throwable t = context.getException();
      if (t instanceof ViewExpiredException) {
        ViewExpiredException vee = (ViewExpiredException) t;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
        NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
        try {
          // Push some useful stuff to the request scope for use in the page
          requestMap.put("currentViewId", vee.getViewId());
          navigationHandler.handleNavigation(facesContext, null, "/viewExpired");
          facesContext.renderResponse();
        } finally {
          i.remove();
        }
      }
    }

    // At this point, the queue will not contain any ViewExpiredEvents. Therefore, let the parent
    // handle them.
    getWrapped().handle();
  }
  /** @see javax.faces.context.ExceptionHandlerWrapper#handle() */
  @Override
  public void handle() throws FacesException {
    Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator();
    while (it.hasNext()) {
      ExceptionQueuedEvent event = it.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      FacesContext facesContext = FacesContext.getCurrentInstance();

      ResourceBundle bundle = facesContext.getApplication().getResourceBundle(facesContext, "msg");

      Throwable t = context.getException();

      String title = bundle.getString("error.unhandled.title");
      String message = bundle.getString("error.unhandled.message") + t;

      if (logger.isErrorEnabled()) {
        logger.error(title, t);
      }

      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, title, message));

      it.remove();
    }

    getWrapped().handle();
  }
Example #3
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();
      }
    }
  }
  @Override
  public void handle() throws FacesException {
    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();

    while (i.hasNext()) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      Throwable t = context.getException();

      final FacesContext fc = FacesContext.getCurrentInstance();
      final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();

      try {
        System.out.printf(">>> Exception caught: %s", t.getMessage());
        t.printStackTrace();

        requestMap.put("exceptionMessage", t.getMessage());

        ExternalContext extContext = fc.getExternalContext();
        String url = extContext.encodeActionURL(extContext.getRequestContextPath() + "/500.xhtml");
        extContext.redirect(url);
      } catch (Exception e) {
        String errorPageLocation = "/WEB-INF/500.xhtml";
        fc.setViewRoot(fc.getApplication().getViewHandler().createView(fc, errorPageLocation));
        fc.getPartialViewContext().setRenderAll(false);
        fc.renderResponse();
      } finally {
        i.remove();
      }
    }

    getWrapped().handle();
  }
  // Metodo responsavel por tratar a exception
  @Override
  public void handle() throws FacesException {
    Iterator<ExceptionQueuedEvent> events = getUnhandledExceptionQueuedEvents().iterator();

    boolean handled = false;

    while (events.hasNext()) {
      ExceptionQueuedEvent event = events.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
      Throwable exception = context.getException();

      try {
        if (exception instanceof ViewExpiredException) {
          System.out.println("[DEBUG] Exception ViewExpired tratada");
          handled = true;
          redirect("/");
        } else { // ERRO DE SISTEMA
          handled = true;
          // add log
          // envia a pagina de erro
        }
      } finally {
        if (handled) {
          events.remove();
          handled = false;
        }
      }
    }

    getWrapped().handle();
  }
  @Override
  public void handle() throws FacesException {

    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
    while (i.hasNext()) {
      ExceptionQueuedEvent event = i.next();
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();

      // get the exception from context
      Throwable t = context.getException();

      final FacesContext fc = FacesContext.getCurrentInstance();
      final Map<String, Object> requestMap = fc.getExternalContext().getRequestMap();
      final NavigationHandler nav = fc.getApplication().getNavigationHandler();

      // here you do what ever you want with exception
      try {

        if (ExceptionUtils.getRootCause(t) instanceof AccessDeniedException) {
          throw (AccessDeniedException) ExceptionUtils.getRootCause(t);
        }

        log.error("złapano wyjątek: nieprzechwycony przez controller");
        log.error(t.getMessage(), t);
        t.printStackTrace();

        // redirect error page
        requestMap.put("exceptionMessage", t.getMessage());
        nav.handleNavigation(fc, null, "/error");
        fc.renderResponse();

        // remove the comment below if you want to report the error in a jsf error message
        //                JsfUtil.addErrorMessage(t.getMessage());

      } finally {
        // remove it from queue
        i.remove();
      }
    }
    // parent hanle
    getWrapped().handle();
  }
  /** @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();
      }
    }
  }