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();
}
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();
}
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();
}
Aggregations