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 8da5d88ee6e..f3e75b5dec5 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 170250cfe37..f5c1ca4a0b5 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 4c7c6957b5a..31b471e9ea3 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 c2008e94f91..e27c9d781d4 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 0a53b815b9b..7e594399eef 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; }