use of javax.faces.event.ExceptionQueuedEvent in project deltaspike by apache.
the class BridgeExceptionHandlerWrapper method processEvent.
@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
//needed because #handle gets called too late in this case
if (event instanceof ExceptionQueuedEvent) {
ExceptionQueuedEvent exceptionQueuedEvent = (ExceptionQueuedEvent) event;
FacesContext facesContext = exceptionQueuedEvent.getContext().getContext();
if (facesContext.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE && exceptionQueuedEvent.getContext().inBeforePhase()) {
Throwable exception = getRootCause(exceptionQueuedEvent.getContext().getException());
if (exception instanceof AccessDeniedException) {
processAccessDeniedException(exception);
} else {
ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(exception);
exceptionToCatchEvent.setOptional(true);
this.beanManager.fireEvent(exceptionToCatchEvent);
if (exceptionToCatchEvent.isHandled()) {
return;
}
}
}
}
super.processEvent(event);
}
use of javax.faces.event.ExceptionQueuedEvent in project oxTrust 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();
final ConfigurableNavigationHandler nav = (ConfigurableNavigationHandler) fc.getApplication().getNavigationHandler();
try {
if (isForbidden(t))
performRedirect(externalContext, "/login");
else
performRedirect(externalContext, "/error");
fc.renderResponse();
} finally {
i.remove();
}
}
getWrapped().handle();
}
use of javax.faces.event.ExceptionQueuedEvent in project deltaspike by apache.
the class DefaultErrorViewAwareExceptionHandlerWrapper method handle.
@Override
public void handle() throws FacesException {
lazyInit();
Iterator<ExceptionQueuedEvent> exceptionQueuedEventIterator = getUnhandledExceptionQueuedEvents().iterator();
while (exceptionQueuedEventIterator.hasNext()) {
ExceptionQueuedEventContext exceptionQueuedEventContext = (ExceptionQueuedEventContext) exceptionQueuedEventIterator.next().getSource();
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" }) Throwable throwable = exceptionQueuedEventContext.getException();
String viewId = null;
if (!isExceptionToHandle(throwable)) {
continue;
}
FacesContext facesContext = exceptionQueuedEventContext.getContext();
Flash flash = facesContext.getExternalContext().getFlash();
if (throwable instanceof ViewExpiredException) {
viewId = ((ViewExpiredException) throwable).getViewId();
} else if (throwable instanceof ContextNotActiveException) {
//(it's recorded below - see flash.put(throwable.getClass().getName(), throwable);)
if (flash.containsKey(ContextNotActiveException.class.getName())) {
//TODO show it in case of project-stage development
break;
}
if (facesContext.getViewRoot() != null) {
viewId = facesContext.getViewRoot().getViewId();
} else {
viewId = BeanProvider.getContextualReference(ViewConfigResolver.class).getDefaultErrorViewConfigDescriptor().getViewId();
}
}
if (viewId != null) {
UIViewRoot uiViewRoot = facesContext.getApplication().getViewHandler().createView(facesContext, viewId);
if (uiViewRoot == null) {
continue;
}
if (facesContext.isProjectStage(javax.faces.application.ProjectStage.Development) || ProjectStageProducer.getInstance().getProjectStage() == ProjectStage.Development || ProjectStageProducer.getInstance().getProjectStage() instanceof TestStage) {
throwable.printStackTrace();
}
facesContext.setViewRoot(uiViewRoot);
exceptionQueuedEventIterator.remove();
//record the current exception -> to check it at the next call or to use it on the error-page
flash.put(throwable.getClass().getName(), throwable);
flash.keep(throwable.getClass().getName());
this.viewNavigationHandler.navigateTo(DefaultErrorView.class);
break;
}
}
this.wrapped.handle();
}
use of javax.faces.event.ExceptionQueuedEvent in project deltaspike by apache.
the class BridgeExceptionHandlerWrapper method handle.
@Override
public void handle() throws FacesException {
FacesContext context = FacesContext.getCurrentInstance();
if (context == null || context.getResponseComplete()) {
return;
}
Iterable<ExceptionQueuedEvent> exceptionQueuedEvents = getUnhandledExceptionQueuedEvents();
if (exceptionQueuedEvents != null && exceptionQueuedEvents.iterator() != null) {
Iterator<ExceptionQueuedEvent> iterator = exceptionQueuedEvents.iterator();
while (iterator.hasNext()) {
Throwable throwable = iterator.next().getContext().getException();
Throwable rootCause = getRootCause(throwable);
if (rootCause instanceof AccessDeniedException) {
processAccessDeniedException(rootCause);
iterator.remove();
continue;
} else {
ExceptionToCatchEvent event = new ExceptionToCatchEvent(rootCause, exceptionQualifier);
event.setOptional(true);
beanManager.fireEvent(event);
if (event.isHandled()) {
iterator.remove();
}
}
// a handle method might redirect and set responseComplete
if (context.getResponseComplete()) {
break;
}
}
}
super.handle();
}
Aggregations