/** * 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)); }
/** * Get the I18NProvider property from the session configurator or try to * load it from application.properties property file. * * @return I18NProvider parameter or null if not found */ private String getI18NProviderProperty() { DeploymentConfiguration deploymentConfiguration = service .getDeploymentConfiguration(); if (deploymentConfiguration == null) { return null; } return deploymentConfiguration .getStringProperty(Constants.I18N_PROVIDER, null); } }
/** * Checks if the application is running in production mode. * * @return <code>true</code> if in production mode, <code>false</code> * otherwise. */ public boolean isProductionMode() { return request.getService().getDeploymentConfiguration() .isProductionMode(); }
/** * 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(); } }
/** * Creates bundle filters for the given service. * * @param service * the Vaadin service for which to create filters, not * <code>null</code> * @return a stream of bundle filters, or an empty stream if no bundle * filter should be used */ public Stream<BundleDependencyFilter> createFilters(VaadinService service) { if (!service.getDeploymentConfiguration() .useCompiledFrontendResources()) { return Stream.empty(); } return Stream .of(createBundleFilterForBrowser(FakeBrowser.getEs6(), service), createBundleFilterForBrowser(FakeBrowser.getEs5(), service)) .flatMap(maybeFilter -> maybeFilter.map(Stream::of) .orElseGet(Stream::empty)); }
/** * Verifies that the given CSRF token (aka double submit cookie) is valid * for the given session. This is used to protect against Cross Site Request * Forgery attacks. * <p> * This protection is enabled by default, but it might need to be disabled * to allow a certain type of testing. For these cases, the check can be * disabled by setting the init parameter * <code>disable-xsrf-protection</code> to <code>true</code>. * * @param session * the vaadin session for which the check should be done * @param requestToken * the CSRF token provided in the request * @return <code>true</code> if the token is valid or if the protection is * disabled; <code>false</code> if protection is enabled and the * token is invalid * @see DeploymentConfiguration#isXsrfProtectionEnabled() */ public static boolean isCsrfTokenValid(VaadinSession session, String requestToken) { if (session.getService().getDeploymentConfiguration() .isXsrfProtectionEnabled()) { String sessionToken = session.getCsrfToken(); if (sessionToken == null || !sessionToken.equals(requestToken)) { return false; } } return true; }
/** * Returns the number of seconds that must pass without a valid UIDL request * being received for the given session before the session is closed, even * though heartbeat requests are received. This is a lower bound; it might * take longer to close an inactive session. * <p> * Returns a negative number if there is no timeout. In this case heartbeat * requests suffice to keep the session alive, but it will still eventually * expire in the regular manner if there are no requests at all (see * {@link WrappedSession#getMaxInactiveInterval()}). * * @return The UIDL request timeout in seconds, or a negative number if * timeout never occurs. * @see DeploymentConfiguration#isCloseIdleSessions() * @see #getHeartbeatTimeout() */ private int getUidlRequestTimeout(VaadinSession session) { return getDeploymentConfiguration().isCloseIdleSessions() ? session.getSession().getMaxInactiveInterval() : -1; }
private void reportException(Exception exception, String path, String exceptionText) { getElement().appendChild(Element.createText(exceptionText)); VaadinService vaadinService = VaadinService.getCurrent(); // Check that we have a vaadinService as else we will fail on a NPE and // the stacktrace we actually got will disappear and getting a NPE is // confusing. boolean productionMode = vaadinService != null && vaadinService .getDeploymentConfiguration().isProductionMode(); if (!productionMode) { checkLogBinding(); printStacktrace(exception); } getLogger().error( "There was an exception while trying to navigate to '{}'", path, exception); }
/** * Returns the UI class mapped for servlet that handles the given request. * <p> * This method is protected for testing purposes. * * @param request * the request for the UI * @return the UI class for the request */ protected static Class<? extends UI> getUIClass(VaadinRequest request) { String uiClassName = request.getService().getDeploymentConfiguration() .getUIClassName(); if (uiClassName == null) { throw new BootstrapException( "Could not determine the uiClassName for the request path " + request.getPathInfo()); } ClassLoader classLoader = request.getService().getClassLoader(); try { return Class.forName(uiClassName, true, classLoader) .asSubclass(UI.class); } catch (ClassNotFoundException e) { throw new BootstrapException( "Vaadin Servlet mapped to the request path " + request.getPathInfo() + " cannot find the mapped UI class with name " + uiClassName, e); } }
this.template = template; boolean productionMode = service.getDeploymentConfiguration() .isProductionMode();
.collect(Collectors.toList()); if (!getDeploymentConfiguration().isProductionMode()) { Logger logger = getLogger(); logger.debug("The application has the following routes: ");
private static Element getPushScript(BootstrapContext context) { VaadinRequest request = context.getRequest(); // Parameter appended to JS to bypass caches after version upgrade. String versionQueryParam = "?v=" + Version.getFullVersion(); // Load client-side dependencies for push support String pushJSPath = ServletHelper.getContextRootRelativePath(request) + "/"; if (request.getService().getDeploymentConfiguration() .isProductionMode()) { pushJSPath += ApplicationConstants.VAADIN_PUSH_JS; } else { pushJSPath += ApplicationConstants.VAADIN_PUSH_DEBUG_JS; } pushJSPath += versionQueryParam; return createJavaScriptElement(pushJSPath); }
if (request.getService().getDeploymentConfiguration() .isSyncIdCheckEnabled()) { syncId = (int) json
/** * Creates and registers a new VaadinSession for this service. Assumes * proper locking has been taken care of by the caller. * * @param request * The request which triggered session creation. * @return A new VaadinSession instance */ private VaadinSession createAndRegisterSession(VaadinRequest request) { assert ((ReentrantLock) getSessionLock(request.getWrappedSession())) .isHeldByCurrentThread() : "Session has not been locked by this thread"; VaadinSession session = createVaadinSession(request); VaadinSession.setCurrent(session); storeSession(session, request.getWrappedSession()); // Initial WebBrowser data comes from the request session.getBrowser().updateRequestDetails(request); session.setConfiguration(getDeploymentConfiguration()); // Initial locale comes from the request if (getInstantiator().getI18NProvider() != null) { setLocale(request, session); } onVaadinSessionStarted(request, session); return session; }
/** * 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; }
.getService().getDeploymentConfiguration(); PushMode pushMode = push.map(Push::value) .orElseGet(deploymentConfiguration::getPushMode);
int syncId = service.getDeploymentConfiguration().isSyncIdCheckEnabled() ? uiInternals.getServerSyncId() : -1; encodeExecuteJavaScriptList(executeJavaScriptList)); if (ui.getSession().getService().getDeploymentConfiguration() .isRequestTiming()) { response.put("timings", createPerformanceData(ui));