From 8d37e1c4ae369a71b1c95aa76843594f2cc750cb Mon Sep 17 00:00:00 2001 From: jfarcand Date: Tue, 31 Mar 2015 12:57:29 -0400 Subject: [PATCH] Fixes #1931 --- .../src/main/java/org/atmosphere/cpr/AtmosphereRequest.java | 2 +- .../cpr/src/main/java/org/atmosphere/cpr/FrameworkConfig.java | 4 ++++ .../java/org/atmosphere/websocket/protocol/ProtocolUtil.java | 2 -- .../org/atmosphere/websocket/protocol/SimpleHttpProtocol.java | 2 ++ .../atmosphere/websocket/protocol/StreamingHttpProtocol.java | 4 +++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java index 8da5d88ee6..f3e75b5dec 100644 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereRequest.java @@ -1247,7 +1247,7 @@ public Builder localInetSocketAddress(Callable localAddr) { } public Builder attributes(Map attributes) { - localAttributes = Collections.synchronizedMap(attributes); + localAttributes = ConcurrentHashMap.class.isAssignableFrom(attributes.getClass()) ? attributes : Collections.synchronizedMap(attributes); return this; } diff --git a/modules/cpr/src/main/java/org/atmosphere/cpr/FrameworkConfig.java b/modules/cpr/src/main/java/org/atmosphere/cpr/FrameworkConfig.java index 170250cfe3..f5c1ca4a0b 100644 --- a/modules/cpr/src/main/java/org/atmosphere/cpr/FrameworkConfig.java +++ b/modules/cpr/src/main/java/org/atmosphere/cpr/FrameworkConfig.java @@ -110,6 +110,10 @@ public interface FrameworkConfig { * The SimpleHttpProtocol. */ String SIMPLE_HTTP_OVER_WEBSOCKET = "polling-websocket-message"; + /** + * The SimpleHttpProtocol. + */ + String STREAMING_HTTP_OVER_WEBSOCKET = "streaming-websocket-message"; /** * Cancel suspending a connection. */ diff --git a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/ProtocolUtil.java b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/ProtocolUtil.java index 4c7c6957b5..31b471e9ea 100644 --- a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/ProtocolUtil.java +++ b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/ProtocolUtil.java @@ -18,7 +18,6 @@ import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.AtmosphereResourceImpl; -import org.atmosphere.cpr.FrameworkConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,7 +56,6 @@ protected static AtmosphereRequest.Builder constructRequest(AtmosphereResource r private static Map attributes(AtmosphereRequest request) { Map m = new ConcurrentHashMap(); - m.put(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.SIMPLE_HTTP_OVER_WEBSOCKET); /*** * This is quite ugly, but the some server may allow null attribute and that break ConcurrentHashMap */ diff --git a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/SimpleHttpProtocol.java b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/SimpleHttpProtocol.java index c2008e94f9..e27c9d781d 100644 --- a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/SimpleHttpProtocol.java +++ b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/SimpleHttpProtocol.java @@ -19,6 +19,7 @@ import org.atmosphere.cpr.AtmosphereConfig; import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResourceImpl; +import org.atmosphere.cpr.FrameworkConfig; import org.atmosphere.websocket.WebSocket; import org.atmosphere.websocket.WebSocketProcessor; import org.atmosphere.websocket.WebSocketProtocol; @@ -88,6 +89,7 @@ public List onMessage(WebSocket webSocket, String message) { return null; } AtmosphereRequest request = resource.getRequest(false); + request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.SIMPLE_HTTP_OVER_WEBSOCKET); if (!resource.isInScope()) return Collections.emptyList(); diff --git a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/StreamingHttpProtocol.java b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/StreamingHttpProtocol.java index 0a53b815b9..7e594399ee 100644 --- a/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/StreamingHttpProtocol.java +++ b/modules/cpr/src/main/java/org/atmosphere/websocket/protocol/StreamingHttpProtocol.java @@ -19,6 +19,7 @@ import org.atmosphere.cpr.AtmosphereConfig; import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResourceImpl; +import org.atmosphere.cpr.FrameworkConfig; import org.atmosphere.websocket.WebSocket; import org.atmosphere.websocket.WebSocketProcessor; import org.atmosphere.websocket.WebSocketProtocolStream; @@ -95,9 +96,10 @@ public List onTextStream(WebSocket webSocket, Reader r) { } AtmosphereRequest request = resource.getRequest(); + request.setAttribute(FrameworkConfig.WEBSOCKET_SUBPROTOCOL, FrameworkConfig.STREAMING_HTTP_OVER_WEBSOCKET); + List list = new ArrayList(); list.add(constructRequest(resource, request.getPathInfo(), request.getRequestURI(), methodType, contentType.equalsIgnoreCase(TEXT) ? null : contentType, destroyable).reader(r).build()); - return list; }