/** * A shorthand of * {@link DeploymentConfiguration#getApplicationOrSystemProperty(String, Object, Function)} * for {@link String} type. * * @param propertyName * The simple of the property, in some contexts, lookup might be * performed using variations of the provided name. * @param defaultValue * the default value that should be used if no value has been * defined * @return the property value, or the passed default value if no property * value is found */ default String getStringProperty(String propertyName, String defaultValue) { return getApplicationOrSystemProperty(propertyName, defaultValue, Function.identity()); }
/** * Determines if webJars mechanism is enabled. It is disabled if the user * have explicitly set the {@link Constants#DISABLE_WEBJARS} property to * {@code true}, or the user have not set the property at all and the * {@link #useCompiledFrontendResources()} returns false. * * @return {@code true} if webJars are enabled, {@code false} otherwise */ default boolean areWebJarsEnabled() { return !getBooleanProperty(Constants.DISABLE_WEBJARS, useCompiledFrontendResources()); }
/** * Gets the URL from which frontend resources should be loaded in ES6 * compatible browsers. * * @return the ES6 resource URL */ default String getEs6FrontendPrefix() { return useCompiledFrontendResources() ? getStringProperty(Constants.FRONTEND_URL_ES6, Constants.FRONTEND_URL_ES6_DEFAULT_VALUE) : getDevelopmentFrontendPrefix(); }
/** * Determines if Flow should use compiled or original frontend resources. * * User can explicitly disable bundled resources usage by setting the * {@link Constants#USE_ORIGINAL_FRONTEND_RESOURCES} property to * {@code true}. * * @return {@code true} if Flow should use compiled frontend resources. */ default boolean useCompiledFrontendResources() { return isProductionMode() && !getBooleanProperty( Constants.USE_ORIGINAL_FRONTEND_RESOURCES, false); }
.getConfiguration(); final boolean productionMode = deploymentConfiguration .isProductionMode(); deploymentConfiguration.getEs6FrontendPrefix()); appConfig.put(ApplicationConstants.FRONTEND_URL_ES5, deploymentConfiguration.getEs5FrontendPrefix()); if (deploymentConfiguration.isRequestTiming()) { appConfig.put("requestTiming", true); deploymentConfiguration.getHeartbeatInterval()); .isSendUrlsAsParameters(); if (!sendUrlsAsParameters) { appConfig.put("sendUrlsAsParameters", false);
@Override public String resolveResource(String url, WebBrowser browser) { Objects.requireNonNull(url, "Url cannot be null"); Objects.requireNonNull(browser, "Browser cannot be null"); String frontendRootUrl; DeploymentConfiguration config = getDeploymentConfiguration(); if (browser.isEs6Supported()) { frontendRootUrl = config.getEs6FrontendPrefix(); } else { frontendRootUrl = config.getEs5FrontendPrefix(); } return contextResolver.resolveVaadinUri(url, frontendRootUrl); }
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); Collection<DeploymentConfiguration> servletConfigurations = getServletConfigurations( context); boolean enableServlets = true; boolean hasDevelopmentMode = servletConfigurations.isEmpty(); for (DeploymentConfiguration configuration : servletConfigurations) { enableServlets = enableServlets && !configuration.disableAutomaticServletRegistration(); hasDevelopmentMode = hasDevelopmentMode || !configuration.useCompiledFrontendResources(); } if (enableServlets) { createAppServlet(context); if (hasDevelopmentMode) { createServletIfNotExists(context, "frontendFilesServlet", "/frontend/*"); } } }
/** * Checks whether precompressed Brotli files should be used if available. * * @return <code>true</code> to serve precompressed Brotli files, * <code>false</code> to not serve Brotli files. */ default boolean isBrotli() { return getBooleanProperty(Constants.SERVLET_PARAMETER_BROTLI, false); } }
/** * Returns the number of seconds that must pass without a valid heartbeat or * UIDL request being received from a UI before that UI is removed from its * session. This is a lower bound; it might take longer to close an inactive * UI. Returns a negative number if heartbeat is disabled and timeout never * occurs. * * @return The heartbeat timeout in seconds or a negative number if timeout * never occurs. * @see DeploymentConfiguration#getHeartbeatInterval() */ private int getHeartbeatTimeout() { // Permit three missed heartbeats before closing the UI return (int) (getDeploymentConfiguration().getHeartbeatInterval() * (3.1)); }
/** * Creates a webJar server that is able to search webJars for files and * return them. * * @param deploymentConfiguration * configuration for the deployment, not <code>null</code> * */ public WebJarServer(DeploymentConfiguration deploymentConfiguration) { assert deploymentConfiguration != null; responseWriter = new ResponseWriter(deploymentConfiguration); String frontendPrefix = deploymentConfiguration .getDevelopmentFrontendPrefix(); if (!frontendPrefix.endsWith("/")) { throw new IllegalArgumentException( "Frontend prefix must end with a /. Got \"" + frontendPrefix + "\""); } if (!frontendPrefix .startsWith(ApplicationConstants.CONTEXT_PROTOCOL_PREFIX)) { throw new IllegalArgumentException( "Cannot host WebJars for a fronted prefix that isn't relative to 'context://'. Current frontend prefix: " + frontendPrefix); } prefix = "/" + frontendPrefix.substring( ApplicationConstants.CONTEXT_PROTOCOL_PREFIX.length()) + "bower_components/"; urlPattern = Pattern.compile("^([/.]?[/..]*)" + prefix); }
/** * Creates a new vaadin service based on a deployment configuration. * * @param deploymentConfiguration * the deployment configuration for the service */ public VaadinService(DeploymentConfiguration deploymentConfiguration) { this.deploymentConfiguration = deploymentConfiguration; final String classLoaderName = getDeploymentConfiguration() .getClassLoaderName(); if (classLoaderName != null) { try { final Class<?> classLoaderClass = getClass().getClassLoader() .loadClass(classLoaderName); final Constructor<?> c = classLoaderClass .getConstructor(ClassLoader.class); setClassLoader((ClassLoader) c.newInstance( new Object[] { getClass().getClassLoader() })); } catch (final Exception e) { throw new RuntimeException( "Could not find specified class loader: " + classLoaderName, e); } } if (getClassLoader() == null) { setDefaultClassLoader(); } }
staticFileHandler = createStaticFileHandler(servletService); if (deploymentConfiguration.areWebJarsEnabled()) { webJarServer = new WebJarServer(deploymentConfiguration);
/** * Gets the push mode to use. * * @return the desired push mode */ public PushMode getPushMode() { if (pushMode == null) { pushMode = getUI().getPushConfiguration().getPushMode(); if (pushMode == null) { pushMode = getRequest().getService() .getDeploymentConfiguration().getPushMode(); } if (pushMode.isEnabled() && !getRequest().getService().ensurePushAvailable()) { /* * Fall back if not supported (ensurePushAvailable will log * information to the developer the first time this happens) */ pushMode = PushMode.DISABLED; } } return pushMode; }
/** * Creates a new bootstrap resolver based on the given request and * session. * * @param ui * the ui to resolve for */ protected BootstrapUriResolver(UI ui) { servletPathToContextRoot = ui.getInternals() .getContextRootRelativePath(); VaadinSession session = ui.getSession(); DeploymentConfiguration config = session.getConfiguration(); if (session.getBrowser().isEs6Supported()) { frontendRootUrl = config.getEs6FrontendPrefix(); } else { frontendRootUrl = config.getEs5FrontendPrefix(); } assert frontendRootUrl.endsWith("/"); assert servletPathToContextRoot.endsWith("/"); }
/** * Determines if Flow should automatically register servlets. For more * information on the servlets registered, refer to * {@link com.vaadin.flow.server.startup.ServletDeployer} javadoc. * * User can explicitly disable automatic servlet registration by setting the * {@link Constants#DISABLE_AUTOMATIC_SERVLET_REGISTRATION} property to * {@code true}. * * @return {@code true} if Flow should not automatically register servlets * @see com.vaadin.flow.server.startup.ServletDeployer */ default boolean disableAutomaticServletRegistration() { return getBooleanProperty( Constants.DISABLE_AUTOMATIC_SERVLET_REGISTRATION, false); }
/** * Gets the URL from which frontend resources should be loaded in ES5 * compatible browsers. * * @return the ES5 resource URL */ default String getEs5FrontendPrefix() { return useCompiledFrontendResources() ? getStringProperty(Constants.FRONTEND_URL_ES5, Constants.FRONTEND_URL_ES5_DEFAULT_VALUE) : getDevelopmentFrontendPrefix(); }
.getBooleanProperty(Constants.LOAD_ES5_ADAPTERS, true); if (loadEs5Adapter && !session.getBrowser().isEs6Supported()) {