use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class BrowserLiveReloadAccessorImplTest method getLiveReload_liveReloadDisabled_instanceIsCreated.
@Test
public void getLiveReload_liveReloadDisabled_instanceIsCreated() {
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(config);
Mockito.when(config.isProductionMode()).thenReturn(false);
Mockito.when(config.isDevModeLiveReloadEnabled()).thenReturn(false);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(context.getAttribute(Mockito.eq(BrowserLiveReload.class), Mockito.any())).thenReturn(Mockito.mock(BrowserLiveReload.class));
Mockito.when(service.getContext()).thenReturn(context);
Assert.assertNotNull(access.getLiveReload(service));
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class BrowserLiveReloadAccessorImplTest method getLiveReload_productionMode_nullIsReturned.
@Test
public void getLiveReload_productionMode_nullIsReturned() {
VaadinService service = Mockito.mock(VaadinService.class);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(service.getDeploymentConfiguration()).thenReturn(config);
Mockito.when(config.isProductionMode()).thenReturn(true);
Assert.assertNull(access.getLiveReload(service));
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class IndexHtmlRequestHandler method addDevmodeGizmo.
private void addDevmodeGizmo(Document indexDocument, DeploymentConfiguration config, VaadinSession session, VaadinRequest request) {
VaadinService service = session.getService();
Optional<BrowserLiveReload> liveReload = BrowserLiveReloadAccessor.getLiveReloadFromService(service);
if (liveReload.isPresent()) {
Element devmodeGizmo = new Element("vaadin-devmode-gizmo");
if (!config.isDevModeLiveReloadEnabled()) {
devmodeGizmo.attr("liveReloadDisabled", "");
}
devmodeGizmo.attr("url", BootstrapHandlerHelper.getPushURL(session, request));
BrowserLiveReload.Backend backend = liveReload.get().getBackend();
if (backend != null) {
devmodeGizmo.attr("backend", backend.toString());
}
devmodeGizmo.attr("springbootlivereloadport", Integer.toString(Constants.SPRING_BOOT_DEFAULT_LIVE_RELOAD_PORT));
indexDocument.body().appendChild(devmodeGizmo);
}
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class UidlWriter method createUidl.
/**
* Creates a JSON object containing all pending changes to the given UI.
*
* @param ui
* The {@link UI} whose changes to write
* @param async
* True if this message is sent by the server asynchronously,
* false if it is a response to a client message
* @param resync
* True iff the client should be asked to resynchronize
* @return JSON object containing the UIDL response
*/
public JsonObject createUidl(UI ui, boolean async, boolean resync) {
JsonObject response = Json.createObject();
UIInternals uiInternals = ui.getInternals();
VaadinSession session = ui.getSession();
VaadinService service = session.getService();
// Purge pending access calls as they might produce additional changes
// to write out
service.runPendingAccessTasks(session);
// Paints components
getLogger().debug("* Creating response to client");
int syncId = service.getDeploymentConfiguration().isSyncIdCheckEnabled() ? uiInternals.getServerSyncId() : -1;
response.put(ApplicationConstants.SERVER_SYNC_ID, syncId);
if (resync) {
response.put(ApplicationConstants.RESYNCHRONIZE_ID, true);
}
int nextClientToServerMessageId = uiInternals.getLastProcessedClientToServerId() + 1;
response.put(ApplicationConstants.CLIENT_TO_SERVER_ID, nextClientToServerMessageId);
SystemMessages messages = service.getSystemMessages(ui.getLocale(), null);
JsonObject meta = new MetadataWriter().createMetadata(ui, false, async, messages);
if (meta.keys().length > 0) {
response.put("meta", meta);
}
JsonArray stateChanges = Json.createArray();
encodeChanges(ui, stateChanges);
populateDependencies(response, uiInternals.getDependencyList(), new ResolveContext(service, session.getBrowser()));
if (uiInternals.getConstantPool().hasNewConstants()) {
response.put("constants", uiInternals.getConstantPool().dumpConstants());
}
if (stateChanges.length() != 0) {
response.put("changes", stateChanges);
}
List<PendingJavaScriptInvocation> executeJavaScriptList = uiInternals.dumpPendingJavaScriptInvocations();
if (!executeJavaScriptList.isEmpty()) {
response.put(JsonConstants.UIDL_KEY_EXECUTE, encodeExecuteJavaScriptList(executeJavaScriptList));
}
if (service.getDeploymentConfiguration().isRequestTiming()) {
response.put("timings", createPerformanceData(ui));
}
uiInternals.incrementServerId();
return response;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class UidlWriter method getInlineResourceStream.
private static InputStream getInlineResourceStream(String url, ResolveContext context) {
VaadinService service = context.getService();
InputStream stream = service.getResourceAsStream(url);
if (stream == null) {
String resolvedPath = service.resolveResource(url);
getLogger().warn("The path '{}' for inline resource " + "has been resolved to '{}'. " + "But resource is not available via the servlet context. " + "Trying to load '{}' as a URL", url, resolvedPath, url);
try {
stream = new URL(url).openConnection().getInputStream();
} catch (MalformedURLException exception) {
throw new IllegalStateException(String.format("The path '%s' is not a valid URL. " + "Unable to fetch a resource addressed by it.", url), exception);
} catch (IOException e) {
throw new IllegalStateException(String.format(COULD_NOT_READ_URL_CONTENTS_ERROR_MESSAGE, url), e);
}
} else if (getLogger().isDebugEnabled()) {
String resolvedPath = service.resolveResource(url);
getLogger().debug("The path '{}' for inline resource has been successfully " + "resolved to resource URL '{}'", url, resolvedPath);
}
return stream;
}
Aggregations