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;
}
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();
}
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));
}
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);
}
}
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;
}
Aggregations