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 either a single or a list of beans in the config
Date Fri, 03 Apr 2015 14:49:46 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 2e79c7e1f -> 840a021d2


[CXF-6329] allow either a single or a list of beans in the config


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

Branch: refs/heads/master
Commit: 840a021d2d24532eff0ab627ec621d415606768f
Parents: 2e79c7e
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Fri Apr 3 16:49:10 2015 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Apr 3 16:49:31 2015 +0200

----------------------------------------------------------------------
 .../websocket/atmosphere/AtmosphereUtils.java   | 17 ++++++++++-----
 ...AtmosphereWebSocketJettyDestinationTest.java | 23 ++++++++++++++++++++
 ...mosphereWebSocketServletDestinationTest.java | 23 ++++++++++++++++++++
 3 files changed, 57 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/840a021d/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 1f0c54e..1a4a9b5 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
@@ -22,6 +22,7 @@ package org.apache.cxf.transport.websocket.atmosphere;
 import java.util.List;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.CastUtils;
 import org.atmosphere.cpr.AtmosphereFramework;
 import org.atmosphere.cpr.AtmosphereInterceptor;
 
@@ -34,13 +35,17 @@ public final class AtmosphereUtils {
     }
 
     public static void addInterceptors(AtmosphereFramework framework, Bus bus) {
-        List<AtmosphereInterceptor> ais = (List<AtmosphereInterceptor>)bus.getProperty("atmosphere.interceptors");
-        if (ais == null) {
-            framework.interceptor(new DefaultProtocolInterceptor());
+        Object ais = bus.getProperty("atmosphere.interceptors");
+        if (ais == null || ais instanceof AtmosphereInterceptor) {
+            framework.interceptor(ais == null 
+                ? new DefaultProtocolInterceptor() : (AtmosphereInterceptor)ais);
             return;
-        } 
-        for (AtmosphereInterceptor i : ais) {
-            framework.interceptor(i);
+        }
+        if (ais instanceof List<?>) {
+            List<AtmosphereInterceptor> icps = CastUtils.cast((List<?>)ais);
+            for (AtmosphereInterceptor icp : icps) {
+                framework.interceptor(icp);
+            }
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/840a021d/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
index 3748357..abff9aa 100644
--- 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
@@ -64,6 +64,29 @@ public class AtmosphereWebSocketJettyDestinationTest extends Assert {
     }
 
     @Test
+    public void testUseCustomAtmoosphereInterceptor() throws Exception {
+        Bus bus = new ExtensionManagerBus();
+        bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
+        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();
+        int added = 0;
+        for (AtmosphereInterceptor a : ais) {
+            if (CustomInterceptor1.class.equals(a.getClass())) {
+                added++;
+                break;
+            } 
+        }
+        assertEquals(1, added);
+    }
+
+    @Test
     public void testUseCustomAtmoosphereInterceptors() throws Exception {
         Bus bus = new ExtensionManagerBus();
         bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(),
new CustomInterceptor2()));

http://git-wip-us.apache.org/repos/asf/cxf/blob/840a021d/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 5a3135d..4db4793 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
@@ -85,6 +85,29 @@ public class AtmosphereWebSocketServletDestinationTest extends Assert {
     }
 
     @Test
+    public void testUseCustomAtmoosphereInterceptor() throws Exception {
+        Bus bus = new ExtensionManagerBus();
+        bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
+        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();
+        int added = 0;
+        for (AtmosphereInterceptor a : ais) {
+            if (CustomInterceptor1.class.equals(a.getClass())) {
+                added++;
+                break;
+            } 
+        }
+        assertEquals(1, added);
+    }
+
+    @Test
     public void testUseCustomAtmoosphereInterceptors() throws Exception {
         Bus bus = new ExtensionManagerBus();
         bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(),
new CustomInterceptor2()));


Mime
View raw message