Ejemplo n.º 1
0
  /** @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();
  }
Ejemplo n.º 2
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 {
    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();
  }
  @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();
  }
  /** Metodo que efetivamente manipula a exception. */
  @Override
  public void handle() throws FacesException {
    // iterage para pegar todas as exceptions geradas
    for (ExceptionQueuedEvent event : getUnhandledExceptionQueuedEvents()) {

      ExceptionQueuedEventContext context = event.getContext();

      Throwable throwable = context.getException(); // tipo FacesException

      Throwable essenciaException = getAlternativeRootCause(throwable);

      if (essenciaException instanceof NegocioException) {
        JSFUtil.addErrorMessage(essenciaException);

      } else {
        JSFUtil.addFatalMessage("Erro inesperado", essenciaException);
      }
    }
  }
Ejemplo n.º 7
0
  @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();
  }
Ejemplo n.º 8
0
  @Override
  public void handle() throws FacesException {
    Iterable<ExceptionQueuedEvent> events = this.wrapped.getUnhandledExceptionQueuedEvents();
    for (Iterator<ExceptionQueuedEvent> it = events.iterator(); it.hasNext(); ) {
      ExceptionQueuedEvent event = it.next();
      ExceptionQueuedEventContext eqec = event.getContext();
      eqec.getException().printStackTrace();
      //            if(eqec.getException() instanceof ViewExpiredException) {
      //                FacesContext context = eqec.getContext();
      //                if(!context.isReleased()) {
      //                    NavigationHandler navHandler =
      // context.getApplication().getNavigationHandler();
      //
      //                    try {
      //
      //                    	//FIXME:session超时挂掉等等,跳转到相应页面,给提示。
      ////                    	FacesUtil.addErrorMessage("长时间未操作。");
      //                    	String originalViewId = context.getViewRoot().getViewId();
      //                    	if (originalViewId.endsWith(".xhtml")) {
      //                    		String redirectUrl = originalViewId.substring(0,
      // originalViewId.length()-6);
      //                    		navHandler.handleNavigation(context, null,
      // redirectUrl+"?faces-redirect=true&expired=true");
      //						}
      ////                        navHandler.handleNavigation(context, null,
      // "pretty:home?faces-redirect=true&expired=true");
      //                    }
      //                    finally {
      //                        it.remove();
      //                    }
      //                }
      //
      //            }
    }

    this.wrapped.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();
      }
    }
  }
Ejemplo n.º 10
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);
    }
  }