/** * Gets the currently processed Vaadin portlet request. The current request * is automatically defined when the request is started. The current request * can not be used in e.g. background threads because of the way server * implementations reuse request instances. * * @return the current Vaadin portlet request instance if available, * otherwise <code>null</code> * */ public static VaadinPortletRequest getCurrentRequest() { return (VaadinPortletRequest) VaadinService.getCurrentRequest(); }
private LegacyApplication getApplication() { LegacyApplication application = VaadinSession.getCurrent() .getAttribute(LegacyApplication.class); if (application == null) { application = createApplication(); if (application == null) { return null; } VaadinSession.getCurrent().setAttribute(LegacyApplication.class, application); URL applicationUrl; try { applicationUrl = VaadinService.getCurrent() .getApplicationUrl(VaadinService.getCurrentRequest()); } catch (MalformedURLException e) { throw new RuntimeException(e); } application.doInit(applicationUrl); } if (application != null && !application.isRunning()) { VaadinSession.getCurrent().setAttribute(LegacyApplication.class, null); // Run again without a current application return getApplication(); } return application; }
/** * Gets the currently processed Vaadin portlet response. The current * response is automatically defined when the request is started. The * current response can not be used in e.g. background threads because of * the way server implementations reuse response instances. * * @return the current Vaadin portlet response instance if available, * otherwise <code>null</code> * */ public static VaadinPortletResponse getCurrentResponse() { return (VaadinPortletResponse) VaadinService.getCurrentResponse(); }
private Class<WidgetsetInfo> findWidgetsetClass() { try { // We cannot naively use Class.forname without getting the correct // classloader // FIXME This might still fail with osgi ClassLoader tccl = VaadinService.getCurrent().getClassLoader(); Class<?> c = Class.forName(APP_WIDGETSET_NAME, true, tccl); // if not implementing the interface, possibly a @WebListener class // from an earlier version - ignore it if (WidgetsetInfo.class.isAssignableFrom(c)) { return (Class<WidgetsetInfo>) c; } } catch (ClassNotFoundException e) { // ClassNotFound is a normal case } return null; }
/** * 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(); }
/** * 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(); } }
final VaadinRequest currentRequest = VaadinService.getCurrentRequest(); final UI currentUI = UI.getCurrent(); if (currentUI != null) { LOGGER.debug("Clearing the session"); final WrappedSession session = currentRequest.getWrappedSession(); final String serviceName = VaadinService.getCurrent().getServiceName(); final Set<String> attributesToSpare = new HashSet<String>(); attributesToSpare.add(serviceName + ".lock"); VaadinService.reinitializeSession(currentRequest); LOGGER.debug("Session reinitialized, new ID is {}", VaadinService.getCurrentRequest().getWrappedSession().getId()); } else { LOGGER
@Override public File applicationBaseDirectory() { if (VaadinService.getCurrent() != null) { File baseDir = VaadinService.getCurrent() .getBaseDirectory(); if (baseDir != null) { log.info("Application base directory (from VaadinService) is {}", baseDir.getAbsolutePath()); } else { log.error("Application base directory has not been set"); } return baseDir; } throw new IllegalStateException("There is no current VaadinService"); }
HttpSession session = ((HttpServletRequest)VaadinService.getCurrentRequest()).getSession(false); if (session != null) { session.invalidate(); session = ((HttpServletRequest)VaadinService.getCurrentRequest()).getSession(true); (HttpServletRequest)VaadinService.getCurrentRequest()); if ((loginMessage != null) && loginMessage.isLoginCurrentlyForbidden()) { user, ou, (VaadinServletRequest)(VaadinService.getCurrentRequest()), (VaadinServletResponse)(VaadinService.getCurrentResponse())); VaadinService.getCurrentRequest().getWrappedSession().setAttribute( CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS, settings);
+ "Session destroy events will not be fired and UIs in the session will not get detached. " + "This might happen if a session is deserialized but never used before it expires."); } else if (VaadinService.getCurrentRequest() != null && getCurrent() == this) { assert hasLock(); service.fireSessionDestroy(this);
/** * 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)); }
/** * Load and initialize the mobile drag-drop-polyfill if needed and not yet * done so. */ private void loadMobileHtml5DndPolyfill() { if (mobileHtml5DndPolyfillLoaded) { return; } if (!getPage().getWebBrowser().isTouchDevice()) { return; } mobileHtml5DndPolyfillLoaded = true; String vaadinLocation = getSession().getService().getStaticFileLocation( VaadinService.getCurrentRequest()) + "/VAADIN/"; getPage().addDependency(new Dependency(Type.JAVASCRIPT, vaadinLocation + ApplicationConstants.MOBILE_DND_POLYFILL_JS)); getRpcProxy(PageClientRpc.class).initializeMobileHtml5DndPolyfill(); }
/** * Creates and binds a TouchKitSettings instance to the * {@link VaadinService} instance, which is automatically fetched from a * thread local. */ public TouchKitSettings() { this(VaadinService.getCurrent()); }
/** * 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; }
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); } }
service.runPendingAccessTasks(session); try { int syncId = service.getDeploymentConfiguration() .isSyncIdCheckEnabled() ? uiConnectorTracker.getCurrentSyncId() .getSystemMessages(ui.getLocale(), null);
/** * 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; }
context.getSession(), context.getRequest()); SystemMessages systemMessages = vaadinService.getSystemMessages(locale, request); if (systemMessages != null) { String vaadinDir = vaadinService.getStaticFileLocation(request) + "/VAADIN/"; appConfig.put(ApplicationConstants.VAADIN_DIR_URL, vaadinDir); if (vaadinService.isStandalone(request)) { appConfig.put("standalone", true); .getDeploymentConfiguration().getHeartbeatInterval()); .getDeploymentConfiguration().isSendUrlsAsParameters(); if (!sendUrlsAsParameters) { appConfig.put("sendUrlsAsParameters", false);
/** * Initializes this service. The service should be initialized before it is * used. * * @since 7.1 * @throws ServiceException * if a problem occurs when creating the service */ public void init() throws ServiceException { List<RequestHandler> handlers = createRequestHandlers(); Collections.reverse(handlers); requestHandlers = Collections.unmodifiableCollection(handlers); DeploymentConfiguration deploymentConf = getDeploymentConfiguration(); String routerConfiguratorClassName = deploymentConf .getRouterConfiguratorClassName(); if (routerConfiguratorClassName != null && !RouterConfigurator.class .getName().equals(routerConfiguratorClassName)) { // Configure router if we have a non-default configurator type configureRouter(routerConfiguratorClassName); } initialized = true; }
/** * Sets the this Vaadin service as the current service and also sets the * current Vaadin request and Vaadin response. This method is used by the * framework to set the current instances when a request related to the * service is processed and they are cleared when the request has been * processed. * <p> * The application developer can also use this method to define the current * instances outside the normal request handling, e.g. when initiating * custom background threads. * </p> * * @param request * the Vaadin request to set as the current request, or * <code>null</code> if no request should be set. * @param response * the Vaadin response to set as the current response, or * <code>null</code> if no response should be set. * * @see #getCurrent() * @see #getCurrentRequest() * @see #getCurrentResponse() */ public void setCurrentInstances(VaadinRequest request, VaadinResponse response) { setCurrent(this); CurrentInstance.set(VaadinRequest.class, request); CurrentInstance.set(VaadinResponse.class, response); }