camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1425653 - in /camel/trunk/components/camel-websocket/src: main/java/org/apache/camel/component/websocket/ test/java/org/apache/camel/component/websocket/
Date Mon, 24 Dec 2012 14:30:36 GMT
Author: ningjiang
Date: Mon Dec 24 14:30:36 2012
New Revision: 1425653

URL: http://svn.apache.org/viewvc?rev=1425653&view=rev
Log:
CAMEL-5908 fixed the NPE issue of starting the Websocket

Added:
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
Modified:
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java?rev=1425653&r1=1425652&r2=1425653&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
Mon Dec 24 14:30:36 2012
@@ -187,10 +187,6 @@ public class WebsocketComponent extends 
                 enableSessionSupport(connectorRef.server, connectorKey);
             }
 
-            if (prodcon instanceof WebsocketConsumer) {
-                // connect websocket consumer, to servlet
-                connectorRef.servlet.connect((WebsocketConsumer) prodcon);
-            }
         }
 
     }
@@ -426,6 +422,8 @@ public class WebsocketComponent extends 
             if (servlet.getConsumer() == null) {
                 servlet.setConsumer(consumer);
             }
+            // registry the consumer here
+            servlet.connect(consumer);
             return servlet;
         } else {
             throw new Exception("Jetty instance has not been retrieved for : " + key);

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java?rev=1425653&r1=1425652&r2=1425653&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
Mon Dec 24 14:30:36 2012
@@ -89,6 +89,7 @@ public class WebsocketEndpoint extends D
     public void connect(WebsocketConsumer consumer) throws Exception {
         component.connect(consumer);
         component.addServlet(sync, consumer, remaining);
+        
     }
 
     public void disconnect(WebsocketConsumer consumer) throws Exception {

Added: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java?rev=1425653&view=auto
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
(added)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerRouteTest.java
Mon Dec 24 14:30:36 2012
@@ -0,0 +1,88 @@
+/**
+ * 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.camel.component.websocket;
+
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.websocket.WebSocket;
+import com.ning.http.client.websocket.WebSocketTextListener;
+import com.ning.http.client.websocket.WebSocketUpgradeHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class WebsocketConsumerRouteTest extends CamelTestSupport {
+    
+    @Test
+    public void testWSHttpCall() throws Exception {
+        AsyncHttpClient c = new AsyncHttpClient();
+
+        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/echo").execute(
+            new WebSocketUpgradeHandler.Builder()
+                .addWebSocketListener(new WebSocketTextListener() {
+                    @Override
+                    public void onMessage(String message) {
+                        
+                    }
+
+                    @Override
+                    public void onFragment(String fragment, boolean last) {
+                    }
+
+                    @Override
+                    public void onOpen(WebSocket websocket) {
+                    }
+
+                    @Override
+                    public void onClose(WebSocket websocket) {
+                    }
+
+                    @Override
+                    public void onError(Throwable t) {
+                        t.printStackTrace();
+                    }
+                }).build()).get();
+        
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedBodiesReceived("Test");
+
+        websocket.sendTextMessage("Test");
+
+        result.assertIsSatisfied();
+        
+        websocket.close();
+        c.close();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("websocket://echo")
+                    .log(">>> Message received from WebSocket Client : ${body}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}



Mime
View raw message