@Override public void run(AtmosphereResource resource, UI ui) throws IOException { getLogger() .log(Level.FINER, "New push connection with transport {0}", resource.transport()); resource.getResponse().setContentType("text/plain; charset=UTF-8"); VaadinSession session = ui.getSession(); if (resource.transport() == TRANSPORT.STREAMING) { // IE8 requires a longer padding to work properly if the // initial message is small (#11573). Chrome does not work // without the original padding... WebBrowser browser = session.getBrowser(); if (browser.isIE() && browser.getBrowserMajorVersion() == 8) { resource.padding(LONG_PADDING); } // Must ensure that the streaming response contains // "Connection: close", otherwise iOS 6 will wait for the // response to this request before sending another request to // the same server (as it will apparently try to reuse the same // connection) resource.getResponse().addHeader("Connection", "close"); } String requestToken = resource.getRequest().getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER); if (!VaadinService.isCsrfTokenValid(session, requestToken)) { getLogger() .log( Level.WARNING, "Invalid CSRF token in new connection received from {0}", resource.getRequest().getRemoteHost()); // Refresh on client side, create connection just for // sending a message sendRefreshAndDisconnect(resource); return; } resource.suspend(); AtmospherePushConnection connection = new AtmospherePushConnection(ui); connection.connect(resource); ui.setPushConnection(connection); }