com.vaadin.server.ErrorEvent Java Examples

The following examples show how to use com.vaadin.server.ErrorEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidValueExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(ErrorEvent event, App app) {
    boolean handled = super.handle(event, app);

    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();
        }
    }
    return handled;
}
 
Example #2
Source File: AbstractExceptionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handle(ErrorEvent event, App app) {
    Throwable exception = event.getThrowable();
    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;
}
 
Example #3
Source File: HawkbitUIErrorHandler.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void error(final ErrorEvent event) {

    // filter upload exceptions
    if (event.getThrowable() instanceof UploadException) {
        return;
    }

    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);
}
 
Example #4
Source File: SockJSPushHandler.java    From vertx-vaadin with MIT License 5 votes vote down vote up
/**
 * 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
        logger.warn("ErrorHandler call failed", ex);
    }
}
 
Example #5
Source File: UiInstanceErrorHandler.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public void error(final ErrorEvent event) {
	if (ExceptionUtils.getRootCause(event.getThrowable()) instanceof AccessDeniedException) {
		final AccessDeniedException accessDeniedException = (AccessDeniedException) ExceptionUtils.getRootCause(event.getThrowable());
		Notification.show(accessDeniedException.getMessage(), Notification.Type.ERROR_MESSAGE);
		ui.getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
	} else {
		LOGGER.warn(LOG_WARN_VAADIN_ERROR, event.getThrowable());
	}
}
 
Example #6
Source File: SpringSecurityErrorHandler.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: SpringSecurityErrorHandler.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: SecurityErrorHandler.java    From jdal with Apache License 2.0 5 votes vote down vote up
@Override
public void error(ErrorEvent event) {
	Throwable t = findRelevantThrowable(event.getThrowable());
	if (isSecurityException(t)) {
		handleSecurityException(t);
		
		return;
	}
		
	super.error(event);
}
 
Example #9
Source File: DefaultExceptionHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handle(ErrorEvent event, App app) {
    // Copied from com.vaadin.server.DefaultErrorHandler.doDefault()

    Throwable t = event.getThrowable();
    if (t instanceof SocketException
            || ExceptionUtils.getRootCause(t) instanceof SocketException) {
        // Most likely client browser closed socket
        return true;
    }

    // if it is UberJar or deployed to Jetty
    if (ExceptionUtils.getThrowableList(t).stream()
            .anyMatch(o -> o.getClass().getName().equals("org.eclipse.jetty.io.EofException"))) {
        // 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, ui, t);
        } else {
            showNotification(app, ui, t);
        }
    }

    // default handler always return true
    return true;
}
 
Example #10
Source File: HawkbitUIErrorHandler.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
    return getRootCauseOf(event.getThrowable());
}
 
Example #11
Source File: SpringSecurityErrorHandler.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 4 votes vote down vote up
@Override
public void error(ErrorEvent event) {
    doDefault(event);
}
 
Example #12
Source File: HawkbitUIErrorHandler.java    From hawkbit with Eclipse Public License 1.0 3 votes vote down vote up
private static Optional<Page> getPageOriginError(final ErrorEvent event) {

        final Component errorOrigin = findAbstractComponent(event);

        if (errorOrigin != null && errorOrigin.getUI() != null) {
            return Optional.ofNullable(errorOrigin.getUI().getPage());
        }

        return Optional.empty();
    }
 
Example #13
Source File: ExceptionHandler.java    From cuba with Apache License 2.0 2 votes vote down vote up
/**
 * 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);