Example usage for com.vaadin.server VaadinSession setErrorHandler

List of usage examples for com.vaadin.server VaadinSession setErrorHandler

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession setErrorHandler.

Prototype

public void setErrorHandler(ErrorHandler errorHandler) 

Source Link

Document

Sets the session error handler.

Usage

From source file:com.haulmont.cuba.web.App.java

License:Apache License

/**
 * Called when <em>the first</em> UI of the session is initialized.
 *///from  w w  w.  j ava2  s.c  o  m
protected void init(Locale requestLocale) {
    VaadinSession vSession = VaadinSession.getCurrent();
    vSession.setAttribute(App.class, this);

    vSession.setLocale(messageTools.getDefaultLocale());

    // set root error handler for all session
    vSession.setErrorHandler(event -> {
        try {
            getExceptionHandlers().handle(event);
            getAppLog().log(event);
        } catch (Throwable e) {
            //noinspection ThrowableResultOfMethodCallIgnored
            log.error("Error handling exception\nOriginal exception:\n{}\nException in handlers:\n{}",
                    ExceptionUtils.getStackTrace(event.getThrowable()), ExceptionUtils.getStackTrace(e));
        }
    });

    appLog = new AppLog();

    connection = createConnection();
    exceptionHandlers = new ExceptionHandlers(this);
    cookies = new AppCookies();

    themeConstants = loadTheme();

    VaadinServlet vaadinServlet = VaadinServlet.getCurrent();
    ServletContext sc = vaadinServlet.getServletContext();
    String resourcesTimestamp = sc.getInitParameter("webResourcesTs");
    if (StringUtils.isNotEmpty(resourcesTimestamp)) {
        this.webResourceTimestamp = resourcesTimestamp;
    }

    log.debug("Initializing application");

    // get default locale from config
    Locale targetLocale = resolveLocale(requestLocale);
    setLocale(targetLocale);
}

From source file:uk.q3c.krail.core.ui.ScopedUI.java

License:Apache License

/**
 * Make sure you call this from sub-class overrides. The Vaadin Page is not available during the construction of
 * this class, but is available when this method is invoked. As a result, this method sets the navigator a listener
 * for URI changes and obtains the browser locale setting for initialising {@link CurrentLocale}. Both of these are
 * provided by the Vaadin Page.//  w  w w.  ja va  2  s.  c  om
 *
 * @see com.vaadin.ui.UI#init(com.vaadin.server.VaadinRequest)
 */
@Override
protected void init(VaadinRequest request) {

    VaadinSession session = getSession();
    session.setConverterFactory(converterFactory);

    // page isn't available during injected construction, so we have to do this here
    Page page = getPage();
    page.addUriFragmentChangedListener(navigator);

    setErrorHandler(errorHandler);
    session.setErrorHandler(errorHandler);
    page.setTitle(pageTitle());

    //  also loads the UserSitemap if not already loaded
    getKrailNavigator().init();

    //layout this UI, which may also create UYI components
    doLayout();

    // now that browser is active, and user sitemap loaded, and UI constructed, set up currentLocale
    currentLocale.readFromEnvironment();
    translator.translate(this);
    // Navigate to the correct start point
    String fragment = getPage().getUriFragment();
    getKrailNavigator().navigateTo(fragment);
}