/** * Returns the location URI of this page, as reported by the browser. Note * that this may not be consistent with the server URI the application is * deployed in due to potential proxies, redirections and similar. * * @return The browser location URI. * @throws IllegalStateException * if the * {@link DeploymentConfiguration#isSendUrlsAsParameters()} is * set to {@code false} */ public URI getLocation() throws IllegalStateException { if (location == null && !uI.getSession().getConfiguration() .isSendUrlsAsParameters()) { throw new IllegalStateException("Location is not available as the " + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS + " parameter is configured as false"); } return location; }
protected void appendMainScriptTagContents(BootstrapContext context, StringBuilder builder) throws IOException { JsonObject appConfig = context.getApplicationParameters(); boolean isDebug = !context.getSession().getConfiguration() .isProductionMode(); if (isDebug) { /* * Add tracking needed for getting bootstrap metrics to the client * side Profiler if another implementation hasn't already been * added. */ builder.append( "if (typeof window.__gwtStatsEvent != 'function') {\n"); builder.append("vaadin.gwtStatsEvents = [];\n"); builder.append( "window.__gwtStatsEvent = function(event) {vaadin.gwtStatsEvents.push(event); return true;};\n"); builder.append("}\n"); } builder.append("vaadin.initApplication(\""); builder.append(context.getAppId()); builder.append("\","); appendJsonObject(builder, appConfig, isDebug); builder.append(");\n"); }
/** * Generates the initial UIDL message that can e.g. be included in a html * page to avoid a separate round trip just for getting the UIDL. * * @param request * the request that caused the initialization * @param uI * the UI for which the UIDL should be generated * @return a string with the initial UIDL message * @throws IOException */ protected String getInitialUidl(VaadinRequest request, UI uI) throws IOException { try (StringWriter writer = new StringWriter()) { writer.write("{"); VaadinSession session = uI.getSession(); if (session.getConfiguration().isXsrfProtectionEnabled()) { writer.write(getSecurityKeyUIDL(session)); } writer.write(getPushIdUIDL(session)); new UidlWriter().write(uI, writer, false); writer.write("}"); String initialUIDL = writer.toString(); getLogger().log(Level.FINE, "Initial UIDL:" + initialUIDL); return initialUIDL; } }
/** * Resolves the URL to use for the {@literal frontend://} protocol. * * @param session * the session of the user to resolve the protocol for * @return the URL that frontend:// resolves to, possibly using another * internal protocol * @since 8.1 */ public static String resolveFrontendUrl(VaadinSession session) { DeploymentConfiguration configuration = session.getConfiguration(); String frontendUrl; if (session.getBrowser().isEs6Supported()) { frontendUrl = configuration.getApplicationOrSystemProperty( ApplicationConstants.FRONTEND_URL_ES6, ApplicationConstants.FRONTEND_URL_ES6_DEFAULT_VALUE); } else { frontendUrl = configuration.getApplicationOrSystemProperty( ApplicationConstants.FRONTEND_URL_ES5, ApplicationConstants.FRONTEND_URL_ES5_DEFAULT_VALUE); } if (!frontendUrl.endsWith("/")) { frontendUrl += "/"; } return frontendUrl; }
if (getSession() != null && getSession().getConfiguration() != null && getSession().getConfiguration().isSendUrlsAsParameters() && getPage().getLocation() != null) {
public static boolean isKickstarter(VaadinSession session) { if(session != null) { return Boolean.parseBoolean( session.getConfiguration().getInitParameters() .getProperty("kickstarterEnvironment", "false")); } else { return false; } }
private static String getBootstrapJS(JsonValue initialUIDL, BootstrapContext context) { boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); String result = getBootstrapJS(); JsonObject appConfig = context.getApplicationParameters(); int indent = 0; if (!productionMode) { indent = 4; } String appConfigString = JsonUtil.stringify(appConfig, indent); String initialUIDLString = JsonUtil.stringify(initialUIDL, indent); // Browser interpret </script> as end of script no matter if it is // inside a string or not so we must escape it initialUIDLString = scriptEndTagPattern.matcher(initialUIDLString) .replaceAll("<\\\\x2F$1"); if (!productionMode) { // only used in debug mode by profiler result = result.replace("{{GWT_STAT_EVENTS}}", GWT_STAT_EVENTS_JS); } else { result = result.replace("{{GWT_STAT_EVENTS}}", ""); } result = result.replace("{{APP_ID}}", context.getAppId()); result = result.replace("{{INITIAL_UIDL}}", initialUIDLString); result = result.replace("{{CONFIG_JSON}}", appConfigString); return result; }
/** * Generates the initial UIDL message which is included in the initial * bootstrap page. * * @param ui * the UI for which the UIDL should be generated * @return a JSON object with the initial UIDL message */ protected static JsonObject getInitialUidl(UI ui) { JsonObject json = new UidlWriter().createUidl(ui, false); VaadinSession session = ui.getSession(); if (session.getConfiguration().isXsrfProtectionEnabled()) { writeSecurityKeyUIDL(json, session); } if (getLogger().isLoggable(Level.FINE)) { getLogger().fine("Initial UIDL:" + json.asString()); } return json; }
private static String getClientEngineUrl(BootstrapContext context) { // use nocache version of client engine if it // has been compiled by SDM or eclipse // In production mode, this should really be loaded by the static block // so emit a warning if we get here (tests will always get here) final boolean productionMode = context.getSession().getConfiguration() .isProductionMode(); boolean resolveNow = !productionMode || clientEngineFile == null; if (resolveNow && BootstrapHandler.class.getResource( "/META-INF/resources/" + CLIENT_ENGINE_NOCACHE_FILE) != null) { return context.getUriResolver().resolveVaadinUri( "context://" + CLIENT_ENGINE_NOCACHE_FILE); } if (clientEngineFile == null) { throw new BootstrapException( "Client engine file name has not been resolved during initialization"); } return context.getUriResolver() .resolveVaadinUri("context://" + clientEngineFile); }
context.getUriResolver().getFrontendUrl()); if (!session.getConfiguration().isProductionMode()) { appConfig.put("debug", true);
VaadinSession session = context.getSession(); VaadinService vaadinService = request.getService(); final boolean productionMode = session.getConfiguration() .isProductionMode();