Search in sources :

Example 1 with AppShellRegistry

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

the class JavaScriptBootstrapHandler method createAndInitUI.

@Override
protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) {
    BootstrapContext context = super.createAndInitUI(JavaScriptBootstrapUI.class, request, response, session);
    JsonObject config = context.getApplicationParameters();
    String requestURL = getRequestUrl(request);
    String serviceUrl = getServiceUrl(request);
    String pushURL = context.getSession().getConfiguration().getPushURL();
    if (pushURL == null) {
        pushURL = serviceUrl;
    }
    PushConfiguration pushConfiguration = context.getUI().getPushConfiguration();
    pushConfiguration.setPushUrl(pushURL);
    AppShellRegistry registry = AppShellRegistry.getInstance(session.getService().getContext());
    registry.modifyPushConfiguration(pushConfiguration);
    config.put("requestURL", requestURL);
    return context;
}
Also used : PushConfiguration(com.vaadin.flow.component.PushConfiguration) JsonObject(elemental.json.JsonObject) AppShellRegistry(com.vaadin.flow.server.AppShellRegistry)

Example 2 with AppShellRegistry

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

the class JavaScriptBootstrapHandlerTest method should_respondPushScript_when_annotatedInAppShell.

@Test
public void should_respondPushScript_when_annotatedInAppShell() throws Exception {
    VaadinServletContext context = new VaadinServletContext(mocks.getServletContext());
    AppShellRegistry registry = AppShellRegistry.getInstance(context);
    registry.setShell(PushAppShell.class);
    mocks.setAppShellRegistry(registry);
    VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&foo&location");
    jsInitHandler.handleRequest(session, request, response);
    Assert.assertEquals(200, response.getErrorCode());
    Assert.assertEquals("application/json", response.getContentType());
    JsonObject json = Json.parse(response.getPayload());
    // Using regex, because version depends on the build
    Assert.assertTrue(json.getString("pushScript").matches("^\\./VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) JsonObject(elemental.json.JsonObject) VaadinRequest(com.vaadin.flow.server.VaadinRequest) AppShellRegistry(com.vaadin.flow.server.AppShellRegistry) Test(org.junit.Test)

Example 3 with AppShellRegistry

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

the class JavaScriptBootstrapHandlerTest method should_invoke_modifyPushConfiguration.

@Test
public void should_invoke_modifyPushConfiguration() throws Exception {
    AppShellRegistry registry = Mockito.mock(AppShellRegistry.class);
    mocks.setAppShellRegistry(registry);
    VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&foo&location=");
    jsInitHandler.handleRequest(session, request, response);
    Mockito.verify(registry).modifyPushConfiguration(Mockito.any(PushConfiguration.class));
}
Also used : PushConfiguration(com.vaadin.flow.component.PushConfiguration) VaadinRequest(com.vaadin.flow.server.VaadinRequest) AppShellRegistry(com.vaadin.flow.server.AppShellRegistry) Test(org.junit.Test)

Example 4 with AppShellRegistry

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

the class IndexHtmlRequestHandler method synchronizedHandleRequest.

@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    if (writeErrorCodeIfRequestLocationIsInvalid(request, response)) {
        return true;
    }
    DeploymentConfiguration config = session.getConfiguration();
    IndexHtmlResponse indexHtmlResponse;
    Document indexDocument = config.isProductionMode() ? getCachedIndexHtmlDocument(request.getService()) : getIndexHtmlDocument(request.getService());
    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, request);
    configureErrorDialogStyles(indexDocument);
    showWebpackErrors(session.getService(), indexDocument);
    response.setContentType(CONTENT_TYPE_TEXT_HTML_UTF_8);
    VaadinContext context = session.getService().getContext();
    AppShellRegistry registry = AppShellRegistry.getInstance(context);
    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);
    // the bootstrap page title could be used as a fallback title to
    // a server-side route that doesn't have a title
    storeAppShellTitleToUI(indexDocument);
    // modify the page based on registered IndexHtmlRequestListener:s
    request.getService().modifyIndexHtmlResponse(indexHtmlResponse);
    if (config.isDevModeGizmoEnabled()) {
        addDevmodeGizmo(indexDocument, config, session, request);
        catchErrorsInDevMode(indexDocument);
    }
    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;
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) JsonObject(elemental.json.JsonObject) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Document(org.jsoup.nodes.Document) AppShellRegistry(com.vaadin.flow.server.AppShellRegistry) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 5 with AppShellRegistry

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

the class IndexHtmlRequestHandlerTest method should_throwUnSupportedException_when_usingAppShellToConfigureLoadingIndicator.

@Test(expected = UnsupportedOperationException.class)
public void should_throwUnSupportedException_when_usingAppShellToConfigureLoadingIndicator() throws Exception {
    // Set class in context and do not call initializer
    AppShellRegistry registry = AppShellRegistry.getInstance(context);
    registry.setShell(MyAppShellWithLoadingIndicatorConfig.class);
    mocks.setAppShellRegistry(registry);
    indexHtmlRequestHandler.synchronizedHandleRequest(session, createVaadinRequest("/"), response);
}
Also used : AppShellRegistry(com.vaadin.flow.server.AppShellRegistry) Test(org.junit.Test)

Aggregations

AppShellRegistry (com.vaadin.flow.server.AppShellRegistry)11 Test (org.junit.Test)8 JsonObject (elemental.json.JsonObject)3 Document (org.jsoup.nodes.Document)3 PushConfiguration (com.vaadin.flow.component.PushConfiguration)2 VaadinContext (com.vaadin.flow.server.VaadinContext)2 VaadinRequest (com.vaadin.flow.server.VaadinRequest)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2 Elements (org.jsoup.select.Elements)2 AppShellConfigurator (com.vaadin.flow.component.page.AppShellConfigurator)1 BodySize (com.vaadin.flow.component.page.BodySize)1 Inline (com.vaadin.flow.component.page.Inline)1 Meta (com.vaadin.flow.component.page.Meta)1 Push (com.vaadin.flow.component.page.Push)1 Viewport (com.vaadin.flow.component.page.Viewport)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 PageTitle (com.vaadin.flow.router.PageTitle)1 ERROR_HEADER_NO_APP_CONFIGURATOR (com.vaadin.flow.server.AppShellRegistry.ERROR_HEADER_NO_APP_CONFIGURATOR)1 ERROR_HEADER_NO_SHELL (com.vaadin.flow.server.AppShellRegistry.ERROR_HEADER_NO_SHELL)1 ERROR_HEADER_OFFENDING_CONFIGURATOR (com.vaadin.flow.server.AppShellRegistry.ERROR_HEADER_OFFENDING_CONFIGURATOR)1