use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class PushAtmosphereHandlerTest method setup.
@Before
public void setup() throws IOException {
request = Mockito.mock(AtmosphereRequest.class);
response = Mockito.mock(AtmosphereResponse.class);
printWriter = Mockito.mock(PrintWriter.class);
Mockito.when(response.getWriter()).thenReturn(printWriter);
resource = Mockito.mock(AtmosphereResource.class);
Mockito.when(resource.getRequest()).thenReturn(request);
Mockito.when(resource.getResponse()).thenReturn(response);
VaadinContext context = new MockVaadinContext();
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getContext()).thenReturn(context);
VaadinServletService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
PushHandler handler = new PushHandler(service);
atmosphereHandler = new PushAtmosphereHandler();
atmosphereHandler.setPushHandler(handler);
}
use of com.vaadin.flow.server.VaadinContext 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.VaadinContext in project flow by vaadin.
the class PushHandlerTest method mockBrowserLiveReloadImpl.
public static BrowserLiveReload mockBrowserLiveReloadImpl(VaadinContext context) {
BrowserLiveReload liveReload = Mockito.mock(BrowserLiveReload.class);
Lookup lookup = Lookup.of(new BrowserLiveReloadAccessor() {
@Override
public BrowserLiveReload getLiveReload(VaadinContext context) {
return liveReload;
}
}, BrowserLiveReloadAccessor.class);
context.setAttribute(Lookup.class, lookup);
return liveReload;
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class PushHandlerTest method onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled.
@Test
public void onMessage_devMode_websocket_refreshConnection_callWithUIIsNotCalled() throws ServiceException {
MockVaadinServletService service = Mockito.spy(MockVaadinServletService.class);
MockDeploymentConfiguration deploymentConfiguration = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
deploymentConfiguration.setProductionMode(false);
deploymentConfiguration.setDevModeLiveReloadEnabled(true);
deploymentConfiguration.setDevModeGizmoEnabled(true);
VaadinContext context = service.getContext();
mockBrowserLiveReloadImpl(context);
AtomicReference<AtmosphereResource> res = new AtomicReference<>();
runTest(service, (handler, resource) -> {
AtmosphereRequest request = resource.getRequest();
try {
Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("")));
} catch (IOException e) {
throw new RuntimeException(e);
}
Mockito.when(request.getParameter(ApplicationConstants.DEBUG_WINDOW_CONNECTION)).thenReturn("");
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
try {
Mockito.when(request.getReader()).thenReturn(new BufferedReader(new StringReader("{}")));
} catch (IOException e) {
throw new RuntimeException(e);
}
handler.onMessage(resource);
res.set(resource);
});
Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
}
use of com.vaadin.flow.server.VaadinContext in project flow by vaadin.
the class UidlRequestHandlerTest method writeSessionExpired.
@Test
public void writeSessionExpired() throws Exception {
ApplicationConfiguration config = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(config.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
Mockito.when(config.getBuildFolder()).thenReturn(".");
VaadinContext context = new MockVaadinContext();
Mockito.when(config.getContext()).thenReturn(context);
VaadinService service = new VaadinServletService(null, new DefaultDeploymentConfiguration(config, getClass(), new Properties()));
when(request.getService()).thenReturn(service);
when(request.getParameter(ApplicationConstants.REQUEST_TYPE_PARAMETER)).thenReturn(RequestType.UIDL.getIdentifier());
boolean result = handler.handleSessionExpired(request, response);
Assert.assertTrue("Result should be true", result);
String responseContent = CommunicationUtil.getStringWhenWriteBytesOffsetLength(outputStream);
// response shouldn't contain async
Assert.assertEquals("Invalid response", "for(;;);[{\"meta\":{\"sessionExpired\":true}}]", responseContent);
}
Aggregations