cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject cxf git commit: [CXF-6329] Allow multiple atmosphere interceptors to be configured for the websocket transport
Date Fri, 03 Apr 2015 11:17:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 318cfdaeb -> 102df12c6


[CXF-6329] Allow multiple atmosphere interceptors to be configured for the websocket transport


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

Branch: refs/heads/master
Commit: 102df12c6f78d852e63f301da9c35eac7811afa9
Parents: 318cfda
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Fri Apr 3 12:56:11 2015 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Apr 3 12:56:23 2015 +0200

----------------------------------------------------------------------
 .../websocket/atmosphere/AtmosphereUtils.java   | 17 ++--
 .../AtmosphereWebSocketJettyDestination.java    |  7 +-
 .../AtmosphereWebSocketServletDestination.java  |  7 +-
 ...AtmosphereWebSocketJettyDestinationTest.java | 82 ++++++++++++++++++++
 ...mosphereWebSocketServletDestinationTest.java | 42 ++++++++++
 5 files changed, 147 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/102df12c/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereUtils.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereUtils.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereUtils.java
index 5f35211..1f0c54e 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereUtils.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereUtils.java
@@ -19,7 +19,10 @@
 
 package org.apache.cxf.transport.websocket.atmosphere;
 
+import java.util.List;
+
 import org.apache.cxf.Bus;
+import org.atmosphere.cpr.AtmosphereFramework;
 import org.atmosphere.cpr.AtmosphereInterceptor;
 
 /**
@@ -30,12 +33,14 @@ public final class AtmosphereUtils {
     private AtmosphereUtils() {
     }
 
-    public static AtmosphereInterceptor getInterceptor(Bus bus) {
-        AtmosphereInterceptor ai = (AtmosphereInterceptor)bus.getProperty("atmosphere.interceptor");
-        if (ai == null) {
-            ai = new DefaultProtocolInterceptor(); 
+    public static void addInterceptors(AtmosphereFramework framework, Bus bus) {
+        List<AtmosphereInterceptor> ais = (List<AtmosphereInterceptor>)bus.getProperty("atmosphere.interceptors");
+        if (ais == null) {
+            framework.interceptor(new DefaultProtocolInterceptor());
+            return;
+        } 
+        for (AtmosphereInterceptor i : ais) {
+            framework.interceptor(i);
         }
-        return ai;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/102df12c/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestination.java
b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestination.java
index ebc33f6..ec873cc 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestination.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestination.java
@@ -69,7 +69,7 @@ public class AtmosphereWebSocketJettyDestination extends JettyHTTPDestination
im
         framework.addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
         framework.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
         framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
-        framework.interceptor(AtmosphereUtils.getInterceptor(bus));
+        AtmosphereUtils.addInterceptors(framework, bus);
         framework.addAtmosphereHandler("/", new DestinationHandler());
         framework.init();
 
@@ -170,4 +170,9 @@ public class AtmosphereWebSocketJettyDestination extends JettyHTTPDestination
im
             r.run();
         }
     }
+
+    // used for internal tests
+    AtmosphereFramework getAtmosphereFramework() {
+        return framework;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/102df12c/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 983ed96..657a183 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
@@ -64,7 +64,7 @@ public class AtmosphereWebSocketServletDestination extends ServletDestination
im
         framework.addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
         framework.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
         framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
-        framework.interceptor(AtmosphereUtils.getInterceptor(bus));
+        AtmosphereUtils.addInterceptors(framework, bus);
         framework.addAtmosphereHandler("/", new DestinationHandler());
         framework.init();
 
@@ -138,4 +138,9 @@ public class AtmosphereWebSocketServletDestination extends ServletDestination
im
             r.run();
         }
     }
+
+    // used for internal tests
+    AtmosphereFramework getAtmosphereFramework() {
+        return framework;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/102df12c/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestinationTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestinationTest.java
b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestinationTest.java
new file mode 100644
index 0000000..36e2aa2
--- /dev/null
+++ b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketJettyDestinationTest.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.transport.websocket.atmosphere;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.atmosphere.cpr.AtmosphereInterceptor;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class AtmosphereWebSocketJettyDestinationTest extends Assert {
+    private static final String ENDPOINT_ADDRESS = "ws://localhost:8080/websocket/nada";
+    private static final QName ENDPOINT_NAME = new QName("urn:websocket:probe", "nada");
+
+    @Test
+    public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
+        Bus bus = new ExtensionManagerBus();        
+        DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
+        EndpointInfo endpoint = new EndpointInfo();
+        endpoint.setAddress(ENDPOINT_ADDRESS);
+        endpoint.setName(ENDPOINT_NAME);
+
+        AtmosphereWebSocketServletDestination dest = 
+            new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
+
+        List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
+        assertEquals(1, ais.size());
+        assertEquals(DefaultProtocolInterceptor.class, ais.get(0).getClass());
+    }
+
+    @Test
+    public void testUseCustomAtmoosphereInterceptors() throws Exception {
+        Bus bus = new ExtensionManagerBus();
+        bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(),
new CustomInterceptor2()));
+        DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
+        EndpointInfo endpoint = new EndpointInfo();
+        endpoint.setAddress(ENDPOINT_ADDRESS);
+        endpoint.setName(ENDPOINT_NAME);
+
+        AtmosphereWebSocketServletDestination dest = 
+            new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
+
+        List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
+        assertEquals(2, ais.size());
+        assertEquals(CustomInterceptor1.class, ais.get(0).getClass());
+        assertEquals(CustomInterceptor2.class, ais.get(1).getClass());
+    }
+    
+    private static class CustomInterceptor1 extends DefaultProtocolInterceptor {
+    }
+    private static class CustomInterceptor2 extends DefaultProtocolInterceptor {
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/102df12c/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java
----------------------------------------------------------------------
diff --git a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java
b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java
index f56c51c..db269c6 100644
--- a/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java
+++ b/rt/transports/websocket/src/test/java/org/apache/cxf/transport/websocket/atmosphere/AtmosphereWebSocketServletDestinationTest.java
@@ -20,6 +20,8 @@
 package org.apache.cxf.transport.websocket.atmosphere;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
@@ -28,6 +30,7 @@ import org.apache.cxf.bus.extension.ExtensionManagerBus;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.atmosphere.cpr.AtmosphereInterceptor;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -59,6 +62,40 @@ public class AtmosphereWebSocketServletDestinationTest extends Assert {
         assertNull(registry.getDestinationForPath(ENDPOINT_ADDRESS));
     }
     
+    @Test
+    public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
+        Bus bus = new ExtensionManagerBus();        
+        DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
+        EndpointInfo endpoint = new EndpointInfo();
+        endpoint.setAddress(ENDPOINT_ADDRESS);
+        endpoint.setName(ENDPOINT_NAME);
+
+        AtmosphereWebSocketServletDestination dest = 
+            new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
+
+        List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
+        assertEquals(1, ais.size());
+        assertEquals(DefaultProtocolInterceptor.class, ais.get(0).getClass());
+    }
+
+    @Test
+    public void testUseCustomAtmoosphereInterceptors() throws Exception {
+        Bus bus = new ExtensionManagerBus();
+        bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(),
new CustomInterceptor2()));
+        DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
+        EndpointInfo endpoint = new EndpointInfo();
+        endpoint.setAddress(ENDPOINT_ADDRESS);
+        endpoint.setName(ENDPOINT_NAME);
+
+        AtmosphereWebSocketServletDestination dest = 
+            new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
+
+        List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
+        assertEquals(2, ais.size());
+        assertEquals(CustomInterceptor1.class, ais.get(0).getClass());
+        assertEquals(CustomInterceptor2.class, ais.get(1).getClass());
+    }
+    
     private static class TestAtmosphereWebSocketServletDestination extends AtmosphereWebSocketServletDestination
{
 
 
@@ -77,4 +114,9 @@ public class AtmosphereWebSocketServletDestinationTest extends Assert {
             super.deactivate();
         }
     }
+    
+    private static class CustomInterceptor1 extends DefaultProtocolInterceptor {
+    }
+    private static class CustomInterceptor2 extends DefaultProtocolInterceptor {
+    }
 }


Mime
View raw message