类com.vaadin.server.ErrorEvent源码实例Demo

下面列出了怎么用com.vaadin.server.ErrorEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: cuba   文件: InvalidValueExceptionHandler.java
@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;
}
 
源代码2 项目: cuba   文件: AbstractExceptionHandler.java
@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;
}
 
源代码3 项目: hawkbit   文件: HawkbitUIErrorHandler.java
@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);
}
 
源代码4 项目: vertx-vaadin   文件: SockJSPushHandler.java
/**
 * 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);
    }
}
 
源代码5 项目: cia   文件: UiInstanceErrorHandler.java
@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());
	}
}
 
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;
}
 
源代码8 项目: jdal   文件: SecurityErrorHandler.java
@Override
public void error(ErrorEvent event) {
	Throwable t = findRelevantThrowable(event.getThrowable());
	if (isSecurityException(t)) {
		handleSecurityException(t);
		
		return;
	}
		
	super.error(event);
}
 
源代码9 项目: cuba   文件: DefaultExceptionHandler.java
@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;
}
 
源代码10 项目: hawkbit   文件: HawkbitUIErrorHandler.java
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
    return getRootCauseOf(event.getThrowable());
}
 
@Override
public void error(ErrorEvent event) {
    doDefault(event);
}
 
源代码12 项目: hawkbit   文件: HawkbitUIErrorHandler.java
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();
    }
 
源代码13 项目: cuba   文件: ExceptionHandler.java
/**
 * 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);