Search in sources :

Example 11 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 12 with DeploymentConfiguration

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

the class BootstrapHandler method createAndInitUI.

protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) {
    UI ui = ReflectTools.createInstance(uiClass);
    PushConfiguration pushConfiguration = ui.getPushConfiguration();
    ui.getInternals().setSession(session);
    ui.setLocale(session.getLocale());
    BootstrapContext context = new BootstrapContext(request, response, session, ui);
    Optional<Push> push = context.getPageConfigurationAnnotation(Push.class);
    DeploymentConfiguration deploymentConfiguration = context.getSession().getService().getDeploymentConfiguration();
    PushMode pushMode = push.map(Push::value).orElseGet(deploymentConfiguration::getPushMode);
    pushConfiguration.setPushMode(pushMode);
    pushConfiguration.setPushUrl(deploymentConfiguration.getPushURL());
    push.map(Push::transport).ifPresent(pushConfiguration::setTransport);
    // Set thread local here so it is available in init
    UI.setCurrent(ui);
    ui.doInit(request, session.getNextUIid());
    session.addUI(ui);
    // After init and adding UI to session fire init listeners.
    session.getService().fireUIInitListeners(ui);
    return context;
}
Also used : PushConfiguration(com.vaadin.flow.component.PushConfiguration) UI(com.vaadin.flow.component.UI) Push(com.vaadin.flow.component.page.Push) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) PushMode(com.vaadin.flow.shared.communication.PushMode)

Example 13 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 14 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)

Example 15 with DeploymentConfiguration

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

the class CompositeTest method setup.

@Before
public void setup() {
    compositeWithComponent = new CompositeWithComponent() {

        @Override
        public String toString() {
            return "Composite";
        }
    };
    layoutWithSingleComponentComposite = new TestLayout() {

        @Override
        public String toString() {
            return "Layout";
        }
    };
    layoutWithSingleComponentComposite.addComponent(compositeWithComponent);
    ((TracksAttachDetach) componentInsideLayoutInsideComposite).track();
    compositeWithComponent.track();
    layoutInsideComposite.track();
    layoutWithSingleComponentComposite.track();
    Assert.assertNull(VaadinService.getCurrent());
    VaadinService service = Mockito.mock(VaadinService.class);
    DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(true);
    Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
    VaadinService.setCurrent(service);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) TestLayout(com.vaadin.flow.component.CompositeNestedTest.TestLayout) TracksAttachDetach(com.vaadin.flow.component.ComponentTest.TracksAttachDetach) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Before(org.junit.Before)

Aggregations

DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)25 VaadinService (com.vaadin.flow.server.VaadinService)8 Test (org.junit.Test)7 URL (java.net.URL)6 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)4 Before (org.junit.Before)4 VaadinServlet (com.vaadin.flow.server.VaadinServlet)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 VaadinSession (com.vaadin.flow.server.VaadinSession)3 Properties (java.util.Properties)3 ServletConfig (javax.servlet.ServletConfig)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 UI (com.vaadin.flow.component.UI)2 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)2 AbstractDeploymentConfiguration (com.vaadin.flow.server.AbstractDeploymentConfiguration)2 ServiceException (com.vaadin.flow.server.ServiceException)2 VaadinUriResolver (com.vaadin.flow.shared.VaadinUriResolver)2 Conf (com.vaadin.flow.uitest.servlet.CustomDeploymentConfiguration.Conf)2