List of usage examples for com.vaadin.server DefaultErrorHandler DefaultErrorHandler
DefaultErrorHandler
From source file:by.bigvova.MainUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { EventBus.register(this); getPage().setTitle("FoodNote"); UI.getCurrent().setLocale(Locale.forLanguageTag("ru-RU")); // Let's register a custom error handler to make the 'access denied' messages a bit friendlier. setErrorHandler(new DefaultErrorHandler() { @Override//from w ww . j a va 2s .c om public void error(com.vaadin.server.ErrorEvent event) { if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) { Notification.show("Sorry, you don't have access to do that."); } else { super.error(event); } } }); HorizontalLayout layout = new HorizontalLayout(); layout.setSizeFull(); // By adding a security item filter, only views that are accessible to the user will show up in the side bar. sideBar.setItemFilter(new VaadinSecurityItemFilter(vaadinSecurity)); sideBar.setHeader(new CssLayout() { { Label header = new Label("<span>Food</span>Note", ContentMode.HTML); header.setWidth(100, Unit.PERCENTAGE); header.setHeightUndefined(); addComponent(header); addComponent(buildUserMenu()); } }); sideBar.getHeader().setStyleName("branding"); layout.addComponent(sideBar); CssLayout viewContainer = new CssLayout(); viewContainer.setSizeFull(); layout.addComponent(viewContainer); layout.setExpandRatio(viewContainer, 1f); Navigator navigator = new Navigator(this, viewContainer); // Without an AccessDeniedView, the view provider would act like the restricted views did not exist at all. springViewProvider.setAccessDeniedViewClass(AccessDeniedView.class); navigator.addProvider(springViewProvider); navigator.setErrorView(ErrorView.class); navigator.navigateTo(navigator.getState()); setContent(layout); // Call this here because the Navigator must have been configured before the Side Bar can be attached to a UI. }
From source file:com.esofthead.mycollab.mobile.MobileApplication.java
License:Open Source License
@Override protected void init(VaadinRequest request) { LOG.debug("Init mycollab mobile application {}", this.toString()); VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override/*from w ww. j av a 2s . c o m*/ public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); IgnoreException ignoreException = (IgnoreException) getExceptionType(e, IgnoreException.class); if (ignoreException != null) { return; } SessionExpireException sessionExpireException = (SessionExpireException) getExceptionType(e, SessionExpireException.class); if (sessionExpireException != null) { Page.getCurrent().getJavaScript().execute("window.location.reload();"); return; } UserInvalidInputException invalidException = (UserInvalidInputException) getExceptionType(e, UserInvalidInputException.class); if (invalidException != null) { NotificationUtil.showWarningNotification(AppContext .getMessage(GenericI18Enum.ERROR_USER_INPUT_MESSAGE, invalidException.getMessage())); } else { UsageExceedBillingPlanException usageBillingException = (UsageExceedBillingPlanException) getExceptionType( e, UsageExceedBillingPlanException.class); if (usageBillingException != null) { if (AppContext.isAdmin()) { ConfirmDialog.show(UI.getCurrent(), AppContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_ADMIN), AppContext.getMessage(GenericI18Enum.BUTTON_YES), AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.CloseListener() { private static final long serialVersionUID = 1L; @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { Collection<Window> windowsList = UI.getCurrent().getWindows(); for (Window window : windowsList) { window.close(); } EventBusFactory.getInstance() .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "billing" })); } } }); } else { NotificationUtil.showErrorNotification( AppContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_USER)); } } else { LOG.error("Error", e); NotificationUtil.showErrorNotification( AppContext.getMessage(GenericI18Enum.ERROR_USER_NOTICE_INFORMATION_MESSAGE)); } } } }); initialUrl = this.getPage().getUriFragment(); MyCollabSession.putVariable(CURRENT_APP, this); currentContext = new AppContext(); postSetupApp(request); try { currentContext.initDomain(initialSubDomain); } catch (Exception e) { // TODO: show content notice user there is no existing domain return; } this.getLoadingIndicatorConfiguration().setFirstDelay(0); this.getLoadingIndicatorConfiguration().setSecondDelay(300); this.getLoadingIndicatorConfiguration().setThirdDelay(500); final MobileNavigationManager manager = new MobileNavigationManager(); manager.addNavigationListener(new NavigationManager.NavigationListener() { private static final long serialVersionUID = -2317588983851761998L; @SuppressWarnings("unchecked") @Override public void navigate(NavigationEvent event) { NavigationManager currentNavigator = (NavigationManager) event.getSource(); if (event.getDirection() == Direction.BACK) { Component nextComponent = currentNavigator.getNextComponent(); ViewState currentState = MobileHistoryViewManager.peak(); if (!(currentState instanceof NullViewState) && currentState.getPresenter().getView().equals(nextComponent)) { ViewState viewState = MobileHistoryViewManager.pop(); while (!(viewState instanceof NullViewState)) { if (viewState.getPresenter().getView().equals(currentNavigator.getCurrentComponent())) { viewState.getPresenter().go(viewState.getContainer(), viewState.getParams()); break; } viewState = MobileHistoryViewManager.pop(false); } } if (nextComponent instanceof NavigationView) { ((NavigationView) nextComponent).setPreviousComponent(null); } currentNavigator.removeComponent(nextComponent); currentNavigator.getState().setNextComponent(null); } } }); setContent(manager); registerControllers(manager); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { private static final long serialVersionUID = -6410955178515535406L; @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { setInitialUrl(event.getUriFragment()); enter(event.getUriFragment()); } }); enter(initialUrl); }
From source file:com.esofthead.mycollab.web.DesktopApplication.java
License:Open Source License
@Override protected void init(VaadinRequest request) { LOG.debug("Init mycollab application {} associate with session {}", this.toString(), VaadinSession.getCurrent()); LOG.debug("Register default error handler"); VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override//from w w w .j a v a2s . c om public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); handleException(e); } }); initialUrl = this.getPage().getUriFragment(); MyCollabSession.putVariable(CURRENT_APP, this); currentContext = new AppContext(); postSetupApp(request); try { currentContext.initDomain(initialSubDomain); } catch (SubDomainNotExistException e) { this.setContent(new NoSubDomainExistedWindow(initialSubDomain)); return; } mainWindowContainer = new MainWindowContainer(); this.setContent(mainWindowContainer); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { private static final long serialVersionUID = 1L; @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { enter(event.getUriFragment()); } }); EventBusFactory.getInstance().register(new ShellErrorHandler()); String userAgent = request.getHeader("user-agent"); if (isInNotSupportedBrowserList(userAgent.toLowerCase())) { NotificationUtil .showWarningNotification("Your browser is out of date. Some features of MyCollab will not" + " behave correctly. You should upgrade to the newer browser."); } }
From source file:com.foc.vaadin.FocWebApplication.java
License:Apache License
public void initialize(VaadinRequest vaadinRequest, ServletContext servletContext, HttpSession httpSession, boolean webServicesOnly) { // setTheme(FocVaadinTheme.THEME_NAME); // Page.getCurrent().setUriFragment("01barmaja"); Globals.logString("FocWebApplication.init 111"); setErrorHandler(new DefaultErrorHandler() { @Override//from ww w . ja va 2 s. c o m public void error(com.vaadin.server.ErrorEvent event) { Globals.logString("Error - 1"); Throwable throwable = event != null ? event.getThrowable() : null; Globals.logString("Error - 2"); if (throwable != null && throwable instanceof Exception) { Globals.logString("Error - 3"); Globals.logException((Exception) throwable); Globals.logString("Error - 4"); } // Do the default error handling (optional) doDefault(event); } }); String userAgent = vaadinRequest != null ? vaadinRequest.getHeader("User-Agent") : null; isMobile = Utils.isMobile(userAgent); Globals.logString("FocWebApplication.init 2"); // isMobile = Globals.isTouchDevice(); String path = vaadinRequest != null ? vaadinRequest.getPathInfo() : null; Globals.logString("FocWebApplication.init 3"); if (path != null && !path.isEmpty() && path.length() > 1) { path = path.substring(1); isMobile = path.toLowerCase().trim().equals("m"); } Globals.logString("FocWebApplication.init 4"); addStyleName("focMainWindow"); Globals.logString("FocWebApplication.init 5"); // FocWebApplication.setInstanceForThread(this); setSessionIfEmpty(httpSession); Globals.logString("FocWebApplication.init 6"); startApplicationServer(servletContext, webServicesOnly); Globals.logString("FocWebApplication.init 7"); FocWebServer focWebServer = FocWebServer.getInstance(); if (focWebServer == null) { Globals.logString("FocWebApplication.init 8 - SERVER IS NULL"); } else { Globals.logString("FocWebApplication.init 8 - SERVER OK"); } focWebServer.addApplication(this); Globals.logString("FocWebApplication.init 9"); }
From source file:com.mycollab.mobile.MobileApplication.java
License:Open Source License
@Override protected void init(VaadinRequest request) { OfflineMode offlineMode = new OfflineMode(); offlineMode.extend(this); // Maintain the session when the browser app closes offlineMode.setPersistentSessionCookie(true); // Define the timeout in secs to wait when a server // request is sent before falling back to offline mode offlineMode.setOfflineModeTimeout(15); VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override//from www .j a va2 s .co m public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); IgnoreException ignoreException = (IgnoreException) getExceptionType(e, IgnoreException.class); if (ignoreException != null) { return; } SessionExpireException sessionExpireException = (SessionExpireException) getExceptionType(e, SessionExpireException.class); if (sessionExpireException != null) { Page.getCurrent().getJavaScript().execute("window.location.reload();"); return; } UserInvalidInputException invalidException = (UserInvalidInputException) getExceptionType(e, UserInvalidInputException.class); if (invalidException != null) { NotificationUtil.showWarningNotification(UserUIContext .getMessage(GenericI18Enum.ERROR_USER_INPUT_MESSAGE, invalidException.getMessage())); } else { UsageExceedBillingPlanException usageBillingException = (UsageExceedBillingPlanException) getExceptionType( e, UsageExceedBillingPlanException.class); if (usageBillingException != null) { if (UserUIContext.isAdmin()) { ConfirmDialog.show(UI.getCurrent(), UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_ADMIN), UserUIContext.getMessage(GenericI18Enum.BUTTON_YES), UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), dialog -> { if (dialog.isConfirmed()) { Collection<Window> windows = UI.getCurrent().getWindows(); for (Window window : windows) { window.close(); } EventBusFactory.getInstance().post(new ShellEvent.GotoUserAccountModule( this, new String[] { "billing" })); } }); } else { NotificationUtil.showErrorNotification( UserUIContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_USER)); } } else { LOG.error("Error", e); NotificationUtil.showErrorNotification( UserUIContext.getMessage(GenericI18Enum.ERROR_USER_NOTICE_INFORMATION_MESSAGE)); } } } }); setCurrentFragmentUrl(this.getPage().getUriFragment()); currentContext = new UserUIContext(); postSetupApp(request); final NavigationManager manager = new NavigationManager(); setContent(manager); registerControllers(manager); ThemeManager.loadMobileTheme(MyCollabUI.getAccountId()); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { private static final long serialVersionUID = -6410955178515535406L; @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { setCurrentFragmentUrl(event.getUriFragment()); enter(event.getUriFragment()); } }); detectAutoLogin(); }
From source file:com.mycollab.web.DesktopApplication.java
License:Open Source License
@Override protected void init(final VaadinRequest request) { broadcastReceiverService = AppContextUtil.getSpringBean(BroadcastReceiverService.class); if (SiteConfiguration.getPullMethod() == SiteConfiguration.PullMethod.push) { getPushConfiguration().setPushMode(PushMode.MANUAL); }/*from www . j a v a 2 s .c o m*/ VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override public void error(com.vaadin.server.ErrorEvent event) { Throwable e = event.getThrowable(); handleException(request, e); } }); setCurrentFragmentUrl(this.getPage().getUriFragment()); currentContext = new UserUIContext(); postSetupApp(request); EventBusFactory.getInstance().register(new ShellErrorHandler()); mainWindowContainer = new MainWindowContainer(); this.setContent(mainWindowContainer); getPage().setTitle("MyCollab - Online project management"); getPage().addUriFragmentChangedListener( uriFragmentChangedEvent -> enter(uriFragmentChangedEvent.getUriFragment())); String userAgent = request.getHeader("user-agent"); if (isInNotSupportedBrowserList(userAgent.toLowerCase())) { NotificationUtil.showWarningNotification(UserUIContext.getMessage(ErrorI18nEnum.BROWSER_OUT_UP_DATE)); } }
From source file:edu.kit.dama.ui.admin.AdminUIMainView.java
License:Apache License
private void doBasicSetup() { //configure SiMon try {//from ww w. j a va 2s . c o m String path = DataManagerSettings.getSingleton() .getStringProperty(DataManagerSettings.SIMON_CONFIG_LOCATION_ID, null); if (path == null || !new File(path).exists()) { throw new ConfigurationException("Configuration element '" + DataManagerSettings.SIMON_CONFIG_LOCATION_ID + "' is not set or not a valid directory."); } File configLocation = new File(path); SimonConfigurator.getSingleton().setConfigLocation(configLocation); } catch (ConfigurationException ex) { LOGGER.error("Failed to initialize SimpleMonitoring", ex); } //set error handler in order to catch unhandled exceptions UI.getCurrent().setErrorHandler(new DefaultErrorHandler() { @Override public void error(com.vaadin.server.ErrorEvent event) { String cause = "<h3>An unexpected error has occured. Please reload the page.<br/>" + "If the error persists, please contact an administrator.</h3>"; Label errorLabel = new Label(cause, ContentMode.HTML); errorLabel.setDescription(StackTraceUtil.getCustomStackTrace(event.getThrowable(), false)); LOGGER.error("An unhandled exception has occured!", event.getThrowable()); // Display the error message in a custom fashion mainLayout.addComponent(errorLabel, 0); // Do the default error handling (optional) doDefault(event); } }); }
From source file:fr.amapj.view.engine.ui.AmapUI.java
License:Open Source License
/** * Gestion des erreurs//from w w w. j av a2s . c o m */ private void setErrorHandling() { setErrorHandler(new DefaultErrorHandler() { @Override public void error(com.vaadin.server.ErrorEvent event) { Throwable t = event.getThrowable(); ErrorPopup.open(t); } }); }
From source file:org.bitpimp.VaadinCurrencyConverter.MyVaadinApplication.java
License:Apache License
@Override protected void init(VaadinRequest request) { // Set the window or tab title getPage().setTitle("Yahoo Currency Converter"); // Create the content root layout for the UI final FormLayout content = new FormLayout(); content.setMargin(true);//from www .j av a 2 s . co m final Panel panel = new Panel(content); panel.setWidth("500"); panel.setHeight("400"); final VerticalLayout root = new VerticalLayout(); root.addComponent(panel); root.setComponentAlignment(panel, Alignment.MIDDLE_CENTER); root.setSizeFull(); root.setMargin(true); setContent(root); content.addComponent(new Embedded("", new ExternalResource("https://vaadin.com/vaadin-theme/images/vaadin/vaadin-logo-color.png"))); content.addComponent(new Embedded("", new ExternalResource("http://images.wikia.com/logopedia/images/e/e4/YahooFinanceLogo.png"))); // Display the greeting final Label heading = new Label("<b>Simple Currency Converter " + "Using YQL/Yahoo Finance Service</b>", ContentMode.HTML); heading.setWidth(null); content.addComponent(heading); // Build the set of fields for the converter form final TextField fromField = new TextField("From Currency", "AUD"); fromField.setRequired(true); fromField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false)); content.addComponent(fromField); final TextField toField = new TextField("To Currency", "USD"); toField.setRequired(true); toField.addValidator(new StringLengthValidator(CURRENCY_CODE_REQUIRED, 3, 3, false)); content.addComponent(toField); final TextField resultField = new TextField("Result"); resultField.setEnabled(false); content.addComponent(resultField); final TextField timeField = new TextField("Time"); timeField.setEnabled(false); content.addComponent(timeField); final Button submitButton = new Button("Submit", new ClickListener() { @Override public void buttonClick(ClickEvent event) { // Do the conversion final String result = converter.convert(fromField.getValue().toUpperCase(), toField.getValue().toUpperCase()); if (result != null) { resultField.setValue(result); timeField.setValue(new Date().toString()); } } }); content.addComponent(submitButton); // Configure the error handler for the UI UI.getCurrent().setErrorHandler(new DefaultErrorHandler() { @Override public void error(com.vaadin.server.ErrorEvent event) { // Find the final cause String cause = "<b>The operation failed :</b><br/>"; Throwable th = Throwables.getRootCause(event.getThrowable()); if (th != null) cause += th.getClass().getName() + "<br/>"; // Display the error message in a custom fashion content.addComponent(new Label(cause, ContentMode.HTML)); // Do the default error handling (optional) doDefault(event); } }); }
From source file:org.freakz.hokan_ng_springboot.bot.SingleSecuredUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { uiServiceMessageHandler.register(this); getPage().setTitle("Hokan"); // Let's register a custom error handler to make the 'access denied' messages a bit friendlier. setErrorHandler(new DefaultErrorHandler() { @Override/*from w w w . ja v a2 s . com*/ public void error(com.vaadin.server.ErrorEvent event) { if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) { Notification.show("Sorry, you don't have access to do that."); } else { super.error(event); } } }); if (vaadinSecurity.isAuthenticated()) { showMainScreen(); } else { showLoginScreen(request.getParameter("goodbye") != null); } }