@Override public final void error(final ErrorEvent event) { // // Extract the relevant exception Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket logger.info("SocketException in CommunicationManager. Most likely client (browser) closed socket."); return; } t = DefaultErrorHandler.findRelevantThrowable(t); // // Create error message final ErrorMessage errorMessage = createErrorMessage(t); // // Display it displayError(errorMessage, event); // also print the error on console logger.error("", t); }
@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(); } if (component instanceof Component.Focusable) { ((Component.Focusable) component).focus(); } //noinspection ThrowableResultOfMethodCallIgnored if (event.getThrowable() instanceof Validator.InvalidValueException) { app.getAppUI().discardAccumulatedEvents(); } } return handled; }
@Override public boolean handle(ErrorEvent event, App app) { Throwable exception = event.getThrowable(); //noinspection unchecked List<Throwable> list = ExceptionUtils.getThrowableList(exception); for (Throwable throwable : list) { if (classNames.contains(throwable.getClass().getName()) && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) { doHandle(app, throwable.getClass().getName(), throwable.getMessage(), throwable); return true; } if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (classNames.contains(cause.getClassName()) && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) { doHandle(app, cause.getClassName(), cause.getMessage(), cause.getThrowable()); return true; } } } } return false; }
@Override public void error(final ErrorEvent event) { final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event)); if (event instanceof ConnectorErrorEvent) { final Connector connector = ((ConnectorErrorEvent) event).getConnector(); if (connector instanceof UI) { final UI uiInstance = (UI) connector; uiInstance.access(() -> message.show(uiInstance.getPage())); return; } } final Optional<Page> originError = getPageOriginError(event); if (originError.isPresent()) { message.show(originError.get()); return; } HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE); }
/** * Adds a default transaction listener. */ @Override public void init() { final LegacyApplication app = this; VaadinSession.getCurrent().setErrorHandler(new ErrorHandler() { private static final long serialVersionUID = 1L; @Override public void error(ErrorEvent event) { Utils.terminalError(event, app); } }); if(!Db.isInitialized()) { logger.warn("No TransactionListener added: Database is not initialized. You can initialize a database configuring a new 'DefaultTransactionListener' in your web.xml and adding a 'configuration.properties' file to your classpath."); } VaadinSession.getCurrent().setAttribute("application", this); }
/** * Call the session's {@link ErrorHandler}, if it has one, with the given * exception wrapped in an {@link ErrorEvent}. */ private void callErrorHandler(VaadinSession session, Exception e) { try { ErrorHandler errorHandler = ErrorEvent.findErrorHandler(session); if (errorHandler != null) { errorHandler.error(new ErrorEvent(e)); } } catch (Exception ex) { // Let's not allow error handling to cause trouble; log fails getLogger().log(Level.WARNING, "ErrorHandler call failed", ex); } }
@Override protected void displayError(final ErrorMessage errorMessage, final ErrorEvent event) { if (component != null) { component.setComponentError(errorMessage); } }
@Override public boolean handle(ErrorEvent event, App app) { // Copied from com.vaadin.server.DefaultErrorHandler.doDefault() //noinspection ThrowableResultOfMethodCallIgnored Throwable t = event.getThrowable(); //noinspection ThrowableResultOfMethodCallIgnored if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) { // Most likely client browser closed socket return true; } // Support Tomcat 8 ClientAbortException if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) { // Most likely client browser closed socket return true; } AppUI ui = AppUI.getCurrent(); if (ui == null) { // there is no UI, just add error to log return true; } if (t != null) { if (app.getConnection().getSession() != null) { showDialog(app, t); } else { showNotification(app, t); } } return true; }
public static void doDefault(ErrorEvent event) { Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket getLogger().info( "SocketException in CommunicationManager." + " Most likely client (browser) closed socket."); return; } t = findRelevantThrowable(t); /* * Handle SpringSecurity */ if (t instanceof AccessDeniedException) { EventBus eventBus = SpringApplicationContext.getEventBus(); eventBus.publish(EventScope.UI, eventBus, new AccessDeniedEvent(t)); getLogger().log(Level.FINE, "Access is denied", t); return; } // Finds the original source of the error/exception AbstractComponent component = findAbstractComponent(event); if (component != null) { // Shows the error in AbstractComponent ErrorMessage errorMessage = AbstractErrorMessage .getErrorMessageForException(t); component.setComponentError(errorMessage); } // also print the error on console getLogger().log(Level.SEVERE, "", t); }
/** * Returns the AbstractComponent associated with the given error if such can * be found * * @param event * The error to investigate * @return The {@link AbstractComponent} to error relates to or null if * could not be determined or if the error does not relate to any * AbstractComponent. */ public static AbstractComponent findAbstractComponent( com.vaadin.server.ErrorEvent event) { if (event instanceof ConnectorErrorEvent) { Component c = findComponent(((ConnectorErrorEvent) event) .getConnector()); if (c instanceof AbstractComponent) { return (AbstractComponent) c; } } return null; }
/** * Shows a terminal error. * @param event * @param application */ public static void terminalError(ErrorEvent event, LegacyApplication application) { String errorTime = Utils.getCurrentTimeAndDate(); logger.error("DefaultApplication Terminal Error (" + errorTime + "):", event.getThrowable()); String errorMessage = Constants.uiTerminalErrorMessage + "<br/><i>" + Constants.uiErrorTime + ": " + errorTime + "</i>"; if(application.getMainWindow() != null) { application.getMainWindow().showNotification(Constants.uiError, errorMessage, Notification.TYPE_ERROR_MESSAGE); } }
@Override public void error(ErrorEvent event) { Throwable t = findRelevantThrowable(event.getThrowable()); if (isSecurityException(t)) { handleSecurityException(t); return; } super.error(event); }
@Override protected void displayError(final ErrorMessage errorMessage, final ErrorEvent event) { final Notification notification = new Notification("", errorMessage.getFormattedHtmlMessage(), defaultType, true); notification.show(Page.getCurrent()); }
private static Throwable getRootExceptionFrom(final ErrorEvent event) { return getRootCauseOf(event.getThrowable()); }
@Override public void error(ErrorEvent event) { doDefault(event); }
/** * @deprecated see EnterpriseApplication.init */ @Deprecated public void terminalError(ErrorEvent event) { Utils.terminalError(event, this); }
private static Optional<Page> getPageOriginError(final ErrorEvent event) { final Component errorOrigin = findAbstractComponent(event); if (errorOrigin != null && errorOrigin.getUI() != null) { return Optional.fromNullable(errorOrigin.getUI().getPage()); } return Optional.absent(); }
/** * Displays the given error message. * * @param errorMessage error message to be displayed * @param event original error event */ protected abstract void displayError(final ErrorMessage errorMessage, final ErrorEvent event);
/** * Handle an exception. Implementation class should either handle the exception and return true, or return false * to delegate execution to the next handler in the chain of responsibility. * @param event error event containing the exception, generated by Vaadin * @param app current {@link App} instance * @return true if the exception has been successfully handled, false if not */ boolean handle(ErrorEvent event, App app);