/** * 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. * * @see DeploymentConfiguration#getHeartbeatInterval() * * @since 7.0.0 * * @return The heartbeat timeout in seconds or a negative number if timeout * never occurs. */ private int getHeartbeatTimeout() { // Permit three missed heartbeats before closing the UI return (int) (getDeploymentConfiguration().getHeartbeatInterval() * (3.1)); }
/** * 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(getClass().getClassLoader())); } catch (final Exception e) { throw new RuntimeException( "Could not find specified class loader: " + classLoaderName, e); } } if (getClassLoader() == null) { setDefaultClassLoader(); } }
/** * Check whether the legacy prefix "v" or the default prefix "vaadin" should * be used when writing designs. The property or context parameter * {@link Constants#SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX} can be used to * switch to the legacy prefix. * * @since 7.5.7 * @return true to use the legacy prefix, false by default */ protected boolean isLegacyPrefixEnabled() { if (legacyDesignPrefix != null) { return legacyDesignPrefix.booleanValue(); } if (VaadinService.getCurrent() == null) { // This will happen at least in JUnit tests. return false; } DeploymentConfiguration configuration = VaadinService.getCurrent() .getDeploymentConfiguration(); legacyDesignPrefix = configuration.getApplicationOrSystemProperty( Constants.SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX, "false") .equals("true"); return legacyDesignPrefix.booleanValue(); }
static Class<? extends LegacyApplication> getLegacyApplicationClass( VaadinService vaadinService) throws ServiceException { Properties initParameters = vaadinService.getDeploymentConfiguration() .getInitParameters(); String applicationParameter = initParameters.getProperty("application"); ClassLoader classLoader = vaadinService.getClassLoader(); if (applicationParameter == null) { throw new ServiceException( "No \"application\" init parameter found"); } try { return classLoader.loadClass(applicationParameter) .asSubclass(LegacyApplication.class); } catch (final ClassNotFoundException e) { throw new ServiceException( "Failed to load application class: " + applicationParameter, e); } }
@Override protected String getMainDivStyle(BootstrapContext context) { VaadinService vaadinService = context.getRequest().getService(); return vaadinService.getDeploymentConfiguration() .getApplicationOrSystemProperty( VaadinPortlet.PORTLET_PARAMETER_STYLE, null); }
@Override public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { VaadinRequest request = event.getRequest(); String uiClassName = request.getService().getDeploymentConfiguration() .getUIClassName(); if (uiClassName != null) { ClassLoader classLoader = request.getService().getClassLoader(); try { Class<? extends UI> uiClass = Class .forName(uiClassName, true, classLoader) .asSubclass(UI.class); return uiClass; } catch (ClassNotFoundException e) { throw new RuntimeException("Could not find UI class", e); } } return null; } }
String requestToken) { if (session.getService().getDeploymentConfiguration() .isXsrfProtectionEnabled()) { String sessionToken = session.getCsrfToken();
/** * 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()}). * * @see DeploymentConfiguration#isCloseIdleSessions() * @see #getHeartbeatTimeout() * * @since 7.0.0 * * @return The UIDL request timeout in seconds, or a negative number if * timeout never occurs. */ private int getUidlRequestTimeout(VaadinSession session) { return getDeploymentConfiguration().isCloseIdleSessions() ? session.getSession().getMaxInactiveInterval() : -1; }
/** * Adds the performance timing data (used by TestBench 3) to the UIDL * response. * * @throws IOException */ private void writePerformanceData(UI ui, Writer writer) throws IOException { if (!ui.getSession().getService().getDeploymentConfiguration() .isProductionMode()) { writer.write(String.format(", \"timings\":[%d, %d]", ui.getSession().getCumulativeRequestDuration(), ui.getSession().getLastRequestDuration())); } }
public static void initDefaultUIProvider(VaadinSession session, VaadinService vaadinService) throws ServiceException { String uiProperty = vaadinService.getDeploymentConfiguration() .getUIClassName(); // Add provider for UI parameter first to give it lower priority // (providers are FILO) if (uiProperty != null) { verifyUIClass(uiProperty, vaadinService.getClassLoader()); session.addUIProvider(new DefaultUIProvider()); } String uiProviderProperty = vaadinService.getDeploymentConfiguration() .getUIProviderClassName(); // Then add custom UI provider if defined if (uiProviderProperty != null) { UIProvider uiProvider = getUIProvider(uiProviderProperty, vaadinService.getClassLoader()); session.addUIProvider(uiProvider); } }
.getDeploymentConfiguration().getResourceCacheTime(); if (resourceCacheTime > 0) { cacheControl = "max-age=" + String.valueOf(resourceCacheTime);
try { int syncId = service.getDeploymentConfiguration() .isSyncIdCheckEnabled() ? uiConnectorTracker.getCurrentSyncId()
if (context.getRequest().getService().getDeploymentConfiguration() .isProductionMode()) { pushJS += ApplicationConstants.VAADIN_PUSH_JS;
if (request.getService().getDeploymentConfiguration() .isSyncIdCheckEnabled()) { syncId = (int) json
.getDeploymentConfiguration().getWidgetset(null); if (initParameterWidgetSet != null) { return new WidgetsetInfoImpl(initParameterWidgetSet);
/** * 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 * @throws ServiceException */ private VaadinSession createAndRegisterSession(VaadinRequest request) throws ServiceException { 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); // Initial locale comes from the request Locale locale = request.getLocale(); session.setLocale(locale); session.setConfiguration(getDeploymentConfiguration()); session.setCommunicationManager( new LegacyCommunicationManager(session)); ServletPortletHelper.initDefaultUIProvider(session, this); onVaadinSessionStarted(request, session); return session; }
pushMode = session.getService().getDeploymentConfiguration() .getPushMode();
/** * Gets the push mode to use. * * @return the desired push mode */ public PushMode getPushMode() { if (pushMode == null) { UICreateEvent event = new UICreateEvent(getRequest(), getUIClass()); pushMode = getBootstrapResponse().getUIProvider() .getPushMode(event); 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; }
/** * 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(); }
.getDeploymentConfiguration().getHeartbeatInterval()); .getDeploymentConfiguration().isSendUrlsAsParameters(); if (!sendUrlsAsParameters) { appConfig.put("sendUrlsAsParameters", false);