public VaadinSession getContext() { return VaadinSession.getCurrent(); }
/** * Checks whether there might be some {@link VaadinSession} other than the * provided one for which the current thread holds a lock. This method might * not detect all cases where some other session is locked, but it should * cover the most typical situations. * * @since 7.2 * @param session * the session that is expected to be locked * @return <code>true</code> if another session is also locked by the * current thread; <code>false</code> if no such session was found */ public static boolean isOtherSessionLocked(VaadinSession session) { VaadinSession otherSession = VaadinSession.getCurrent(); if (otherSession == null || otherSession == session) { return false; } return otherSession.hasLock(); }
public void doInit(URL url) { this.url = url; VaadinSession.getCurrent().setErrorHandler(this); init(); }
/** * Adds a new browser level window to this application. * * @param uI * the UI window to add to the application */ public void addWindow(LegacyWindow uI) { if (uI.getName() == null) { String name = Integer.toString(namelessUIIndex++); uI.setName(name); } uI.setApplication(this); legacyUINames.put(uI.getName(), uI); uI.setSession(VaadinSession.getCurrent()); }
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; }
/** * Called after the framework has handled a request and the response has * been written. * * @param request * The request object * @param response * The response object * @param session * The session which was used during the request or null if the * request did not use a session */ public void requestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session) { if (session != null) { assert VaadinSession.getCurrent() == session; session.lock(); try { cleanupSession(session); final long duration = (System.nanoTime() - (Long) request .getAttribute(REQUEST_START_TIME_ATTRIBUTE)) / 1000000; session.setLastRequestDuration(duration); } finally { session.unlock(); } } CurrentInstance.clearAll(); }
session = VaadinSession.getCurrent();
if (VaadinSession.getCurrent() != null) { ErrorHandler errorHandler = VaadinSession.getCurrent() .getErrorHandler(); if (errorHandler != null) {
+ "This might happen if a session is deserialized but never used before it expires."); } else if (VaadinService.getCurrentRequest() != null && getCurrent() == this) { assert hasLock();
VaadinResponse response) throws IOException { try (Writer page = response.getWriter()) { WebBrowser b = VaadinSession.getCurrent().getBrowser();
&& !getSession().equals(VaadinSession.getCurrent())) { message += "Furthermore, it is already attached to another VaadinSession. ";
try { session = service.findVaadinSession(vaadinRequest); assert VaadinSession.getCurrent() == session;
@Override public void checkUIAccess() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession == null || !vaadinSession.hasLock()) { throw new IllegalConcurrentAccessException(); } }
@Override public Object remove(String name) { VaadinSession session = VaadinSession.getCurrent(); if (session == null || !session.hasLock()) { throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread"); } Object bean = session.getAttribute(name); session.setAttribute(name, null); return bean; }
@Override public void logout() { VaadinSession.getCurrent().close(); Page.getCurrent().reload(); }
@Override public void logout(String logoutUrl) { VaadinSession.getCurrent().close(); Page.getCurrent().setLocation(logoutUrl); }
protected WebBrowser getWebBrowserDetails() { // timezone info is passed only on VaadinSession creation WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser(); VaadinRequest currentRequest = VaadinService.getCurrentRequest(); // update web browser instance if current request is not null // it can be null in case of background/async processing of login request if (currentRequest != null) { webBrowser.updateRequestDetails(currentRequest); } return webBrowser; }
@Override public void set(SecurityContext securityContext) { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null && vaadinSession.hasLock()) { vaadinSession.setAttribute(SecurityContext.class, securityContext); } else { super.set(securityContext); } } }
@Override public void logout(String logoutUrl) { VaadinSession.getCurrent().close(); Page.getCurrent().setLocation(logoutUrl); }
protected void setSessionInternal(ClientUserSession userSession) { VaadinSession.getCurrent().setAttribute(UserSession.class, userSession); if (userSession != null) { AppContext.setSecurityContext(new SecurityContext(userSession)); } else { AppContext.setSecurityContext(null); } }