You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/07/18 17:49:36 UTC

git commit: [CXF-5889] Using a custom servlet wrapper to preserve the attribute

Repository: cxf
Updated Branches:
  refs/heads/master 7df90539a -> 53836207b


[CXF-5889] Using a custom servlet wrapper to preserve the attribute


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

Branch: refs/heads/master
Commit: 53836207b431ea6cb480373d2643cd119bf01e08
Parents: 7df9053
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Fri Jul 18 16:49:15 2014 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Fri Jul 18 16:49:15 2014 +0100

----------------------------------------------------------------------
 parent/pom.xml                                  |  2 +-
 .../AtmosphereWebSocketServletDestination.java  | 20 ++++++-
 ...RSClientServerWebSocketSpringWebAppTest.java |  8 ++-
 .../JAXRSClientServerWebSocketTest.java         | 57 +++++++++++---------
 4 files changed, 57 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/53836207/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 50ab6a5..9dc65d2 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -75,7 +75,7 @@
         <cxf.abdera.version>1.1.3</cxf.abdera.version>
         <cxf.activemq.version>5.9.1</cxf.activemq.version>
         <cxf.ahc.version>1.8.5</cxf.ahc.version>
-        <cxf.atmosphere.version>2.1.3</cxf.atmosphere.version>
+        <cxf.atmosphere.version>2.1.7</cxf.atmosphere.version>
         <cxf.axiom.version>1.2.14</cxf.axiom.version>
         <cxf.bcprov.version>1.50</cxf.bcprov.version>
         <cxf.cglib.bundle.version>2.2_2</cxf.cglib.bundle.version>

http://git-wip-us.apache.org/repos/asf/cxf/blob/53836207/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java
index 508bf2d..1885924 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestination.java
@@ -26,6 +26,7 @@ import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cxf.Bus;
@@ -76,7 +77,8 @@ public class AtmosphereWebSocketServletDestination extends ServletDestination im
                        HttpServletResponse resp) throws IOException {
         if (Utils.webSocketEnabled(req)) {
             try {
-                framework.doCometSupport(AtmosphereRequest.wrap(req), AtmosphereResponse.wrap(resp));
+                framework.doCometSupport(AtmosphereRequest.wrap(new HttpServletRequestFilter(req)), 
+                                         AtmosphereResponse.wrap(resp));
             } catch (ServletException e) {
                 throw new IOException(e);
             }
@@ -94,4 +96,20 @@ public class AtmosphereWebSocketServletDestination extends ServletDestination im
     Executor getExecutor() {
         return executor;
     }
+    
+    private static class HttpServletRequestFilter extends HttpServletRequestWrapper {
+        private static final String TRANSPORT_ADDRESS 
+            = "org.apache.cxf.transport.endpoint.address";
+        private String transportAddress; 
+        public HttpServletRequestFilter(HttpServletRequest request) {
+            super(request);
+            transportAddress = (String)request.getAttribute(TRANSPORT_ADDRESS);
+        }
+        
+        @Override
+        public Object getAttribute(String name) {
+            return TRANSPORT_ADDRESS.equals(name) ? transportAddress : super.getAttribute(name);
+        }
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/53836207/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java
index 068e532..cf0bbab 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/JAXRSClientServerWebSocketSpringWebAppTest.java
@@ -54,7 +54,7 @@ public class JAXRSClientServerWebSocketSpringWebAppTest extends JAXRSClientServe
         } catch (URISyntaxException e1) {
             e1.printStackTrace();
         }
-        webappcontext.setContextPath("/");
+        webappcontext.setContextPath("/webapp");
 
         webappcontext.setWar(contextPath);
         HandlerCollection handlers = new HandlerCollection();
@@ -66,7 +66,7 @@ public class JAXRSClientServerWebSocketSpringWebAppTest extends JAXRSClientServe
     
     @Test
     public void testGetBookHTTP() throws Exception {
-        String address = "http://localhost:" + getPort() + "/http/web/bookstore/books/1";
+        String address = "http://localhost:" + getPort() + getContext() + "/http/web/bookstore/books/1";
         WebClient wc = WebClient.create(address);
         wc.accept("application/xml");
         Book book = wc.get(Book.class);
@@ -76,4 +76,8 @@ public class JAXRSClientServerWebSocketSpringWebAppTest extends JAXRSClientServe
     protected String getPort() {
         return PORT;
     }
+    @Override
+    protected String getContext() {
+        return "/webapp";
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/53836207/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 b30984f..01e4ccb 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
@@ -43,14 +43,14 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testBookWithWebSocket() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             // call the GET service
-            wsclient.sendMessage("GET /websocket/web/bookstore/booknames".getBytes());
-            assertTrue("one book must be returned", wsclient.await(3));
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/web/bookstore/booknames").getBytes());
+            assertTrue("one book must be returned", wsclient.await(30000));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             assertEquals(1, received.size());
             WebSocketTestClient.Response resp = received.get(0);
@@ -61,7 +61,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             
             // call the same GET service in the text mode
             wsclient.reset(1);
-            wsclient.sendTextMessage("GET /websocket/web/bookstore/booknames");
+            wsclient.sendTextMessage("GET " +  getContext() + "/websocket/web/bookstore/booknames");
             assertTrue("one book must be returned", wsclient.await(3));
             received = wsclient.getReceivedResponses();
             assertEquals(1, received.size());
@@ -73,7 +73,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
 
             // call another GET service
             wsclient.reset(1);
-            wsclient.sendMessage("GET /websocket/web/bookstore/books/123".getBytes());
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/web/bookstore/books/123").getBytes());
             assertTrue("response expected", wsclient.await(3));
             received = wsclient.getReceivedResponses();
             resp = received.get(0);
@@ -85,7 +85,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             // call the POST service
             wsclient.reset(1);
             wsclient.sendMessage(
-                "POST /websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n123"
+                ("POST " +  getContext() + "/websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n123")
                     .getBytes());
             assertTrue("response expected", wsclient.await(3));
             received = wsclient.getReceivedResponses();
@@ -98,7 +98,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             // call the same POST service in the text mode 
             wsclient.reset(1);
             wsclient.sendTextMessage(
-                "POST /websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n123");
+                "POST " +  getContext() + "/websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n123");
             assertTrue("response expected", wsclient.await(3));
             received = wsclient.getReceivedResponses();
             resp = received.get(0);
@@ -109,7 +109,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
 
             // call the GET service returning a continous stream output
             wsclient.reset(6);
-            wsclient.sendMessage("GET /websocket/web/bookstore/bookbought".getBytes());
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/web/bookstore/bookbought").getBytes());
             assertTrue("response expected", wsclient.await(5));
             received = wsclient.getReceivedResponses();
             assertEquals(6, received.size());
@@ -131,14 +131,15 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testGetBookStream() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             wsclient.reset(5);
             wsclient.sendMessage(
-                "GET /websocket/web/bookstore/bookstream\r\nAccept: application/json\r\n\r\n".getBytes());
+                ("GET " +  getContext() + "/websocket/web/bookstore/bookstream\r\nAccept: application/json\r\n\r\n")
+                .getBytes());
             assertTrue("response expected", wsclient.await(5));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             assertEquals(5, received.size());
@@ -164,13 +165,13 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testBookWithWebSocketAndHTTP() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             // call the GET service
-            wsclient.sendMessage("GET /websocket/web/bookstore/booknames".getBytes());
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/web/bookstore/booknames").getBytes());
             assertTrue("one book must be returned", wsclient.await(3));
             List<Object> received = wsclient.getReceived();
             assertEquals(1, received.size());
@@ -189,7 +190,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testGetBookHTTPFromWebSocketEndpoint() throws Exception {
-        String address = "http://localhost:" + getPort() + "/websocket/web/bookstore/books/1";
+        String address = "http://localhost:" + getPort() + getContext() + "/websocket/web/bookstore/books/1";
         WebClient wc = WebClient.create(address);
         wc.accept("application/xml");
         Book book = wc.get(Book.class);
@@ -198,12 +199,13 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testBookWithWebSocketServletStream() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
-            wsclient.sendMessage("GET /websocket/web/bookstore/booknames/servletstream".getBytes());
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/web/bookstore/booknames/servletstream")
+                                 .getBytes());
             assertTrue("one book must be returned", wsclient.await(3));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             assertEquals(1, received.size());
@@ -219,14 +221,14 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testWrongMethod() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             // call the GET service using POST
             wsclient.reset(1);
-            wsclient.sendMessage("POST /websocket/web/bookstore/booknames".getBytes());
+            wsclient.sendMessage(("POST " +  getContext() + "/websocket/web/bookstore/booknames").getBytes());
             assertTrue("error response expected", wsclient.await(3));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             assertEquals(1, received.size());
@@ -239,13 +241,13 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testPathRestriction() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             // call the GET service over the different path
-            wsclient.sendMessage("GET /websocket/bookstore2".getBytes());
+            wsclient.sendMessage(("GET " +  getContext() + "/websocket/bookstore2").getBytes());
             assertTrue("error response expected", wsclient.await(3));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             assertEquals(1, received.size());
@@ -258,14 +260,14 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testCallsWithIDReferences() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
         try {
             // call the POST service without requestId
             wsclient.sendTextMessage(
-                "POST /websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n459");
+                "POST " +  getContext() + "/websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n\r\n459");
             assertTrue("response expected", wsclient.await(3));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
             WebSocketTestClient.Response resp = received.get(0);
@@ -281,10 +283,10 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             String reqid1 = UUID.randomUUID().toString();
             String reqid2 = UUID.randomUUID().toString();
             wsclient.sendTextMessage(
-                "POST /websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n" 
+                "POST " +  getContext() + "/websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n" 
                 + WebSocketConstants.DEFAULT_REQUEST_ID_KEY + ": " + reqid1 + "\r\n\r\n549");
             wsclient.sendTextMessage(
-                "POST /websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n" 
+                "POST " +  getContext() + "/websocket/web/bookstore/booksplain\r\nContent-Type: text/plain\r\n" 
                 + WebSocketConstants.DEFAULT_REQUEST_ID_KEY + ": " + reqid2 + "\r\n\r\n495");
             assertTrue("response expected", wsclient.await(3));
             received = wsclient.getReceivedResponses();
@@ -308,7 +310,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     
     @Test
     public void testCallsInParallel() throws Exception {
-        String address = "ws://localhost:" + getPort() + "/websocket/web/bookstore";
+        String address = "ws://localhost:" + getPort() + getContext() + "/websocket/web/bookstore";
 
         WebSocketTestClient wsclient = new WebSocketTestClient(address);
         wsclient.connect();
@@ -316,9 +318,9 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
             // call the GET service that takes a long time to response
             wsclient.reset(2);
             wsclient.sendTextMessage(
-                "GET /websocket/web/bookstore/hold/3000");
+                "GET " +  getContext() + "/websocket/web/bookstore/hold/3000");
             wsclient.sendTextMessage(
-                "GET /websocket/web/bookstore/hold/3000");
+                "GET " +  getContext() + "/websocket/web/bookstore/hold/3000");
             // each call takes 3 seconds but executed in parallel, so waiting 4 secs is sufficient
             assertTrue("response expected", wsclient.await(4));
             List<WebSocketTestClient.Response> received = wsclient.getReceivedResponses();
@@ -331,4 +333,7 @@ public class JAXRSClientServerWebSocketTest extends AbstractBusClientServerTestB
     protected String getPort() {
         return PORT;
     }
+    protected String getContext() {
+        return "";
+    }
 }