diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2013-05-20 15:08:48 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-05-21 07:35:04 +0000 |
commit | 42c4b2097bc955ca18107c449e04f0d5d5683ca3 (patch) | |
tree | 2b441ac94efff0b0b4671d3b673d208efdf4b8b9 /server/src | |
parent | 2772641acf8f84046e3ac42c8386b65e4f2346f2 (diff) | |
download | vaadin-framework-42c4b2097bc955ca18107c449e04f0d5d5683ca3.tar.gz vaadin-framework-42c4b2097bc955ca18107c449e04f0d5d5683ca3.zip |
Use "\0" instead of "|" as a push message delimiter (#11692)
Used with TrackMessageSizeInterceptor and with client-to-server Websocket message splitting (see #11648)
The original issue that the delimiter can not appear in the message (unescaped) is apparently fixed in Atmosphere 1.0.13
Also ensure the max size of a websocket fragment in bytes does not exceed the buffer size (#11842)
Change-Id: I768524bb54a5b8b9479dc7bda821256bd843dc52
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/com/vaadin/server/communication/AtmospherePushConnection.java | 9 | ||||
-rw-r--r-- | server/src/com/vaadin/server/communication/PushRequestHandler.java | 17 |
2 files changed, 16 insertions, 10 deletions
diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 0bba65ff1d..96507b55f1 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -32,7 +32,7 @@ import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.AtmosphereResource.TRANSPORT; import org.json.JSONException; -import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.communication.PushConstants; import com.vaadin.ui.UI; /** @@ -52,11 +52,12 @@ public class AtmospherePushConnection implements Serializable, PushConnection { private final int messageLength; public FragmentedMessage(Reader reader) throws IOException { - // Messages are prefixed by the total message length plus '|' + // Messages are prefixed by the total message length plus a + // delimiter String length = ""; int c; while ((c = reader.read()) != -1 - && c != ApplicationConstants.WEBSOCKET_MESSAGE_DELIMITER) { + && c != PushConstants.MESSAGE_DELIMITER) { length += (char) c; } try { @@ -76,7 +77,7 @@ public class AtmospherePushConnection implements Serializable, PushConnection { * @throws IOException */ public boolean append(Reader reader) throws IOException { - char[] buffer = new char[ApplicationConstants.WEBSOCKET_BUFFER_SIZE]; + char[] buffer = new char[PushConstants.WEBSOCKET_BUFFER_SIZE]; int read; while ((read = reader.read(buffer)) != -1) { message.append(buffer, 0, read); diff --git a/server/src/com/vaadin/server/communication/PushRequestHandler.java b/server/src/com/vaadin/server/communication/PushRequestHandler.java index 8360e08af9..e75798a980 100644 --- a/server/src/com/vaadin/server/communication/PushRequestHandler.java +++ b/server/src/com/vaadin/server/communication/PushRequestHandler.java @@ -23,6 +23,7 @@ import javax.servlet.ServletException; import org.atmosphere.client.TrackMessageSizeInterceptor; import org.atmosphere.cpr.ApplicationConfig; import org.atmosphere.cpr.AtmosphereFramework; +import org.atmosphere.cpr.AtmosphereInterceptor; import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResponse; @@ -36,7 +37,7 @@ import com.vaadin.server.VaadinServletRequest; import com.vaadin.server.VaadinServletResponse; import com.vaadin.server.VaadinServletService; import com.vaadin.server.VaadinSession; -import com.vaadin.shared.ApplicationConstants; +import com.vaadin.shared.communication.PushConstants; /** * Handles requests to open a push (bidirectional) communication channel between @@ -61,9 +62,11 @@ public class PushRequestHandler implements RequestHandler, atmosphere.addAtmosphereHandler("/*", pushHandler); atmosphere.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true"); + atmosphere.addInitParameter(ApplicationConfig.MESSAGE_DELIMITER, + String.valueOf(PushConstants.MESSAGE_DELIMITER)); final String bufferSize = String - .valueOf(ApplicationConstants.WEBSOCKET_BUFFER_SIZE); + .valueOf(PushConstants.WEBSOCKET_BUFFER_SIZE); atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE, bufferSize); atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE, @@ -75,12 +78,14 @@ public class PushRequestHandler implements RequestHandler, atmosphere.addInitParameter("org.atmosphere.cpr.showSupportMessage", "false"); - // Required to ensure the client-side knows at which points to split the - // message stream into individual messages when using certain transports - atmosphere.interceptor(new TrackMessageSizeInterceptor()); - try { atmosphere.init(service.getServlet().getServletConfig()); + + // Ensure the client-side knows how to split the message stream + // into individual messages when using certain transports + AtmosphereInterceptor trackMessageSize = new TrackMessageSizeInterceptor(); + trackMessageSize.configure(atmosphere.getAtmosphereConfig()); + atmosphere.interceptor(trackMessageSize); } catch (ServletException e) { throw new ServiceException("Could not read atmosphere settings", e); } |