Java Code Examples for com.vaadin.flow.server.VaadinSession#setAttribute()

The following examples show how to use com.vaadin.flow.server.VaadinSession#setAttribute() . 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: WebComponentUI.java    From flow with Apache License 2.0 6 votes vote down vote up
static SessionEmbeddedComponentRegistry getSessionRegistry(
        VaadinSession session) {
    Objects.requireNonNull(session,
            "Null session is not supported for session route registry");
    SessionEmbeddedComponentRegistry registry = session
            .getAttribute(SessionEmbeddedComponentRegistry.class);
    if (registry == null) {
        registry = new SessionEmbeddedComponentRegistry(session);
        session.setAttribute(SessionEmbeddedComponentRegistry.class,
                registry);
    }
    if (!registry.session.equals(session)) {
        throw new IllegalStateException(String.format(
                "Session has an attribute for %s registered for "
                        + "another session!",
                SessionEmbeddedComponentRegistry.class
                        .getSimpleName()));
    }
    return registry;
}
 
Example 2
Source File: AbstractNavigationStateRenderer.java    From flow with Apache License 2.0 5 votes vote down vote up
static void setPreservedChain(VaadinSession session, String windowName,
        Location location, ArrayList<HasElement> chain) {
    PreservedComponentCache cache = session
            .getAttribute(PreservedComponentCache.class);
    if (cache == null) {
        cache = new PreservedComponentCache();
    }
    cache.put(windowName, new Pair<>(location.getPath(), chain));
    session.setAttribute(PreservedComponentCache.class, cache);
}
 
Example 3
Source File: IndexHtmlRequestHandler.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public boolean synchronizedHandleRequest(VaadinSession session,
        VaadinRequest request, VaadinResponse response) throws IOException {
    Document indexDocument = getIndexHtmlDocument(request);

    prependBaseHref(request, indexDocument);

    JsonObject initialJson = Json.createObject();

    if (request.getService().getBootstrapInitialPredicate()
            .includeInitialUidl(request)) {
        includeInitialUidl(initialJson, session, request, response);

        indexHtmlResponse = new IndexHtmlResponse(request, response, indexDocument, UI.getCurrent());

        // App might be using classic server-routing, which is true
        // unless we detect a call to JavaScriptBootstrapUI.connectClient
        session.setAttribute(SERVER_ROUTING, Boolean.TRUE);
    } else {
        indexHtmlResponse = new IndexHtmlResponse(request, response, indexDocument);
    }

    addInitialFlow(initialJson, indexDocument, session);

    configureErrorDialogStyles(indexDocument);

    showWebpackErrors(indexDocument);

    response.setContentType(CONTENT_TYPE_TEXT_HTML_UTF_8);

    VaadinContext context = session.getService().getContext();
    AppShellRegistry registry = AppShellRegistry.getInstance(context);

    DeploymentConfiguration config = session.getConfiguration();
    if (!config.isProductionMode()) {
        UsageStatisticsExporter.exportUsageStatisticsToDocument(indexDocument);
    }

    // modify the page based on the @PWA annotation
    setupPwa(indexDocument, session.getService());

    // modify the page based on the @Meta, @ViewPort, @BodySize and @Inline annotations
    // and on the AppShellConfigurator
    registry.modifyIndexHtml(indexDocument, request);

    // modify the page based on registered IndexHtmlRequestListener:s
    request.getService().modifyIndexHtmlResponse(indexHtmlResponse);

    try {
        response.getOutputStream()
                .write(indexDocument.html().getBytes(UTF_8));
    } catch (IOException e) {
        getLogger().error("Error writing 'index.html' to response", e);
        return false;
    }
    return true;
}