Search in sources :

Example 16 with VaadinServletRequest

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

the class IndexHtmlRequestHandlerTest method createRequestWithDestination.

private VaadinServletRequest createRequestWithDestination(String pathInfo, String fetchDest, String fetchMode) {
    VaadinServletRequest req = createVaadinRequest(pathInfo);
    Mockito.when(req.getHeader(Mockito.anyString())).thenAnswer(arg -> {
        if ("Sec-Fetch-Dest".equals(arg.getArgument(0))) {
            return fetchDest;
        } else if ("Sec-Fetch-Mode".equals(arg.getArgument(0))) {
            return fetchMode;
        }
        return null;
    });
    return req;
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest)

Example 17 with VaadinServletRequest

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

the class IndexHtmlRequestHandlerTest method serviceWorkerRequest_canNotHandleRequest.

@Test
public void serviceWorkerRequest_canNotHandleRequest() {
    IndexHtmlRequestHandler bootstrapHandler = new IndexHtmlRequestHandler();
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    Mockito.when(request.getHeader(BootstrapHandler.SERVICE_WORKER_HEADER)).thenReturn("script");
    Assert.assertFalse(bootstrapHandler.canHandleRequest(request));
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Test(org.junit.Test)

Example 18 with VaadinServletRequest

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

the class IndexHtmlRequestHandlerTest method synchronizedHandleRequest_badLocation_noUiCreated.

@Test
public void synchronizedHandleRequest_badLocation_noUiCreated() throws IOException {
    final IndexHtmlRequestHandler bootstrapHandler = new IndexHtmlRequestHandler();
    final VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    Mockito.doAnswer(invocation -> "..**").when(request).getPathInfo();
    final MockServletServiceSessionSetup.TestVaadinServletResponse response = mocks.createResponse();
    final boolean value = bootstrapHandler.synchronizedHandleRequest(mocks.getSession(), request, response);
    Assert.assertTrue("No further request handlers should be called", value);
    Assert.assertEquals("Invalid status code reported", 400, response.getErrorCode());
    Assert.assertEquals("Invalid message reported", "Invalid location: Relative path cannot contain .. segments", response.getErrorMessage());
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) MockServletServiceSessionSetup(com.vaadin.flow.server.MockServletServiceSessionSetup) Test(org.junit.Test)

Example 19 with VaadinServletRequest

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

the class IndexHtmlRequestHandlerTest method internal_request_no_bootstrap_page.

@Test
public void internal_request_no_bootstrap_page() {
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    Mockito.when(request.getPathInfo()).thenReturn(null);
    Mockito.when(request.getParameter("v-r")).thenReturn("hello-foo-bar");
    Assert.assertTrue(BootstrapHandler.isFrameworkInternalRequest(request));
    Assert.assertFalse(indexHtmlRequestHandler.canHandleRequest(request));
    Mockito.when(request.getParameter("v-r")).thenReturn("init");
    Assert.assertTrue(BootstrapHandler.isFrameworkInternalRequest(request));
    Assert.assertFalse(indexHtmlRequestHandler.canHandleRequest(request));
}
Also used : VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Test(org.junit.Test)

Example 20 with VaadinServletRequest

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

the class RemoveFallbackChunkInfo method handleRequest.

boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) {
    VaadinServletRequest servletRequest = (VaadinServletRequest) request;
    HttpServletRequest httpRequest = servletRequest.getHttpServletRequest();
    String query = httpRequest.getQueryString();
    if ("drop-fallback".equals(query)) {
        // self check
        FallbackChunk chunk = session.getService().getContext().getAttribute(FallbackChunk.class);
        if (chunk == null) {
            throw new RuntimeException("Vaadin context has no fallback chunk data");
        }
        // remove fallback chunk data to that the chunk won't be loaded
        session.getService().getContext().removeAttribute(FallbackChunk.class);
    }
    return false;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest)

Aggregations

VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)40 Test (org.junit.Test)19 VaadinSession (com.vaadin.flow.server.VaadinSession)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 VaadinServletService (com.vaadin.flow.server.VaadinServletService)8 IOException (java.io.IOException)7 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)6 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)6 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)6 VaadinRequest (com.vaadin.flow.server.VaadinRequest)6 VaadinResponse (com.vaadin.flow.server.VaadinResponse)6 UI (com.vaadin.flow.component.UI)5 Element (org.jsoup.nodes.Element)5 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)3 SessionExpiredException (com.vaadin.flow.server.SessionExpiredException)3 VaadinService (com.vaadin.flow.server.VaadinService)3 InvalidUIDLSecurityKeyException (com.vaadin.flow.server.communication.ServerRpcHandler.InvalidUIDLSecurityKeyException)3 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)3 JsonException (elemental.json.JsonException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3