Search in sources :

Example 1 with VaadinSession

use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.

the class VaadinSessionScope method getBeanStore.

@Override
protected BeanStore getBeanStore() {
    final VaadinSession session = getVaadinSession();
    session.lock();
    try {
        BeanStore beanStore = session.getAttribute(BeanStore.class);
        if (beanStore == null) {
            beanStore = new SessionBeanStore(session);
            session.setAttribute(BeanStore.class, beanStore);
        }
        return beanStore;
    } finally {
        session.unlock();
    }
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) SpringVaadinSession(com.vaadin.flow.spring.SpringVaadinSession)

Example 2 with VaadinSession

use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.

the class VaadinUIScope method getBeanStore.

@Override
protected BeanStore getBeanStore() {
    final VaadinSession session = getVaadinSession();
    session.lock();
    try {
        UIStoreWrapper wrapper = session.getAttribute(UIStoreWrapper.class);
        if (wrapper == null) {
            wrapper = new UIStoreWrapper(session);
            session.setAttribute(UIStoreWrapper.class, wrapper);
        }
        return wrapper.getBeanStore(getUI());
    } finally {
        session.unlock();
    }
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) SpringVaadinSession(com.vaadin.flow.spring.SpringVaadinSession)

Example 3 with VaadinSession

use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.

the class VaadinUIScopeTest method mockUI.

private UI mockUI() {
    VaadinSession session = mockSession();
    RouterInterface routerIface = mock(RouterInterface.class);
    VaadinService service = session.getService();
    when(service.getRouter()).thenReturn(routerIface);
    ImmutableRouterConfiguration config = mock(ImmutableRouterConfiguration.class);
    when(routerIface.getConfiguration()).thenReturn(config);
    when(config.isConfigured()).thenReturn(false);
    UI ui = new UI();
    ui.getInternals().setSession(session);
    ui.doInit(null, 1);
    UI.setCurrent(ui);
    // prevent UI from being GCed.
    this.ui = ui;
    return ui;
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) SpringVaadinSession(com.vaadin.flow.spring.SpringVaadinSession) UI(com.vaadin.flow.component.UI) VaadinService(com.vaadin.flow.server.VaadinService) ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) RouterInterface(com.vaadin.flow.router.RouterInterface)

Example 4 with VaadinSession

use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.

the class InfoView method update.

private void update(UI ui) {
    VaadinSession session = ui.getSession();
    WebBrowser webBrowser = session.getBrowser();
    DeploymentConfiguration deploymentConfiguration = session.getConfiguration();
    List<String> device = new ArrayList<>();
    List<String> os = new ArrayList<>();
    List<String> browser = new ArrayList<>();
    removeAll();
    add(new NativeButton("Refresh", e -> {
        update(ui);
    }));
    header("Browser");
    info("Address", webBrowser.getAddress());
    add(device, "Android", webBrowser.isAndroid());
    add(device, "iOS", webBrowser.isIOS());
    add(device, "iPad", webBrowser.isIPad());
    add(device, "iPhone", webBrowser.isIPhone());
    add(device, "Windows Phone", webBrowser.isWindowsPhone());
    info("Device", device.stream().collect(Collectors.joining(", ")));
    add(os, "Linux", webBrowser.isLinux());
    add(os, "Mac", webBrowser.isMacOSX());
    add(os, "Windows", webBrowser.isWindows());
    info("Os", os.stream().collect(Collectors.joining(", ")));
    add(browser, "Touch device", webBrowser.isTouchDevice());
    add(browser, "Chrome", webBrowser.isChrome());
    add(browser, "Edge", webBrowser.isEdge());
    add(browser, "Firefox", webBrowser.isFirefox());
    add(browser, "IE", webBrowser.isIE());
    add(browser, "Safari", webBrowser.isSafari());
    info("Browser", browser.stream().collect(Collectors.joining(", ")));
    if (webBrowser.isTooOldToFunctionProperly()) {
        header("Browser is too old to function properly");
    }
    info("User-agent", webBrowser.getBrowserApplication());
    info("Browser major", webBrowser.getBrowserMajorVersion());
    info("Browser minor", webBrowser.getBrowserMinorVersion());
    info("Screen height", webBrowser.getScreenHeight());
    info("Screen width", webBrowser.getScreenWidth());
    info("Locale", webBrowser.getLocale());
    info("Secure connection (https)", webBrowser.isSecureConnection());
    separator();
    header("Push configuration");
    info("Push mode", ui.getPushConfiguration().getPushMode());
    info("Push transport", ui.getPushConfiguration().getTransport());
    separator();
    header("Deployment configuration");
    info("Heartbeat interval", deploymentConfiguration.getHeartbeatInterval());
    info("Router configurator class", deploymentConfiguration.getRouterConfiguratorClassName());
    info("UI class", deploymentConfiguration.getUIClassName());
    info("Close idle sessions", deploymentConfiguration.isCloseIdleSessions());
    info("Send URLs as parameters", deploymentConfiguration.isSendUrlsAsParameters());
    info("Sync id enabled", deploymentConfiguration.isSyncIdCheckEnabled());
    info("XSRF protection enabled", deploymentConfiguration.isXsrfProtectionEnabled());
    info("Production mode", deploymentConfiguration.isProductionMode());
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) Html(com.vaadin.flow.component.Html) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ViewTestLayout(com.vaadin.flow.uitest.servlet.ViewTestLayout) Hr(com.vaadin.flow.component.html.Hr) Collectors(java.util.stream.Collectors) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) WebBrowser(com.vaadin.flow.server.WebBrowser) UI(com.vaadin.flow.component.UI) AttachEvent(com.vaadin.flow.component.AttachEvent) NativeButton(com.vaadin.flow.component.html.NativeButton) VaadinSession(com.vaadin.flow.server.VaadinSession) WebBrowser(com.vaadin.flow.server.WebBrowser) ArrayList(java.util.ArrayList) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 5 with VaadinSession

use of com.vaadin.flow.server.VaadinSession in project flow by vaadin.

the class MockUI method findOrcreateSession.

private static VaadinSession findOrcreateSession() {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null) {
        session = new AlwaysLockedVaadinSession(null);
        VaadinSession.setCurrent(session);
    }
    return session;
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession)

Aggregations

VaadinSession (com.vaadin.flow.server.VaadinSession)26 UI (com.vaadin.flow.component.UI)9 VaadinService (com.vaadin.flow.server.VaadinService)9 Before (org.junit.Before)6 DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)4 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)4 SpringVaadinSession (com.vaadin.flow.spring.SpringVaadinSession)4 Test (org.junit.Test)4 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 SessionExpiredException (com.vaadin.flow.server.SessionExpiredException)2 SystemMessages (com.vaadin.flow.server.SystemMessages)2 VaadinServlet (com.vaadin.flow.server.VaadinServlet)2 VaadinServletService (com.vaadin.flow.server.VaadinServletService)2 InvalidUIDLSecurityKeyException (com.vaadin.flow.server.communication.ServerRpcHandler.InvalidUIDLSecurityKeyException)2 PushMode (com.vaadin.flow.shared.communication.PushMode)2 JsonException (elemental.json.JsonException)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Field (java.lang.reflect.Field)2