cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject git commit: the subsequently pushed websocket data to carry the empty status (CXF-5339)
Date Wed, 05 Mar 2014 09:33:54 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 0d63e9579 -> b83e3fc79


the subsequently pushed websocket data to carry the empty status (CXF-5339)


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b83e3fc7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b83e3fc7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b83e3fc7

Branch: refs/heads/master
Commit: b83e3fc793f14e180eb4346ac6bf73b758476e11
Parents: 0d63e95
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Wed Mar 5 10:29:33 2014 +0100
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Wed Mar 5 10:32:24 2014 +0100

----------------------------------------------------------------------
 .../transport/http_jetty/JettyWebSocket.java    | 20 +++++++++++-----
 .../JAXRSClientServerWebSocketTest.java         | 24 ++++++++++++--------
 2 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b83e3fc7/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyWebSocket.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyWebSocket.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyWebSocket.java
index 30660aa99..247545d 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyWebSocket.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyWebSocket.java
@@ -186,6 +186,14 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
         }
         return longdata;
     }
+
+    private static byte[] buildResponse(byte[] data, int offset, int length) {
+        byte[] longdata = new byte[length + 2];
+        longdata[0] = 0x0d;
+        longdata[1] = 0x0a;
+        System.arraycopy(data, offset, longdata, 2, length);
+        return longdata;
+    }
     
     ServletOutputStream getServletOutputStream(final Map<String, String> headers) {
         LOG.log(Level.INFO, "getServletOutputStream()");
@@ -202,11 +210,11 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
             public void write(byte[] data, int offset, int length) throws IOException {
                 if (headers.get("$flushed") == null) {
                     data = buildResponse(headers, data, offset, length);
-                    offset = 0;
-                    length = data.length;
                     headers.put("$flushed", "true");
+                } else {
+                    data = buildResponse(data, offset, length);
                 }
-                webSocketConnection.sendMessage(data, offset, length);
+                webSocketConnection.sendMessage(data, 0, data.length);
             }
         };
     }
@@ -226,11 +234,11 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
             public void write(byte[] data, int offset, int length) throws IOException {
                 if (headers.get("$flushed") == null) {
                     data = buildResponse(headers, data, offset, length);
-                    offset = 0;
-                    length = data.length;
                     headers.put("$flushed", "true");
+                } else {
+                    data = buildResponse(data, offset, length);
                 }
-                webSocketConnection.sendMessage(data, offset, length);
+                webSocketConnection.sendMessage(data, 0, data.length);
             }
         };
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/b83e3fc7/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketTest.java
index 583f3a4..9688197 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketTest.java
@@ -94,8 +94,10 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             value = new String(resp.getEntity());
             assertTrue(value.startsWith("Today:"));
             for (int r = 2, i = 1; i < 6; r *= 2, i++) {
-                // subsequent data should not carry headers
-                assertEquals(r, Integer.parseInt(new String(received.get(i))));
+                // subsequent data should not carry the headers nor the status.
+                resp = new Response(received.get(i));
+                assertEquals(0, resp.getStatusCode());
+                assertEquals(r, Integer.parseInt(new String(resp.getEntity())));
             }
         } finally {
             wsclient.close();
@@ -172,14 +174,16 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
         public Response(byte[] data) {
             this.data = data;
             String line = readLine();
-            statusCode = Integer.parseInt(line);
-            while ((line = readLine()) != null) {
-                if (line.length() > 0) {
-                    int del = line.indexOf(':');
-                    String h = line.substring(0, del).trim();
-                    String v = line.substring(del + 1).trim();
-                    if ("Content-Type".equalsIgnoreCase(h)) {
-                        contentType = v;
+            if (line != null) {
+                statusCode = Integer.parseInt(line);
+                while ((line = readLine()) != null) {
+                    if (line.length() > 0) {
+                        int del = line.indexOf(':');
+                        String h = line.substring(0, del).trim();
+                        String v = line.substring(del + 1).trim();
+                        if ("Content-Type".equalsIgnoreCase(h)) {
+                            contentType = v;
+                        }
                     }
                 }
             }


Mime
View raw message