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;
}
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\\.\\-]+$"));
}
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));
}
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;
}
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);
}
Aggregations