cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject git commit: enable the ivalid request test (status 400) for websocket
Date Thu, 13 Mar 2014 15:53:06 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 760e4bd32 -> d3da9ed54


enable the ivalid request test (status 400) for websocket


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

Branch: refs/heads/master
Commit: d3da9ed549ec3bfc48da8ea536624a5e57b29010
Parents: 760e4bd
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Thu Mar 13 16:52:08 2014 +0100
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Thu Mar 13 16:52:26 2014 +0100

----------------------------------------------------------------------
 .../atmosphere/AtmosphereWebSocketHandler.java  | 25 +++++++++++++++++---
 .../websocket/jetty/JettyWebSocket.java         |  3 ++-
 .../JAXRSClientServerWebSocketTest.java         |  1 -
 3 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d3da9ed5/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
index 95ef86e..2183e2b 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketHandler.java
@@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.transport.websocket.InvalidPathException;
 import org.apache.cxf.transport.websocket.WebSocketDestinationService;
 import org.apache.cxf.transport.websocket.WebSocketServletHolder;
 import org.apache.cxf.transport.websocket.WebSocketVirtualServletRequest;
@@ -80,22 +81,40 @@ public class AtmosphereWebSocketHandler implements WebSocketProtocol {
     @Override
     public List<AtmosphereRequest> onMessage(WebSocket webSocket, byte[] data, int
offset, int length) {
         LOG.info("onMessage(WebSocket, byte[], int, int)");
-        
+        HttpServletRequest request = null;
+        HttpServletResponse response = null;
         try {
             WebSocketServletHolder webSocketHolder = new AtmosphereWebSocketServletHolder(webSocket);
-            HttpServletRequest request = createServletRequest(webSocketHolder, data, offset,
length);
-            HttpServletResponse response = createServletResponse(webSocketHolder);
+            response = createServletResponse(webSocketHolder);
+            request = createServletRequest(webSocketHolder, data, offset, length);
             if (destination != null) {
                 ((WebSocketDestinationService)destination).invokeInternal(null, 
                     webSocket.resource().getRequest().getServletContext(),
                     request, response);
             }
+        } catch (InvalidPathException ex) { 
+            reportErrorStatus(response, 400);
         } catch (Exception e) {
             LOG.log(Level.WARNING, "Failed to invoke service", e);
+            reportErrorStatus(response, 500);
         }
         return null;
     }
 
+    // may want to move this error reporting code to WebSocketServletHolder
+    private void reportErrorStatus(HttpServletResponse response, int status) {
+        if (response != null) {
+            response.setStatus(status);
+            try {
+                response.getWriter().write("\r\n");
+                response.getWriter().close();
+                response.flushBuffer();
+            } catch (IOException ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+    }
+
     /** {@inheritDoc}*/
     @Override
     public void onOpen(WebSocket webSocket) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/d3da9ed5/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
index 2f1ceb3..a9ff973 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/JettyWebSocket.java
@@ -100,8 +100,8 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
         HttpServletRequest request = null;
         HttpServletResponse response = null;
         try {
-            request = createServletRequest(data, offset, length);
             response = createServletResponse();
+            request = createServletRequest(data, offset, length);
             if (manager != null) {
                 manager.service(request, response);
             }
@@ -113,6 +113,7 @@ class JettyWebSocket implements WebSocket.OnBinaryMessage, WebSocket.OnTextMessa
         }
     }
     
+    // may want to move this error reporting code to WebSocketServletHolder
     private void reportErrorStatus(HttpServletResponse response, int status) {
         if (response != null) {
             response.setStatus(status);

http://git-wip-us.apache.org/repos/asf/cxf/blob/d3da9ed5/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 0d1c404..b26e1f7 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
@@ -143,7 +143,6 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     }
     
     @Test
-    @Ignore
     public void testPathRestriction() throws Exception {
         String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
 


Mime
View raw message