/** * Finds the {@link VaadinSession} to which this connector belongs. If the * connector has not been attached, <code>null</code> is returned. * * @return The connector's session, or <code>null</code> if not attached */ protected VaadinSession getSession() { UI uI = getUI(); if (uI == null) { return null; } else { return uI.getSession(); } }
public WebBrowser getWebBrowser() { return uI.getSession().getBrowser(); }
/** * 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())); } }
/** * Removes all references and information about connectors marked as * unregistered. * */ private void removeUnregisteredConnectors() { GlobalResourceHandler globalResourceHandler = uI.getSession() .getGlobalResourceHandler(false); for (ClientConnector connector : unregisteredConnectors) { removeUnregisteredConnector(connector, globalResourceHandler); } unregisteredConnectors.clear(); }
/** * Sets current instances for the UI and all related classes. The previously * defined values can be restored by passing the returned map to * {@link #restoreInstances(Map)}. * * @since 7.1 * * @param ui * The UI * @return A map containing the old values of the instances that this method * updated. */ public static Map<Class<?>, CurrentInstance> setCurrent(UI ui) { Map<Class<?>, CurrentInstance> old = setCurrent(ui.getSession()); old.put(UI.class, set(UI.class, ui)); return old; }
/** * Gets a connector by its id. * * @param connectorId * The connector id to look for * @return The connector with the given id or null if no connector has the * given id */ public ClientConnector getConnector(String connectorId) { ClientConnector connector = connectorIdToConnector.get(connectorId); // Ignore connectors that have been unregistered but not yet cleaned up if (unregisteredConnectors.contains(connector)) { return null; } else if (connector != null) { return connector; } else { DragAndDropService service = uI.getSession() .getDragAndDropService(); if (connectorId.equals(service.getConnectorId())) { return service; } } return null; }
/** * 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; }
@Override public InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { VaadinPortletSession session = (VaadinPortletSession) uI.getSession(); PortletContext portletContext = session.getPortletSession() .getPortletContext(); return portletContext .getResourceAsStream("/" + VaadinPortlet.THEME_DIR_PATH + '/' + themeName + "/" + resource); }
/** * Adds an initialized UI to this session. * * @param ui * the initialized UI to add. */ public void addUI(UI ui) { assert hasLock(); if (ui.getUIId() == -1) { throw new IllegalArgumentException( "Can not add an UI that has not been initialized."); } if (ui.getSession() != this) { throw new IllegalArgumentException( "The UI belongs to a different session"); } Integer uiId = Integer.valueOf(ui.getUIId()); uIs.put(uiId, ui); String embedId = ui.getEmbedId(); if (embedId != null) { Integer previousUiId = embedIdMap.put(embedId, uiId); if (previousUiId != null) { UI previousUi = uIs.get(previousUiId); assert previousUi != null && embedId.equals(previousUi .getEmbedId()) : "UI id map and embed id map not in sync"; // Will fire cleanup events at the end of the request handling. previousUi.close(); } } }
@Override public void addAttribute(String name, Resource value) throws PaintException { if (value == null) { throw new NullPointerException(); } ClientConnector ownerConnector = openPaintables.peek(); ownerConnector.getUI().getSession().getGlobalResourceHandler(true) .register(value, ownerConnector); ResourceReference reference = ResourceReference.create(value, ownerConnector, name); addAttribute(name, reference.getURL()); }
/** * 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; } }
ui.getSession().getCommunicationManager() .handleConnectorRelatedException(connector, e);
/** * Handles the given RPC method invocation for the given connector. * * @since 7.7 * @param ui * the UI containing the connector * @param connector * the connector the RPC is targeted to * @param invocation * information about the rpc to invoke */ protected void handleInvocation(UI ui, ClientConnector connector, ServerRpcMethodInvocation invocation) { try { ServerRpcManager.applyInvocation(connector, invocation); } catch (RpcInvocationException e) { ui.getSession().getCommunicationManager() .handleConnectorRelatedException(connector, e); } }
.findErrorHandler(UI.this); if (errorHandler == null && getSession() == null) {
.getSession().getGlobalResourceHandler(false); if (globalResourceHandler != null) { String uri = globalResourceHandler.getUri(connector,
Lock lockInstance = ui.getSession().getLockInstance(); if (lockInstance instanceof ReentrantLock) { if (((ReentrantLock) lockInstance).hasQueuedThreads()) {
VaadinSession parentSession = parentUI.getSession(); if (parentSession != null && !parentSession.hasLock()) { String message = "Cannot remove from parent when the session is not locked.";
@Override public void setPushMode(PushMode pushMode) { if (pushMode == null) { throw new IllegalArgumentException("Push mode cannot be null"); } VaadinSession session = ui.getSession(); if (session == null) { throw new UIDetachedException( "Cannot set the push mode for a detached UI"); } assert session.hasLock(); if (pushMode.isEnabled() && !session.getService().ensurePushAvailable()) { throw new IllegalStateException( "Push is not available. See previous log messages for more information."); } PushMode oldMode = getState().mode; if (oldMode != pushMode) { getState().mode = pushMode; if (!oldMode.isEnabled() && pushMode.isEnabled()) { // The push connection is initially in a disconnected state; // the client will establish the connection ui.setPushConnection(new AtmospherePushConnection(ui)); } // Nothing to do here if disabling push; // the client will close the connection } }
VaadinSession session = getSession();
/** * 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(); }