com.vaadin.server.VaadinSession - java examples

Here are the examples of the java api com.vaadin.server.VaadinSession taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

56 Examples 7

19 View Complete Implementation : WebLookupFieldTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebLookupFieldTest extends LookupFieldTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebLookupField lookupField = (WebLookupField) component;
        lookupField.setBeanLocator(beanLocator);
        lookupField.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : WebOptionsGroupTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebOptionsGroupTest extends OptionsGroupTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebOptionsGroup optionsGroup = (WebOptionsGroup) component;
        optionsGroup.setBeanLocator(beanLocator);
    }
}

19 View Complete Implementation : WebPickerFieldDsTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebPickerFieldDsTest extends PickerFieldDsTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebPickerField pickerField = (WebPickerField) component;
        pickerField.setBeanLocator(beanLocator);
        pickerField.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : WebFieldGroupTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebFieldGroupTest extends FieldGroupTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
    }

    @Override
    protected UiComponents createComponentsFactory() {
        return new TestUiComponents(applicationContext);
    }

    @Override
    protected int getGridRows(FieldGroup fieldGroup) {
        return fieldGroup.unwrap(GridLayout.clreplaced).getRows();
    }

    @Override
    protected int getGridColumns(FieldGroup fieldGroup) {
        return fieldGroup.unwrap(GridLayout.clreplaced).getColumns();
    }

    @Override
    protected Object getGridCellComposition(FieldGroup fieldGroup, int col, int row) {
        return fieldGroup.unwrap(GridLayout.clreplaced).getComponent(col, row);
    }

    @Override
    protected void autowireUiComponent(Component o) {
        super.autowireUiComponent(o);
        if (o instanceof WebTextField) {
            WebTextField textField = (WebTextField) o;
            textField.setUserSessionSource(userSessionSource);
            textField.setBeanLocator(beanLocator);
        }
    }
}

19 View Complete Implementation : WebPickerFieldTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebPickerFieldTest extends PickerFieldTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebPickerField pickerField = (WebPickerField) component;
        pickerField.setBeanLocator(beanLocator);
        pickerField.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : WebLookupPickerFieldDsTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebLookupPickerFieldDsTest extends LookupPickerFieldDsTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Mocked
    protected ClientConfig clientConfig;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
                configuration.getConfig(ClientConfig.clreplaced);
                result = clientConfig;
                minTimes = 0;
                clientConfig.getPickerShortcutModifiers();
                result = "CTRL-ALT";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebLookupPickerField lookupPickerField = (WebLookupPickerField) component;
        lookupPickerField.setBeanLocator(beanLocator);
        lookupPickerField.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : WebLookupPickerFieldTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebLookupPickerFieldTest extends LookupPickerFieldTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebLookupPickerField lookupPickerField = (WebLookupPickerField) component;
        lookupPickerField.setBeanLocator(beanLocator);
        lookupPickerField.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : WebTextFieldDsTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebTextFieldDsTest extends TextFieldDsTest {

    @Mocked
    protected VaadinSession vaadinSession;

    public WebTextFieldDsTest() {
    }

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebTextField textField = (WebTextField) component;
        textField.setUserSessionSource(userSessionSource);
        textField.setBeanLocator(beanLocator);
    }
}

19 View Complete Implementation : WebOptionsListTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebOptionsListTest extends OptionsListTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebOptionsList optionsList = (WebOptionsList) component;
        optionsList.setBeanLocator(beanLocator);
    }
}

19 View Complete Implementation : WebVaadinCompatibleSecurityContextHolder.java
Copyright Apache License 2.0
Author : cuba-platform
@Override
public SecurityContext get() {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession != null && vaadinSession.hasLock()) {
        return vaadinSession.getAttribute(SecurityContext.clreplaced);
    }
    return super.get();
}

19 View Complete Implementation : WebLabelDsTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebLabelDsTest extends LabelDsTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebLabel label = (WebLabel) component;
        label.setBeanLocator(beanLocator);
        label.setMetadataTools(metadata.getTools());
    }
}

19 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
public static WebResource getAnnisWebResource(VaadinSession vSession) {
    // get URI used by the application
    String uri = getServiceURL(vSession);
    // if already authentificated the REST client is set as the "user" property
    AnnisUser user = getUser(vSession);
    return getAnnisWebResource(uri, user);
}

19 View Complete Implementation : WebDateFieldTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebDateFieldTest extends DateFieldTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebDateField dateField = (WebDateField) component;
        dateField.setBeanLocator(beanLocator);
        dateField.setDateTimeTransformations(new DateTimeTransformations());
    }
}

19 View Complete Implementation : WebLookupFieldDsTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebLookupFieldDsTest extends LookupFieldDsTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                vaadinSession.getConverterFactory();
                result = new DefaultConverterFactory();
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebLookupField lookupField = (WebLookupField) component;
        lookupField.setBeanLocator(beanLocator);
        lookupField.setMetadataTools(metadata.getTools());
    }
}

18 View Complete Implementation : WebBackgroundWorker.java
Copyright Apache License 2.0
Author : cuba-platform
@Override
public void checkUIAccess() {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession == null || !vaadinSession.hasLock()) {
        throw new IllegalConcurrentAccessException();
    }
}

18 View Complete Implementation : VaadinSessionScope.java
Copyright Apache License 2.0
Author : cuba-platform
@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;
}

18 View Complete Implementation : VaadinSessionScope.java
Copyright Apache License 2.0
Author : cuba-platform
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null || !session.hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }
    Object object = session.getAttribute(name);
    if (object == null) {
        object = objectFactory.getObject();
        session.setAttribute(name, object);
    }
    return object;
}

18 View Complete Implementation : WebVaadinCompatibleSecurityContextHolder.java
Copyright Apache License 2.0
Author : cuba-platform
@Override
public void set(SecurityContext securityContext) {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession != null && vaadinSession.hasLock()) {
        vaadinSession.setAttribute(SecurityContext.clreplaced, securityContext);
    } else {
        super.set(securityContext);
    }
}

18 View Complete Implementation : WebTextFieldTest.java
Copyright Apache License 2.0
Author : cuba-platform
public clreplaced WebTextFieldTest extends TextFieldTest {

    @Mocked
    protected VaadinSession vaadinSession;

    @Mocked
    protected DataAwareComponentsTools dataAwareComponentsTools;

    @Override
    protected void initExpectations() {
        super.initExpectations();
        new Expectations() {

            {
                vaadinSession.getLocale();
                result = Locale.ENGLISH;
                minTimes = 0;
                VaadinSession.getCurrent();
                result = vaadinSession;
                minTimes = 0;
                globalConfig.getAvailableLocales();
                result = ImmutableMap.of("en", Locale.ENGLISH);
                minTimes = 0;
                AppContext.getProperty("cuba.mainMessagePack");
                result = "com.haulmont.cuba.web";
                minTimes = 0;
            }
        };
        this.uiComponents = new TestUiComponents(applicationContext);
    }

    @Override
    protected void autowireUiComponent(Component component) {
        super.autowireUiComponent(component);
        WebTextField textField = (WebTextField) component;
        textField.setUserSessionSource(userSessionSource);
        textField.setBeanLocator(beanLocator);
        textField.setDataAwareComponentsTools(dataAwareComponentsTools);
    }
}

18 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
public static String getServiceURL(VaadinSession session) {
    if (session != null) {
        String overriddenByInit = session.getConfiguration().getInitParameters().getProperty("AnnisWebService.URL");
        ;
        if (overriddenByInit != null) {
            return overriddenByInit;
        }
    }
    return cfg.webserviceURL();
}

18 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
public static boolean isKickstarter(VaadinSession session) {
    if (session != null) {
        return Boolean.parseBoolean(session.getConfiguration().getInitParameters().getProperty("kickstarterEnvironment", "false"));
    } else {
        return false;
    }
}

18 View Complete Implementation : SockJSPushHandler.java
Copyright MIT License
Author : mcollovati
/**
 * Checks whether a given push id matches the session's push id.
 *
 * @param session       the vaadin session for which the check should be done
 * @param requestPushId the push id provided in the request
 * @return {@code true} if the id is valid, {@code false} otherwise
 */
private static boolean isPushIdValid(VaadinSession session, String requestPushId) {
    String sessionPushId = session.getPushId();
    return requestPushId != null && requestPushId.equals(sessionPushId);
}

18 View Complete Implementation : VertxVaadinService.java
Copyright MIT License
Author : mcollovati
// Adapted from VaadinServletService
@Override
public String getMainDivId(VaadinSession session, VaadinRequest request, Clreplaced<? extends UI> uiClreplaced) {
    String appId = request.getPathInfo();
    if (appId == null || "".equals(appId) || "/".equals(appId)) {
        appId = "ROOT";
    }
    appId = appId.replaceAll("[^a-zA-Z0-9]", "");
    // Add hashCode to the end, so that it is still (sort of)
    // predictable, but indicates that it should not be used in CSS
    // and
    // such:
    int hashCode = appId.hashCode();
    if (hashCode < 0) {
        hashCode = -hashCode;
    }
    appId = appId + "-" + hashCode;
    return appId;
}

18 View Complete Implementation : CurrentUser.java
Copyright The Unlicense
Author : vaadin
private static WrappedSession getCurrentHttpSession() {
    VaadinSession s = VaadinSession.getCurrent();
    if (s == null) {
        throw new IllegalStateException("No session found for current thread");
    }
    return s.getSession();
}

18 View Complete Implementation : App.java
Copyright Apache License 2.0
Author : cuba-platform
/**
 * @return true if an {@link App} instance is currently bound and can be safely obtained by {@link #getInstance()}
 */
public static boolean isBound() {
    VaadinSession vSession = VaadinSession.getCurrent();
    return vSession != null && vSession.hasLock() && vSession.getAttribute(App.clreplaced) != null;
}

17 View Complete Implementation : PDFVisualizer.java
Copyright Apache License 2.0
Author : korpling
@Override
public Panel createComponent(VisualizerInput input, VisualizationToggle visToggle) {
    PDFViewer pdfViewer = null;
    try {
        if (VaadinSession.getCurrent().getAttribute(PDFController.clreplaced) != null) {
            VaadinSession session = VaadinSession.getCurrent();
            PDFController pdfController = session.getAttribute(PDFController.clreplaced);
            pdfViewer = new PDFViewerImpl(input, visToggle);
            pdfController.addPDF(input.getId(), pdfViewer);
        }
    } catch (Exception ex) {
        log.error("could not create pdf vis", ex);
    }
    return (Panel) pdfViewer;
}

17 View Complete Implementation : SockJSPushHandler.java
Copyright MIT License
Author : mcollovati
/**
 * Call the session's {@link ErrorHandler}, if it has one, with the given
 * exception wrapped in an {@link ErrorEvent}.
 */
private void callErrorHandler(VaadinSession session, Exception e) {
    try {
        ErrorHandler errorHandler = ErrorEvent.findErrorHandler(session);
        if (errorHandler != null) {
            errorHandler.error(new ErrorEvent(e));
        }
    } catch (Exception ex) {
        // Let's not allow error handling to cause trouble; log fails
        logger.warn("ErrorHandler call failed", ex);
    }
}

17 View Complete Implementation : UiServlet.java
Copyright Apache License 2.0
Author : opensecuritycontroller
/**
 * Every incoming request should set the current user context
 */
@Override
protected VaadinServletRequest createVaadinRequest(HttpServletRequest request) {
    VaadinServletRequest vaadinRequest = super.createVaadinRequest(request);
    VaadinSession vaadinSession;
    try {
        vaadinSession = getService().findVaadinSession(vaadinRequest);
    } catch (Exception e) {
        // This exception will be handled later when we try to service
        // the request
        vaadinSession = null;
    }
    if (vaadinSession != null) {
        this.userContext.setUser((String) vaadinSession.getAttribute("user"));
    } else {
        this.userContext.setUser(null);
    }
    return vaadinRequest;
}

17 View Complete Implementation : VaadinScope.java
Copyright Apache License 2.0
Author : chelu
private String getConversationId(Integer id) {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null) {
        log.info("Request Conversation id without session");
        return null;
    }
    return session.getSession().getId() + ":" + id.toString();
}

17 View Complete Implementation : App.java
Copyright Apache License 2.0
Author : cuba-platform
/**
 * @return Current App instance. Can be invoked anywhere in application code.
 * @throws IllegalStateException if no application instance is bound to the current {@link VaadinSession}
 */
public static App getInstance() {
    VaadinSession vSession = VaadinSession.getCurrent();
    if (vSession == null) {
        throw new IllegalStateException("No VaadinSession found");
    }
    if (!vSession.hasLock()) {
        throw new IllegalStateException("VaadinSession is not owned by the current thread");
    }
    App app = vSession.getAttribute(App.clreplaced);
    if (app == null) {
        throw new IllegalStateException("No App is bound to the current VaadinSession");
    }
    return app;
}

17 View Complete Implementation : AppSession.java
Copyright GNU General Public License v3.0
Author : JumpMind
public clreplaced AppSession implements Serializable {

    private static final long serialVersionUID = 1L;

    private static List<AppSession> appSessions = new ArrayList<>();

    public static synchronized List<AppSession> getAppSessions() {
        return new ArrayList<>(appSessions);
    }

    public static synchronized void addAppSession(AppSession appSession) {
        appSessions.add(appSession);
    }

    public static synchronized void remove(AppSession appSession) {
        appSessions.remove(appSession);
    }

    User user;

    String remoteUser;

    String remoteAddress;

    String remoteHost;

    String userAgent;

    VaadinSession vaadinSession;

    Date loginTime;

    public AppSession(String remoteUser, String remoteAddress, String remoteHost, VaadinSession vaadinSession, String userAgent, Date createTime) {
        this.remoteUser = remoteUser;
        this.remoteAddress = remoteAddress;
        this.remoteHost = remoteHost;
        this.vaadinSession = vaadinSession;
        this.loginTime = createTime;
        this.userAgent = userAgent;
    }

    public boolean equals(Object o) {
        if (o != null && o instanceof AppSession) {
            AppSession appSession = (AppSession) o;
            if (vaadinSession.getSession() == null || appSession.getVaadinSession().getSession() == null) {
                return user.getLoginId().equals(appSession.user.getLoginId()) && remoteAddress.equals(appSession.remoteAddress) && loginTime.equals(appSession.loginTime);
            } else {
                return vaadinSession.getSession().getId().equals(((AppSession) o).vaadinSession.getSession().getId());
            }
        }
        return false;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getLoginId() {
        return user.getLoginId();
    }

    /**
     * @return the remoteUser
     */
    public String getRemoteUser() {
        return remoteUser;
    }

    /**
     * @return the remoteAddress
     */
    public String getRemoteAddress() {
        return remoteAddress;
    }

    /**
     * @return the remoteHost
     */
    public String getRemoteHost() {
        return remoteHost;
    }

    public Date getLastActivity() {
        return new Date(vaadinSession.getLastRequestTimestamp());
    }

    /**
     * @return the createTime
     */
    public Date getLoginTime() {
        return loginTime;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public VaadinSession getVaadinSession() {
        return vaadinSession;
    }

    public User getUser() {
        return user;
    }
}

17 View Complete Implementation : MainToolbar.java
Copyright Apache License 2.0
Author : korpling
/**
 * Adds the login button + login text to the toolbar. This is only happened,
 * when the gui is not started via the kickstarter.
 *
 * <p>
 * The Kickstarter overrides the "kickstarterEnvironment" context parameter
 * and set it to "true", so the gui can detect, that is not necessary to offer
 * a login button.</p>
 *
 * component.
 */
private void addLoginButton() {
    VaadinSession session = VaadinSession.getCurrent();
    if (session != null) {
        boolean kickstarter = Helper.isKickstarter(session);
        if (!kickstarter) {
            addComponent(lblUserName);
            setComponentAlignment(lblUserName, Alignment.MIDDLE_RIGHT);
            addComponent(btLogin);
            setComponentAlignment(btLogin, Alignment.MIDDLE_RIGHT);
        }
    }
}

17 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
public static AnnisUser getUser(UI ui) {
    if (ui != null) {
        VaadinSession vSession = ui.getSession();
        return getUser(vSession);
    }
    return null;
}

17 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
/**
 * Gets or creates a web resource to the ANNIS service.
 *
 * This is a convenience wrapper to
 * {@link #getAnnisWebResource(java.lang.String, annis.security.AnnisUser) }
 * that does not need any arguments
 *
 * @return A reference to the ANNIS service root resource.
 */
public static WebResource getAnnisWebResource(UI ui) {
    if (ui != null) {
        VaadinSession vSession = ui.getSession();
        return getAnnisWebResource(vSession);
    } else {
        return null;
    }
}

16 View Complete Implementation : WebSettingsClient.java
Copyright Apache License 2.0
Author : cuba-platform
public void clearCache() {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null || !session.hasLock()) {
        throw new IllegalConcurrentAccessException("Illegal access to settings client from background thread");
    }
    session.setAttribute(SettingsClient.NAME, null);
}

16 View Complete Implementation : WebSettingsClient.java
Copyright Apache License 2.0
Author : cuba-platform
protected Map<String, Optional<String>> getCache() {
    VaadinSession session = VaadinSession.getCurrent();
    if (session == null || !session.hasLock()) {
        throw new IllegalConcurrentAccessException("Illegal access to settings client from background thread");
    }
    @SuppressWarnings("unchecked")
    Map<String, Optional<String>> settings = (Map<String, Optional<String>>) session.getAttribute(SettingsClient.NAME);
    if (settings == null) {
        settings = new HashMap<>();
        session.setAttribute(SettingsClient.NAME, settings);
    }
    return settings;
}

16 View Complete Implementation : ShortenerRequestHandler.java
Copyright Apache License 2.0
Author : korpling
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    String id = request.getParameter("id");
    if (id == null) {
        return false;
    }
    // get the actual URL
    WebResource res = Helper.getAnnisWebResource(session);
    res = res.path("shortener").path(id);
    String longURL = res.get(String.clreplaced);
    // redirects only work in http servlets
    if (response instanceof VaadinServletResponse) {
        ServletResponse servletResponse = ((VaadinServletResponse) response).getResponse();
        if (servletResponse instanceof HttpServletResponse) {
            HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
            httpResponse.setHeader("Location", request.getContextPath() + longURL);
            // temporary redirect
            httpResponse.setStatus(307);
            return true;
        }
    }
    return false;
}

16 View Complete Implementation : Helper.java
Copyright Apache License 2.0
Author : korpling
public static AnnisUser getUser(VaadinSession vSession) {
    WrappedSession wrappedSession = null;
    if (vSession != null) {
        wrappedSession = vSession.getSession();
    }
    if (wrappedSession != null) {
        Object o = wrappedSession.getAttribute(AnnisBaseUI.USER_KEY);
        if (o != null && o instanceof AnnisUser) {
            return (AnnisUser) o;
        }
    }
    return null;
}

16 View Complete Implementation : UiServlet.java
Copyright Apache License 2.0
Author : opensecuritycontroller
@Deactivate
void stop() {
    // Terminate Vaadin UI Application
    destroy();
    for (VaadinSession vaadinSession : sessions) {
        vaadinSession.close();
        // Redirect all UIs to force the close
        for (UI ui : vaadinSession.getUIs()) {
            ui.access(() -> ui.getPage().setLocation("/"));
        }
    }
}

15 View Complete Implementation : BinaryRequestHandler.java
Copyright Apache License 2.0
Author : korpling
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            sendResponse(session, request, response, true);
            return true;
        } else if ("HEAD".equalsIgnoreCase(request.getMethod())) {
            sendResponse(session, request, response, false);
            return true;
        }
    }
    return false;
}

15 View Complete Implementation : LoginServletRequestHandler.java
Copyright Apache License 2.0
Author : korpling
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        if ("GET".equalsIgnoreCase(request.getMethod())) {
            doGet(session, request, response);
            return true;
        } else if ("POST".equalsIgnoreCase(request.getMethod())) {
            doPost(session, request, response);
            return true;
        }
    }
    return false;
}

15 View Complete Implementation : AbstractIFrameVisualizer.java
Copyright Apache License 2.0
Author : korpling
@Override
public Component createComponent(final VisualizerInput vis, VisualizationToggle visToggle) {
    VaadinSession session = vis.getUI().getSession();
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    writeOutput(vis, outStream);
    IFrameResource res = new IFrameResource();
    res.setData(outStream.toByteArray());
    res.setMimeType(getContentType());
    UUID uuid = UUID.randomUUID();
    session.getAttribute(IFrameResourceMap.clreplaced).put(uuid, res);
    URI base;
    try {
        String ctx = Helper.getContext(vis.getUI());
        if (!ctx.endsWith("/")) {
            ctx = ctx + "/";
        }
        base = new URI(ctx);
    } catch (URISyntaxException e) {
        log.warn("Getting context failed, falling back to using the complete URL, which will fail if ANNIS used with an instance URL", e);
        base = vis.getUI().getPage().getLocation();
    }
    AutoHeightIFrame iframe = new AutoHeightIFrame(base.resolve("vis-iframe-res/" + uuid.toString()));
    return iframe;
}

15 View Complete Implementation : UiListenerDelegate.java
Copyright Apache License 2.0
Author : opensecuritycontroller
// Close vaadin sessions replacedociated to the given loginName,
// or all sessions if loginName is null.
private void closeUserVaadinSessions(String loginName) {
    // CopyOnWriteArrayList is thread safe for iteration under update
    for (HttpSession session : this.sessions) {
        for (VaadinSession vaadinSession : VaadinSession.getAllSessions(session)) {
            Object userName = vaadinSession.getAttribute("user");
            if (loginName == null || loginName.equals(userName)) {
                vaadinSession.close();
                // Redirect all UIs to force the close
                for (UI ui : vaadinSession.getUIs()) {
                    ui.access(() -> {
                        ui.getPage().setLocation("/");
                    });
                }
            }
        }
    }
}

12 View Complete Implementation : App.java
Copyright Apache License 2.0
Author : cuba-platform
/**
 * Called when <em>the first</em> UI of the session is initialized.
 */
protected void init(Locale requestLocale) {
    VaadinSession vSession = VaadinSession.getCurrent();
    vSession.setAttribute(App.clreplaced, this);
    vSession.setLocale(messageTools.getDefaultLocale());
    // set root error handler for all session
    vSession.setErrorHandler(event -> {
        try {
            getExceptionHandlers().handle(event);
            getAppLog().log(event);
        } catch (Throwable e) {
            log.error("Error handling exception\nOriginal exception:\n{}\nException in handlers:\n{}", ExceptionUtils.getStackTrace(event.getThrowable()), ExceptionUtils.getStackTrace(e));
        }
    });
    log.debug("Initializing application");
    appLog = new AppLog(webConfig.getAppLogMaxItemsCount(), beanLocator.get(TimeSource.NAME));
    connection = createConnection();
    exceptionHandlers = new ExceptionHandlers(this, beanLocator);
    cookies = new AppCookies();
    themeConstants = loadTheme();
    // get default locale from config
    Locale targetLocale = resolveLocale(requestLocale);
    setLocale(targetLocale);
}

10 View Complete Implementation : CitizenIntelligenceAgencySpringVaadinServlet.java
Copyright Apache License 2.0
Author : Hack23
@Override
protected void servletInitialized() throws ServletException {
    final VaadinServletService service = getService();
    service.addSessionInitListener(event -> {
        final VaadinSession session = event.getSession();
        for (final UIProvider provider : session.getUIProviders()) {
            if (DefaultUIProvider.clreplaced.getCanonicalName().equals(provider.getClreplaced().getCanonicalName())) {
                session.removeUIProvider(provider);
            }
        }
        session.addUIProvider(new CustomSpringUIProvider(session));
    });
    service.addSessionDestroyListener(event -> {
        final VaadinSession session = event.getSession();
        UIScopeImpl.cleanupSession(session);
        VaadinSessionScope.cleanupSession(session);
    });
}

9 View Complete Implementation : SchemeRequestHandler.java
Copyright Apache License 2.0
Author : consulo
@Override
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    response.setContentType("text/css");
    byte[] text = generateCss();
    response.setCacheTime(-1);
    response.setStatus(HttpURLConnection.HTTP_OK);
    try (OutputStream stream = response.getOutputStream()) {
        response.setContentLength(text.length);
        stream.write(text);
    }
    return true;
}

9 View Complete Implementation : LoginServletRequestHandler.java
Copyright Apache License 2.0
Author : korpling
private void doGet(VaadinSession session, VaadinRequest request, VaadinResponse response) {
    response.setContentType("text/html");
    OutputStream out = null;
    try {
        out = response.getOutputStream();
        String htmlSource = Resources.toString(LoginServletRequestHandler.clreplaced.getResource("login.html"), Charsets.UTF_8);
        htmlSource = htmlSource.replaceAll("%usercaption%", "Username").replaceAll("%preplacedwordcaption%", "Preplacedword").replaceAll("%replacedle%", "ANNIS Login").replaceAll("%logincaption%", "Login").replaceAll("%or%", "or").replaceAll("%cancelcaption%", "Cancel");
        try (OutputStreamWriter writer = new OutputStreamWriter(out, Charsets.UTF_8)) {
            CharStreams.copy(new StringReader(htmlSource), writer);
            out.flush();
        }
    } catch (IOException ex) {
        log.error(null, ex);
    } catch (Exception ex) {
        log.error(null, ex);
    } finally {
        response.setStatus(200);
        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                log.error("closing OutputStream filed", ex);
            }
        }
    }
}

9 View Complete Implementation : ResourceRequestHandler.java
Copyright Apache License 2.0
Author : korpling
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
    if (request.getPathInfo() != null && request.getPathInfo().startsWith(prefix)) {
        String uuidString = StringUtils.removeStart(request.getPathInfo(), prefix);
        UUID uuid = UUID.fromString(uuidString);
        IFrameResourceMap map = VaadinSession.getCurrent().getAttribute(IFrameResourceMap.clreplaced);
        if (map == null) {
            response.setStatus(404);
        } else {
            IFrameResource res = map.get(uuid);
            if (res != null) {
                response.setStatus(200);
                response.setContentType(res.getMimeType());
                response.getOutputStream().write(res.getData());
            }
        }
        return true;
    }
    return false;
}

9 View Complete Implementation : SockJSPushHandler.java
Copyright MIT License
Author : mcollovati
void connectionLost(PushEvent event) {
    // We don't want to use callWithUi here, as it replacedumes there's a client
    // request active and does requestStart and requestEnd among other
    // things.
    VaadinRequest vaadinRequest = new VertxVaadinRequest(service, event.routingContext);
    VaadinSession session;
    try {
        session = service.findVaadinSession(vaadinRequest);
    } catch (ServiceException e) {
        logger.error("Could not get session. This should never happen", e);
        return;
    } catch (SessionExpiredException e) {
        // This happens at least if the server is restarted without
        // preserving the session. After restart the client reconnects, gets
        // a session expired notification and then closes the connection and
        // ends up here
        logger.debug("Session expired before push disconnect event was received", e);
        return;
    }
    UI ui;
    session.lock();
    try {
        VaadinSession.setCurrent(session);
        // Sets UI.currentInstance
        ui = service.findUI(vaadinRequest);
        if (ui == null) {
            /*
                 * UI not found, could be because FF has asynchronously closed
                 * the websocket connection and Atmosphere has already done
                 * cleanup of the request attributes.
                 *
                 * In that case, we still have a chance of finding the right UI
                 * by iterating through the UIs in the session looking for one
                 * using the same AtmosphereResource.
                 */
            ui = findUiUsingSocket(event.socket(), session.getUIs());
            if (ui == null) {
                logger.debug("Could not get UI. This should never happen," + " except when reloading in Firefox and Chrome -" + " see http://dev.vaadin.com/ticket/14251.");
                return;
            } else {
                logger.info("No UI was found based on data in the request," + " but a slower lookup based on the AtmosphereResource succeeded." + " See http://dev.vaadin.com/ticket/14251 for more details.");
            }
        }
        PushMode pushMode = ui.getPushConfiguration().getPushMode();
        SockJSPushConnection pushConnection = getConnectionForUI(ui);
        String id = event.socket().getUUID();
        if (pushConnection == null) {
            logger.warn("Could not find push connection to close: {} with transport {}", id, "resource.transport()");
        } else {
            if (!pushMode.isEnabled()) {
                /*
                     * The client is expected to close the connection after push
                     * mode has been set to disabled.
                     */
                logger.debug("Connection closed for resource {}", id);
            } else {
                /*
                     * Unexpected cancel, e.g. if the user closes the browser
                     * tab.
                     */
                logger.debug("Connection unexpectedly closed for resource {} with transport {}", id, "resource.transport()");
            }
            pushConnection.connectionLost();
        }
    } catch (final Exception e) {
        callErrorHandler(session, e);
    } finally {
        try {
            session.unlock();
        } catch (Exception e) {
            logger.warn("Error while unlocking session", e);
        // can't call ErrorHandler, we (hopefully) don't have a lock
        }
    }
}

7 View Complete Implementation : TestUiEnvironment.java
Copyright Apache License 2.0
Author : cuba-platform
protected void setupVaadinUi() {
    AutowireCapableBeanFactory injector = getInjector();
    app = new DefaultApp();
    setThemeConstants(app, new ThemeConstants(new HashMap<>()));
    setCookies(app, new AppCookies());
    Connection connection = new ConnectionImpl();
    injector.autowireBean(connection);
    setConnection(app, connection);
    VaadinSession vaadinSession = new TestVaadinSession(new WebBrowser(), getLocale());
    vaadinSession.setAttribute(App.clreplaced, app);
    vaadinSession.setAttribute(App.NAME, app);
    vaadinSession.setAttribute(Connection.clreplaced, connection);
    vaadinSession.setAttribute(Connection.NAME, connection);
    vaadinSession.setAttribute(UserSession.clreplaced, sessionSource.getSession());
    VaadinSession.setCurrent(vaadinSession);
    injector.autowireBean(app);
    ui = new AppUI();
    injector.autowireBean(ui);
    // setup UI
    ConnectorTracker connectorTracker = new TestConnectorTracker(ui);
    try {
        getDeclaredField(UI.clreplaced, "connectorTracker", true).set(ui, connectorTracker);
        getDeclaredField(UI.clreplaced, "session", true).set(ui, vaadinSession);
    } catch (Exception e) {
        throw new RuntimeException("Unable to init Vaadin UI state", e);
    }
    UI.setCurrent(ui);
    VaadinRequest vaadinRequest = new TestVaadinRequest();
    ui.getPage().init(vaadinRequest);
    initUi(ui, vaadinRequest);
}