Browse Source

Detect Atmosphere in the same way for servlets and portlets (#11493)

Change-Id: I6c153291045a35f253cd7e6987d7eb90dbc93a1e
tags/7.6.0.alpha7
Artur Signell 8 years ago
parent
commit
2d2418516a

+ 39
- 6
server/src/com/vaadin/server/VaadinService.java View File

@@ -52,6 +52,7 @@ import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.event.EventRouter;
import com.vaadin.server.VaadinSession.FutureAccess;
import com.vaadin.server.VaadinSession.State;
import com.vaadin.server.communication.AtmospherePushConnection;
import com.vaadin.server.communication.FileUploadHandler;
import com.vaadin.server.communication.HeartbeatHandler;
import com.vaadin.server.communication.PublishedFileHandler;
@@ -133,6 +134,8 @@ public abstract class VaadinService implements Serializable {

private Iterable<RequestHandler> requestHandlers;

private boolean atmosphereAvailable = checkAtmosphereSupport();

/**
* Keeps track of whether a warning about missing push support has already
* been logged. This is used to avoid spamming the log with the same message
@@ -1625,13 +1628,43 @@ public abstract class VaadinService implements Serializable {
* is not available.
*/
public boolean ensurePushAvailable() {
if (!pushWarningEmitted) {
pushWarningEmitted = true;
getLogger().log(Level.WARNING, Constants.PUSH_NOT_SUPPORTED_ERROR,
getClass().getSimpleName());
if (atmosphereAvailable) {
return true;
} else {
if (!pushWarningEmitted) {
pushWarningEmitted = true;
getLogger().log(Level.WARNING,
Constants.ATMOSPHERE_MISSING_ERROR);
}
return false;
}
// Not supported by default for now, sublcasses may override
return false;
}

private static boolean checkAtmosphereSupport() {
String rawVersion = AtmospherePushConnection.getAtmosphereVersion();
if (rawVersion == null) {
return false;
}

if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION.equals(rawVersion)) {
getLogger().log(
Level.WARNING,
Constants.INVALID_ATMOSPHERE_VERSION_WARNING,
new Object[] {
Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION,
rawVersion });
}
return true;
}

/**
* Checks whether Atmosphere is avilable for use
*
* @since
* @return true if Atmosphere is available, false otherwise
*/
protected boolean isAtmosphereAvailable() {
return atmosphereAvailable;
}

/**

+ 1
- 42
server/src/com/vaadin/server/VaadinServletService.java View File

@@ -27,7 +27,6 @@ import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import com.vaadin.server.communication.AtmospherePushConnection;
import com.vaadin.server.communication.PushRequestHandler;
import com.vaadin.server.communication.ServletBootstrapHandler;
import com.vaadin.server.communication.ServletUIInitHandler;
@@ -36,15 +35,6 @@ import com.vaadin.ui.UI;
public class VaadinServletService extends VaadinService {
private final VaadinServlet servlet;

private boolean atmosphereAvailable = checkAtmosphereSupport();

/**
* Keeps track of whether a warning about missing push support has already
* been logged. This is used to avoid spamming the log with the same message
* every time a new UI is bootstrapped.
*/
private boolean pushWarningLogged = false;

public VaadinServletService(VaadinServlet servlet,
DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
@@ -52,30 +42,13 @@ public class VaadinServletService extends VaadinService {
this.servlet = servlet;
}

private static boolean checkAtmosphereSupport() {
String rawVersion = AtmospherePushConnection.getAtmosphereVersion();
if (rawVersion == null) {
return false;
}

if (!Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION.equals(rawVersion)) {
getLogger().log(
Level.WARNING,
Constants.INVALID_ATMOSPHERE_VERSION_WARNING,
new Object[] {
Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION,
rawVersion });
}
return true;
}

@Override
protected List<RequestHandler> createRequestHandlers()
throws ServiceException {
List<RequestHandler> handlers = super.createRequestHandlers();
handlers.add(0, new ServletBootstrapHandler());
handlers.add(new ServletUIInitHandler());
if (atmosphereAvailable) {
if (isAtmosphereAvailable()) {
try {
handlers.add(new PushRequestHandler(this));
} catch (ServiceException e) {
@@ -86,7 +59,6 @@ public class VaadinServletService extends VaadinService {
.log(Level.WARNING,
"Error initializing Atmosphere. Push will not work.",
e);
atmosphereAvailable = false;
}
}
return handlers;
@@ -271,17 +243,4 @@ public class VaadinServletService extends VaadinService {
return Logger.getLogger(VaadinServletService.class.getName());
}

@Override
public boolean ensurePushAvailable() {
if (atmosphereAvailable) {
return true;
} else {
if (!pushWarningLogged) {
pushWarningLogged = true;
getLogger().log(Level.WARNING,
Constants.ATMOSPHERE_MISSING_ERROR);
}
return false;
}
}
}

Loading…
Cancel
Save