Search in sources :

Example 1 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class VaadinServletTest method resolveTranslation_for_servlet_with_path.

@Test
public void resolveTranslation_for_servlet_with_path() throws MalformedURLException {
    request = Mockito.mock(VaadinServletRequest.class);
    CurrentInstance.set(VaadinRequest.class, request);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(((VaadinServletRequest) request).getServletPath()).thenReturn("/app/");
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(factory.getUriResolver(request)).thenReturn(vaadinUriResolver);
    String path = "/src/foo";
    String resolved = "./../src/bar";
    Mockito.when(vaadinUriResolver.resolveVaadinUri(path)).thenReturn(resolved);
    Mockito.when(vaadinUriResolver.resolveVaadinUri("/theme/foo")).thenReturn("./../theme/foo");
    Mockito.when(context.getResource("/./theme/foo")).thenReturn(new URL("http://theme/foo"));
    String urlTranslation = servlet.getUrlTranslation(new MyTheme(), path);
    Assert.assertEquals("/theme/foo", urlTranslation);
}
Also used : DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 2 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class WebJarServerTest method init.

@Before
public void init() throws Exception {
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.getDevelopmentFrontendPrefix()).thenReturn(Constants.FRONTEND_URL_DEV_DEFAULT);
    VaadinServletService servletService = Mockito.mock(VaadinServletService.class);
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    servlet = new VaadinServlet() {

        @Override
        protected VaadinServletService createServletService() throws ServletException, ServiceException {
            return servletService;
        }

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }
    };
    Mockito.when(servletService.getDeploymentConfiguration()).thenReturn(configuration);
    Mockito.when(configuration.areWebJarsEnabled()).thenReturn(true);
    servlet.init(Mockito.mock(ServletConfig.class));
    Field webJarServerField = VaadinServlet.class.getDeclaredField("webJarServer");
    webJarServerField.setAccessible(true);
    webJarServer = (WebJarServer) webJarServerField.get(servlet);
    // webJarServer = new WebJarServer(configuration);
    // context = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getResource(GRID_WEBJAR)).thenReturn(new URL("http://localhost:8080" + GRID_DEPENDENCY));
}
Also used : ServletException(javax.servlet.ServletException) Field(java.lang.reflect.Field) ServiceException(com.vaadin.flow.server.ServiceException) VaadinServlet(com.vaadin.flow.server.VaadinServlet) ServletConfig(javax.servlet.ServletConfig) VaadinServletService(com.vaadin.flow.server.VaadinServletService) ServletContext(javax.servlet.ServletContext) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) URL(java.net.URL) Before(org.junit.Before)

Example 3 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class BootstrapHandler method getApplicationParameters.

private static JsonObject getApplicationParameters(VaadinRequest request, VaadinSession session) {
    VaadinService vaadinService = session.getService();
    DeploymentConfiguration deploymentConfiguration = session.getConfiguration();
    final boolean productionMode = deploymentConfiguration.isProductionMode();
    JsonObject appConfig = Json.createObject();
    appConfig.put(ApplicationConstants.FRONTEND_URL_ES6, deploymentConfiguration.getEs6FrontendPrefix());
    appConfig.put(ApplicationConstants.FRONTEND_URL_ES5, deploymentConfiguration.getEs5FrontendPrefix());
    if (!productionMode) {
        JsonObject versionInfo = Json.createObject();
        versionInfo.put("vaadinVersion", Version.getFullVersion());
        String atmosphereVersion = AtmospherePushConnection.getAtmosphereVersion();
        if (atmosphereVersion != null) {
            versionInfo.put("atmosphereVersion", atmosphereVersion);
        }
        appConfig.put("versionInfo", versionInfo);
    }
    // Use locale from session if set, else from the request
    Locale locale = ServletHelper.findLocale(session, request);
    // Get system messages
    SystemMessages systemMessages = vaadinService.getSystemMessages(locale, request);
    if (systemMessages != null) {
        JsonObject sessExpMsg = Json.createObject();
        putValueOrNull(sessExpMsg, CAPTION, systemMessages.getSessionExpiredCaption());
        putValueOrNull(sessExpMsg, MESSAGE, systemMessages.getSessionExpiredMessage());
        putValueOrNull(sessExpMsg, URL, systemMessages.getSessionExpiredURL());
        appConfig.put("sessExpMsg", sessExpMsg);
    }
    String contextRoot = ServletHelper.getContextRootRelativePath(request) + "/";
    appConfig.put(ApplicationConstants.CONTEXT_ROOT_URL, contextRoot);
    if (!productionMode) {
        appConfig.put("debug", true);
    }
    if (deploymentConfiguration.isRequestTiming()) {
        appConfig.put("requestTiming", true);
    }
    appConfig.put("heartbeatInterval", deploymentConfiguration.getHeartbeatInterval());
    boolean sendUrlsAsParameters = deploymentConfiguration.isSendUrlsAsParameters();
    if (!sendUrlsAsParameters) {
        appConfig.put("sendUrlsAsParameters", false);
    }
    return appConfig;
}
Also used : Locale(java.util.Locale) JsonObject(elemental.json.JsonObject) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 4 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class BootstrapHandler method appendWebComponentsPolyfills.

private static void appendWebComponentsPolyfills(Element head, BootstrapContext context) {
    Optional<WebComponents> webComponents = AnnotationReader.getAnnotationFor(context.getUI().getClass(), WebComponents.class);
    DeploymentConfiguration config = context.getSession().getConfiguration();
    String webComponentsPolyfillBase = config.getWebComponentsPolyfillBase().orElse(null);
    if (webComponentsPolyfillBase == null) {
        return;
    }
    assert webComponentsPolyfillBase.endsWith("/");
    boolean loadEs5Adapter = config.getBooleanProperty(Constants.LOAD_ES5_ADAPTERS, webComponents.map(WebComponents::loadEs5Adapter).orElse(true));
    if (loadEs5Adapter && !context.getSession().getBrowser().isEs6Supported()) {
        // This adapter is required since lots of our current customers use
        // polymer-cli to transpile sources,
        // this tool adds babel-helpers dependency into each file, see:
        // https://github.com/Polymer/polymer-cli/blob/master/src/build/build.ts#L64
        // and
        // https://github.com/Polymer/polymer-cli/blob/master/src/build/optimize-streams.ts#L119
        head.appendChild(createInlineJavaScriptElement(BABEL_HELPERS_JS));
    }
    head.appendChild(createJavaScriptElement(context.getUriResolver().resolveVaadinUri(webComponentsPolyfillBase + "webcomponents-loader.js"), false));
}
Also used : WebComponents(com.vaadin.flow.component.WebComponents) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 5 with DeploymentConfiguration

use of com.vaadin.flow.function.DeploymentConfiguration in project flow by vaadin.

the class BundleFilterInitializer method serviceInit.

@Override
public void serviceInit(ServiceInitEvent event) {
    DeploymentConfiguration deploymentConfiguration = event.getSource().getDeploymentConfiguration();
    if (deploymentConfiguration.isProductionMode()) {
        VaadinUriResolver es6ContextPathResolver = new VaadinUriResolver() {

            @Override
            protected String getContextRootUrl() {
                return "/";
            }

            @Override
            protected String getFrontendRootUrl() {
                return deploymentConfiguration.getEs6FrontendPrefix();
            }
        };
        Map<String, Set<String>> importsInBundles = readBundleDependencies(event, es6ContextPathResolver);
        if (!importsInBundles.isEmpty()) {
            if (importsInBundles.values().stream().noneMatch(importSet -> importSet.contains(BundleDependencyFilter.MAIN_BUNDLE_URL))) {
                throw new IllegalArgumentException(String.format("Attempted to initialize BundleDependencyFilter with an " + "import to bundle mapping which does not contain the main bundle %s", BundleDependencyFilter.MAIN_BUNDLE_URL));
            }
            event.addDependencyFilter(new BundleDependencyFilter(importsInBundles));
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)63 Test (org.junit.Test)24 VaadinService (com.vaadin.flow.server.VaadinService)23 VaadinSession (com.vaadin.flow.server.VaadinSession)9 UI (com.vaadin.flow.component.UI)8 Before (org.junit.Before)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)6 URL (java.net.URL)6 Properties (java.util.Properties)6 VaadinContext (com.vaadin.flow.server.VaadinContext)5 PushConfiguration (com.vaadin.flow.component.PushConfiguration)4 HashMap (java.util.HashMap)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 Method (java.lang.reflect.Method)3 Set (java.util.Set)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 Div (com.vaadin.flow.component.html.Div)2