Search in sources :

Example 1 with FallbackChunk

use of com.vaadin.flow.server.frontend.FallbackChunk in project flow by vaadin.

the class DeploymentConfigurationFactoryTest method mockApplicationConfiguration.

private ApplicationConfiguration mockApplicationConfiguration() {
    VaadinContext context = new MockVaadinContext();
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(configuration.enableDevServer()).thenReturn(true);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(configuration.useV14Bootstrap()).thenReturn(false);
    Mockito.when(configuration.getContext()).thenReturn(context);
    Mockito.when(configuration.getStringProperty(Mockito.anyString(), Mockito.anyString())).thenReturn(null);
    Mockito.when(configuration.isXsrfProtectionEnabled()).thenReturn(false);
    Mockito.when(configuration.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
    fallbackChunk = Mockito.mock(FallbackChunk.class);
    Mockito.when(configuration.getFallbackChunk()).thenReturn(fallbackChunk);
    return configuration;
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 2 with FallbackChunk

use of com.vaadin.flow.server.frontend.FallbackChunk in project flow by vaadin.

the class VaadinServletService method init.

@Override
public void init() throws ServiceException {
    DeploymentConfiguration deploymentConfiguration = getDeploymentConfiguration();
    Properties initParameters = deploymentConfiguration.getInitParameters();
    Object object = initParameters.get(DeploymentConfigurationFactory.FALLBACK_CHUNK);
    if (object instanceof FallbackChunk) {
        VaadinContext context = getContext();
        context.setAttribute(object);
    }
    super.init();
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) Properties(java.util.Properties) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 3 with FallbackChunk

use of com.vaadin.flow.server.frontend.FallbackChunk in project flow by vaadin.

the class SpringServletTest method fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration.

// #662
@Test
public void fallbackChunk_givenInInitParameter_passedOnToDeploymentConfiguration() throws ServletException {
    FallbackChunk fallbackChunk = new FallbackChunk(Collections.emptyList(), Collections.emptyList());
    final Properties properties = new Properties();
    properties.put(DeploymentConfigurationFactory.FALLBACK_CHUNK, fallbackChunk);
    VaadinService service = SpringInstantiatorTest.getService(context, properties, true);
    Assert.assertSame(fallbackChunk, service.getDeploymentConfiguration().getInitParameters().get(DeploymentConfigurationFactory.FALLBACK_CHUNK));
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) VaadinService(com.vaadin.flow.server.VaadinService) Properties(java.util.Properties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringInstantiatorTest(com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)

Example 4 with FallbackChunk

use of com.vaadin.flow.server.frontend.FallbackChunk in project flow by vaadin.

the class DeploymentConfigurationFactory method readBuildInfo.

private void readBuildInfo(Properties initParameters, VaadinContext context) {
    String json = getTokenFileContent(initParameters::getProperty);
    FallbackChunk fallbackChunk = null;
    // already set.
    if (json != null) {
        JsonObject buildInfo = JsonUtil.parse(json);
        Map<String, String> properties = getConfigParametersUsingTokenData(buildInfo);
        // only insert properties that haven't been defined
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            if (!initParameters.containsKey(entry.getKey())) {
                initParameters.put(entry.getKey(), entry.getValue());
            }
        }
        fallbackChunk = FrontendUtils.readFallbackChunk(buildInfo);
    }
    if (fallbackChunk == null) {
        fallbackChunk = ApplicationConfiguration.get(context).getFallbackChunk();
    }
    if (fallbackChunk != null) {
        initParameters.put(FALLBACK_CHUNK, fallbackChunk);
    }
}
Also used : FallbackChunk(com.vaadin.flow.server.frontend.FallbackChunk) JsonObject(elemental.json.JsonObject) Map(java.util.Map)

Example 5 with FallbackChunk

use of com.vaadin.flow.server.frontend.FallbackChunk 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

FallbackChunk (com.vaadin.flow.server.frontend.FallbackChunk)11 Map (java.util.Map)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 VaadinContext (com.vaadin.flow.server.VaadinContext)2 CssImportData (com.vaadin.flow.server.frontend.FallbackChunk.CssImportData)2 File (java.io.File)2 ServletContext (javax.servlet.ServletContext)2 CssImport (com.vaadin.flow.component.dependency.CssImport)1 JavaScript (com.vaadin.flow.component.dependency.JavaScript)1 JsModule (com.vaadin.flow.component.dependency.JsModule)1 Lookup (com.vaadin.flow.di.Lookup)1 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 ExecutionFailedException (com.vaadin.flow.server.ExecutionFailedException)1 VaadinService (com.vaadin.flow.server.VaadinService)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1 DefaultApplicationConfigurationFactory (com.vaadin.flow.server.startup.DefaultApplicationConfigurationFactory)1 SpringInstantiatorTest (com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)1