use of javax.faces.event.ExceptionQueuedEventContext in project ART-TIME by Artezio.
the class ExceptionHandler method handle.
@Override
public void handle() throws FacesException {
final Iterator<ExceptionQueuedEvent> iterator = getUnhandledExceptionQueuedEvents().iterator();
List<String> errorMessages = new ArrayList<String>();
while (iterator.hasNext()) {
ExceptionQueuedEvent exceptionEvent = iterator.next();
ExceptionQueuedEventContext exceptionEventContext = (ExceptionQueuedEventContext) exceptionEvent.getSource();
Throwable incomingException = exceptionEventContext.getException();
List<String> messages = findErrorMessages(incomingException);
if (!messages.isEmpty()) {
errorMessages.addAll(messages);
iterator.remove();
}
}
if (!errorMessages.isEmpty()) {
MessagesUtil.removeMessagesLessThan(FacesMessage.SEVERITY_ERROR);
for (String message : errorMessages) {
MessagesUtil.addError(null, message);
}
resetDataTablesRowIndex(getViewRoot());
}
getWrapped().handle();
}
use of javax.faces.event.ExceptionQueuedEventContext 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.ExceptionQueuedEventContext 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 (isSecurityException(t)) {
performRedirect(externalContext, "/login");
} else if (isConversationException(t)) {
log.error(t.getMessage(), t);
performRedirect(externalContext, "/conversation_error");
}
if (isViewExpiredException(t)) {
storeRequestURI();
performRedirect(externalContext, "/login");
} else {
log.error(t.getMessage(), t);
performRedirect(externalContext, "/error");
}
fc.renderResponse();
} finally {
i.remove();
}
}
getWrapped().handle();
}
use of javax.faces.event.ExceptionQueuedEventContext in project ART-TIME by Artezio.
the class ExceptionHandlerTest method testHandle_ifErrorMessageIsNull.
@Test
public final void testHandle_ifErrorMessageIsNull() {
PowerMock.mockStatic(MessagesUtil.class);
PowerMock.mockStatic(ExceptionHandler.class);
exceptionHandler = createMockBuilder(ExceptionHandler.class).addMockedMethod("findErrorMessages").addMockedMethod("getUnhandledExceptionQueuedEvents").addMockedMethod("getWrapped").createMock();
wrappedExceptionHandler = EasyMock.createMock(javax.faces.context.ExceptionHandler.class);
PowerMock.mockStatic(MessagesUtil.class);
Throwable exceptionForSearch = new ArithmeticException();
ExceptionQueuedEventContext exceptionEventContext = new ExceptionQueuedEventContext(FacesContext.getCurrentInstance(), exceptionForSearch);
ExceptionQueuedEvent exceptionEvent = new ExceptionQueuedEvent(exceptionEventContext);
Iterable<ExceptionQueuedEvent> exceptionEvents = new LinkedList<ExceptionQueuedEvent>(Arrays.asList(exceptionEvent));
expect(exceptionHandler.getUnhandledExceptionQueuedEvents()).andReturn(exceptionEvents);
expect(exceptionHandler.findErrorMessages(exceptionForSearch)).andReturn(new ArrayList<String>());
expect(exceptionHandler.getWrapped()).andReturn(wrappedExceptionHandler);
wrappedExceptionHandler.handle();
PowerMock.expectLastCall();
PowerMock.replay(exceptionHandler, wrappedExceptionHandler, MessagesUtil.class);
exceptionHandler.handle();
PowerMock.verify(exceptionHandler, wrappedExceptionHandler, MessagesUtil.class);
}
use of javax.faces.event.ExceptionQueuedEventContext in project ART-TIME by Artezio.
the class ExceptionHandlerTest method testHandle.
@Test
public final void testHandle() {
PowerMock.mockStatic(MessagesUtil.class);
PowerMock.mockStatic(ExceptionHandler.class);
exceptionHandler = createMockBuilder(ExceptionHandler.class).addMockedMethod("findErrorMessages").addMockedMethod("getUnhandledExceptionQueuedEvents").addMockedMethod("getWrapped").createMock();
wrappedExceptionHandler = EasyMock.createMock(javax.faces.context.ExceptionHandler.class);
PowerMock.mockStatic(MessagesUtil.class);
Throwable exceptionForSearch = new ArithmeticException();
ExceptionQueuedEventContext exceptionEventContext = new ExceptionQueuedEventContext(FacesContext.getCurrentInstance(), exceptionForSearch);
ExceptionQueuedEvent exceptionEvent = new ExceptionQueuedEvent(exceptionEventContext);
Iterable<ExceptionQueuedEvent> exceptionEvents = new LinkedList<ExceptionQueuedEvent>(Arrays.asList(exceptionEvent));
List<String> messages = Arrays.asList("Exception message");
expect(exceptionHandler.getUnhandledExceptionQueuedEvents()).andReturn(exceptionEvents);
expect(exceptionHandler.findErrorMessages(exceptionForSearch)).andReturn(messages);
MessagesUtil.removeMessagesLessThan(FacesMessage.SEVERITY_ERROR);
MessagesUtil.addError(null, messages.get(0));
expect(exceptionHandler.getWrapped()).andReturn(wrappedExceptionHandler);
wrappedExceptionHandler.handle();
PowerMock.replay(exceptionHandler, wrappedExceptionHandler, MessagesUtil.class);
exceptionHandler.handle();
PowerMock.verify(exceptionHandler, wrappedExceptionHandler, MessagesUtil.class);
}
Aggregations