Search in sources :

Example 6 with ExceptionQueuedEventContext

use of javax.faces.event.ExceptionQueuedEventContext in project fit3d by fkaiserbio.

the class Fit3DExceptionHandler method 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 {
            // log error ?
            logger.error(t.getMessage(), t);
            Flash flash = fc.getExternalContext().getFlash();
            // Put the exception in the flash scope to be displayed in the
            // error
            // page if necessary ...
            // TODO prevent direct access to errorpage
            flash.put("errorDetails", t.getMessage());
            // redirect error page
            requestMap.put("exceptionMessage", t.getMessage());
            nav.handleNavigation(fc, null, "/errorpages/generic");
            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 handle
    getWrapped().handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) NavigationHandler(javax.faces.application.NavigationHandler) Flash(javax.faces.context.Flash)

Example 7 with ExceptionQueuedEventContext

use of javax.faces.event.ExceptionQueuedEventContext in project muikku by otavanopisto.

the class ExceptionHandler method handle.

@Override
public void handle() throws FacesException {
    for (final Iterator<ExceptionQueuedEvent> queuedEventIterator = getUnhandledExceptionQueuedEvents().iterator(); queuedEventIterator.hasNext(); ) {
        ExceptionQueuedEvent queuedEvent = queuedEventIterator.next();
        ExceptionQueuedEventContext queuedEventContext = queuedEvent.getContext();
        Throwable exception = queuedEventContext.getException();
        while ((exception instanceof FacesException || exception instanceof EJBException || exception instanceof ELException || exception instanceof RewriteException || exception instanceof CreationException || exception instanceof IllegalStateException) && exception.getCause() != null) {
            exception = exception.getCause();
        }
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        try {
            if (exception instanceof AuthorizationException) {
                externalContext.setResponseStatus(HttpServletResponse.SC_FORBIDDEN);
                renderView("/error/access-denied.jsf");
            } else if (exception instanceof FileNotFoundException) {
                externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                renderView("/error/not-found.jsf");
            } else {
                throw new FacesException(exception);
            }
        } finally {
            queuedEventIterator.remove();
        }
    }
    getWrapped().handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) AuthorizationException(fi.otavanopisto.security.AuthorizationException) FileNotFoundException(java.io.FileNotFoundException) CreationException(javax.enterprise.inject.CreationException) FacesException(javax.faces.FacesException) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) RewriteException(org.ocpsoft.rewrite.exception.RewriteException) ExternalContext(javax.faces.context.ExternalContext) ELException(javax.el.ELException) EJBException(javax.ejb.EJBException)

Example 8 with ExceptionQueuedEventContext

use of javax.faces.event.ExceptionQueuedEventContext in project oxAuth by GluuFederation.

the class GlobalExceptionHandler method handle.

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 ExternalContext externalContext = fc.getExternalContext();
        try {
            if (isInvalidSessionStateException(t)) {
                log.error(t.getMessage(), t);
                performRedirect(externalContext, "/error_session.htm");
            } else {
                log.error(t.getMessage(), t);
                performRedirect(externalContext, "/error_service.htm");
            }
            fc.renderResponse();
        } finally {
            i.remove();
        }
    }
    getWrapped().handle();
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) ExceptionQueuedEventContext(javax.faces.event.ExceptionQueuedEventContext) ExternalContext(javax.faces.context.ExternalContext)

Aggregations

ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)8 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)8 FacesContext (javax.faces.context.FacesContext)5 ExternalContext (javax.faces.context.ExternalContext)3 LinkedList (java.util.LinkedList)2 Flash (javax.faces.context.Flash)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AuthorizationException (fi.otavanopisto.security.AuthorizationException)1 FileNotFoundException (java.io.FileNotFoundException)1 EJBException (javax.ejb.EJBException)1 ELException (javax.el.ELException)1 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)1 CreationException (javax.enterprise.inject.CreationException)1 FacesException (javax.faces.FacesException)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 NavigationHandler (javax.faces.application.NavigationHandler)1 ViewExpiredException (javax.faces.application.ViewExpiredException)1 UIViewRoot (javax.faces.component.UIViewRoot)1