Search in sources :

Example 6 with DevModeHandler

use of com.vaadin.flow.internal.DevModeHandler in project flow by vaadin.

the class BootstrapHandler method showWebpackErrors.

protected static void showWebpackErrors(VaadinService service, Document document) {
    Optional<DevModeHandler> devServer = DevModeHandlerManager.getDevModeHandler(service);
    if (devServer.isPresent()) {
        String errorMsg = devServer.get().getFailedOutput();
        if (errorMsg != null) {
            // Make error lines more prominent
            errorMsg = errorMsg.replaceAll("(ERROR.+?\n)", "<b>$1</b>");
            Element errorElement = document.createElement("div");
            errorElement.setBaseUri("");
            errorElement.attr("class", "v-system-error");
            errorElement.html("<h3 style=\"display:inline;\">Webpack Error</h3>" + "<h6 style=\"display:inline; padding-left:10px;\" " + "onclick=\"this.parentElement.parentElement.removeChild(this.parentElement)\">Close</h6>" + "<pre>" + errorMsg + "</pre>");
            document.body().appendChild(errorElement);
        }
    }
}
Also used : DevModeHandler(com.vaadin.flow.internal.DevModeHandler) Element(org.jsoup.nodes.Element)

Example 7 with DevModeHandler

use of com.vaadin.flow.internal.DevModeHandler in project flow by vaadin.

the class VaadinServletService method createRequestHandlers.

@Override
protected List<RequestHandler> createRequestHandlers() throws ServiceException {
    List<RequestHandler> handlers = super.createRequestHandlers();
    handlers.add(0, new FaviconHandler());
    if (isAtmosphereAvailable()) {
        try {
            handlers.add(new PushRequestHandler(this));
        } catch (ServiceException e) {
            // Atmosphere init failed. Push won't work but we don't throw a
            // service exception as we don't want to prevent non-push
            // applications from working
            getLogger().warn("Error initializing Atmosphere. Push will not work.", e);
        }
    }
    if (getDeploymentConfiguration().enableDevServer()) {
        Optional<DevModeHandler> handlerManager = DevModeHandlerManager.getDevModeHandler(this);
        if (handlerManager.isPresent()) {
            handlers.add(handlerManager.get());
        } else {
            getLogger().warn("no DevModeHandlerManager implementation found " + "but dev server enabled. Include the " + "com.vaadin.vaadin-dev-server dependency.");
        }
    }
    addBootstrapHandler(handlers);
    return handlers;
}
Also used : IndexHtmlRequestHandler(com.vaadin.flow.server.communication.IndexHtmlRequestHandler) PushRequestHandler(com.vaadin.flow.server.communication.PushRequestHandler) FaviconHandler(com.vaadin.flow.server.communication.FaviconHandler) PushRequestHandler(com.vaadin.flow.server.communication.PushRequestHandler) DevModeHandler(com.vaadin.flow.internal.DevModeHandler)

Example 8 with DevModeHandler

use of com.vaadin.flow.internal.DevModeHandler in project flow by vaadin.

the class VaadinServletContextInitializerTest method onStartup_devModeAlreadyInitialized_devModeInitializationSkipped.

@Test
public void onStartup_devModeAlreadyInitialized_devModeInitializationSkipped() throws Exception {
    initDefaultMocks();
    DevModeHandler devModeHandler = Mockito.mock(DevModeHandler.class);
    Mockito.when(devModeHandlerManager.getDevModeHandler()).thenReturn(devModeHandler);
    Mockito.when(devModeHandlerManager.getHandlesTypes()).thenReturn(new Class<?>[0]);
    Mockito.when(appConfig.enableDevServer()).thenReturn(true);
    VaadinServletContextInitializer vaadinServletContextInitializer = getStubbedVaadinServletContextInitializer();
    // Simulate Spring context start only
    vaadinServletContextInitializer.onStartup(servletContext);
    // In our case, we want to check if Dev Mode has been started within
    // onStartup() call, that means DevModeInitializer.initDevModeHandler()
    // should not have been called.
    Mockito.verify(devModeHandlerManager, Mockito.never()).initDevModeHandler(Mockito.any(), Mockito.any(VaadinContext.class));
}
Also used : VaadinContext(com.vaadin.flow.server.VaadinContext) DevModeHandler(com.vaadin.flow.internal.DevModeHandler) Test(org.junit.Test)

Aggregations

DevModeHandler (com.vaadin.flow.internal.DevModeHandler)8 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.Test)3 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 VaadinContext (com.vaadin.flow.server.VaadinContext)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 AbstractDevModeTest (com.vaadin.base.devserver.startup.AbstractDevModeTest)1 Lookup (com.vaadin.flow.di.Lookup)1 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 DevModeHandlerManager (com.vaadin.flow.internal.DevModeHandlerManager)1 FaviconHandler (com.vaadin.flow.server.communication.FaviconHandler)1 IndexHtmlRequestHandler (com.vaadin.flow.server.communication.IndexHtmlRequestHandler)1 PushRequestHandler (com.vaadin.flow.server.communication.PushRequestHandler)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1 JsonObject (elemental.json.JsonObject)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Scanner (java.util.Scanner)1 Set (java.util.Set)1