List of usage examples for com.vaadin.server DefaultErrorHandler findAbstractComponent
public static AbstractComponent findAbstractComponent(com.vaadin.server.ErrorEvent event)
From source file:com.haulmont.cuba.web.exception.InvalidValueExceptionHandler.java
License:Apache License
@Override public boolean handle(ErrorEvent event, App app) { boolean handled = super.handle(event, app); //noinspection ThrowableResultOfMethodCallIgnored if (handled && event.getThrowable() != null) { // Finds the original source of the error/exception AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event); if (component != null) { component.markAsDirty();/*from w w w. j a v a 2s.com*/ } if (component instanceof Component.Focusable) { ((Component.Focusable) component).focus(); } //noinspection ThrowableResultOfMethodCallIgnored if (event.getThrowable() instanceof Validator.InvalidValueException) { app.getAppUI().discardAccumulatedEvents(); } } return handled; }
From source file:com.haulmont.cuba.web.log.AppLog.java
License:Apache License
@SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void log(ErrorEvent event) { Throwable t = event.getThrowable(); if (t instanceof SilentException) return;/*from w w w . j av a 2 s. c o m*/ if (t instanceof Validator.InvalidValueException) return; if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) { // Most likely client browser closed socket LogItem item = new LogItem(LogLevel.WARNING, "SocketException in CommunicationManager. Most likely client (browser) closed socket.", null); log(item); return; } // Support Tomcat 8 ClientAbortException if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) { // Most likely client browser closed socket LogItem item = new LogItem(LogLevel.WARNING, "ClientAbortException on write response to client. Most likely client (browser) closed socket.", null); log(item); return; } Throwable rootCause = ExceptionUtils.getRootCause(t); if (rootCause == null) rootCause = t; Logging annotation = rootCause.getClass().getAnnotation(Logging.class); Logging.Type loggingType = annotation == null ? Logging.Type.FULL : annotation.value(); if (loggingType == Logging.Type.NONE) return; // Finds the original source of the error/exception AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event); StringBuilder msg = new StringBuilder(); msg.append("Exception"); if (component != null) msg.append(" in ").append(component.getClass().getName()); msg.append(": "); if (loggingType == Logging.Type.BRIEF) { error(msg + rootCause.toString()); } else { LogItem item = new LogItem(LogLevel.ERROR, msg.toString(), t); log(item); } }
From source file:de.symeda.sormas.ui.SormasErrorHandler.java
License:Open Source License
public static void handleError(ErrorEvent event) { final Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket logger.info(/*from w w w. ja va 2s . c om*/ "SocketException in CommunicationManager." + " Most likely client (browser) closed socket."); return; } ErrorMessage errorMessage = getErrorMessageForException(t); if (t != null) { // log the error or warning if (errorMessage instanceof SystemError) { logger.error(t.getMessage(), t); } else { logger.warn(t.getMessage(), t); } } // finds the original source of the error/exception AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event); if (errorMessage != null && component != null) { // Shows the error in AbstractComponent if (errorMessage instanceof SystemError) { Notification.show( I18nProperties.getString(Strings.errorOccurred, I18nProperties.getString(Strings.errorOccurred)), I18nProperties.getString(Strings.errorWasReported), Notification.Type.ERROR_MESSAGE); } else { // to prevent the original message from appearing, if necessary if (component instanceof AbstractField<?>) { ((AbstractField<?>) component).setCurrentBufferedSourceException(null); } Notification notification = new Notification( I18nProperties.getString(Strings.errorProblemOccurred, I18nProperties.getString(Strings.errorProblemOccurred)), errorMessage.getFormattedHtmlMessage(), Notification.Type.WARNING_MESSAGE, true); notification.setDelayMsec(-1); notification.show(Page.getCurrent()); component.setComponentError(errorMessage); } } }