camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: [CAMEL-9391] Set parameter enableEventsResending should be before Atmosphere wrap request
Date Sat, 05 Dec 2015 13:33:43 GMT
Repository: camel
Updated Branches:
  refs/heads/master d04c83c86 -> 28831913f


[CAMEL-9391] Set parameter enableEventsResending should be before Atmosphere wrap request


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

Branch: refs/heads/master
Commit: 2d77c3a338183492557effde353bb5d90015c42c
Parents: d04c83c
Author: Pavlo Kletsko <pkletsko@gmail.com>
Authored: Sat Dec 5 12:57:37 2015 +0100
Committer: Pavlo Kletsko <pkletsko@gmail.com>
Committed: Sat Dec 5 12:57:37 2015 +0100

----------------------------------------------------------------------
 .../atmosphere/websocket/WebsocketConsumer.java |  2 +-
 ...cketCamelRouterWithInitParamTestSupport.java | 74 ++++++++++++++++++++
 .../websocket/WebsocketRouteTest.java           | 37 ++--------
 .../WebsocketRouteWithInitParamTest.java        | 60 ++++++++++++++++
 4 files changed, 139 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2d77c3a3/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketConsumer.java
b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketConsumer.java
index 934fa5f..b8267ac 100644
--- a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketConsumer.java
+++ b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/WebsocketConsumer.java
@@ -62,8 +62,8 @@ public class WebsocketConsumer extends ServletConsumer {
     }
     
     void service(HttpServletRequest request, HttpServletResponse response, boolean enableEventsResending)
throws IOException, ServletException {
-        framework.doCometSupport(AtmosphereRequestImpl.wrap(request), AtmosphereResponseImpl.wrap(response));
         this.enableEventsResending = enableEventsResending;
+        framework.doCometSupport(AtmosphereRequestImpl.wrap(request), AtmosphereResponseImpl.wrap(response));
     }
 
     public void sendMessage(final String connectionKey, Object message) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2d77c3a3/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketCamelRouterWithInitParamTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketCamelRouterWithInitParamTestSupport.java
b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketCamelRouterWithInitParamTestSupport.java
new file mode 100644
index 0000000..8acf18c
--- /dev/null
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketCamelRouterWithInitParamTestSupport.java
@@ -0,0 +1,74 @@
+/**
+ * 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.atmosphere.websocket;
+
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.After;
+import org.junit.Before;
+
+public class WebsocketCamelRouterWithInitParamTestSupport extends CamelTestSupport {
+    public static final String CONTEXT = "/mycontext";
+    public static final String CONTEXT_URL = "http://localhost/mycontext";
+    protected static final int PORT = AvailablePortFinder.getNextAvailable();
+    protected boolean startCamelContext = true;
+    
+    protected Server server;
+
+    protected ServletHolder servletHolder;
+
+    @Before
+    public void setUp() throws Exception {
+        server = new Server();
+        Connector connector = new SelectChannelConnector();
+        connector.setHost("localhost");
+        connector.setPort(PORT);
+        server.addConnector(connector);
+        
+        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+        context.setContextPath("/");
+        server.setHandler(context);
+
+        servletHolder = new ServletHolder(new CamelWebSocketServlet());
+        servletHolder.setName("CamelWsServlet");
+        servletHolder.setInitParameter("events", "true");
+        context.addServlet(servletHolder, "/*");
+        
+        server.start();
+        
+        if (startCamelContext) {        
+            super.setUp();
+        }
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if (startCamelContext) {
+            super.tearDown();
+        }
+        
+        server.stop();
+        server.destroy();
+    }
+    
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/2d77c3a3/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
index dd4063b..fa05da5 100644
--- a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteTest.java
@@ -117,17 +117,8 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport
{
     }
 
     @Test
-    public void testWebsocketEventsResendingEnabled() throws Exception {
-        servletHolder.setInitParameter("events", "true");
-
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola4");
-        wsclient.connect();
-        wsclient.close();
-    }
-
-    @Test
     public void testWebsocketEventsResendingDisabled() throws Exception {
-        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola5");
+        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola4");
         wsclient.connect();
         assertFalse(wsclient.await(10));
         wsclient.close();
@@ -158,19 +149,12 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport
{
                     }
                 }).to("atmosphere-websocket:///hola3");
 
-                // route for events resending enabled
-                from("atmosphere-websocket:///hola4").to("log:info").process(new Processor()
{
-                    public void process(final Exchange exchange) throws Exception {
-                        checkEventsResendingEnabled(exchange);
-                    }
-                });
-
                 // route for events resending disabled
-                from("atmosphere-websocket:///hola5").to("log:info").process(new Processor()
{
+                from("atmosphere-websocket:///hola4").to("log:info").process(new Processor()
{
                     public void process(final Exchange exchange) throws Exception {
                         checkEventsResendingDisabled(exchange);
                     }
-                }).to("atmosphere-websocket:///hola5");
+                }).to("atmosphere-websocket:///hola4");
             }
         };
     }
@@ -194,24 +178,11 @@ public class WebsocketRouteTest extends WebsocketCamelRouterTestSupport
{
         }
     }
 
-    private static void checkEventsResendingEnabled(Exchange exchange) {
-        Object connectionKey = exchange.getIn().getHeader(WebsocketConstants.CONNECTION_KEY);
-        Object eventType = exchange.getIn().getHeader(WebsocketConstants.EVENT_TYPE);
-        Object msg = exchange.getIn().getBody();
-
-        assertEquals(null, msg);
-        assertTrue(connectionKey != null);
-
-        if (eventType instanceof Integer) {
-            assertTrue(eventType.equals(1) || eventType.equals(0) || eventType.equals(-1));
-        }
-    }
-
     private static void checkEventsResendingDisabled(Exchange exchange) {
         Object eventType = exchange.getIn().getHeader(WebsocketConstants.EVENT_TYPE);
 
         if (eventType instanceof Integer) {
-            if (eventType.equals(1) || eventType.equals(0) || eventType.equals(-1)) {
+            if (eventType.equals(WebsocketConstants.ONOPEN_EVENT_TYPE) || eventType.equals(WebsocketConstants.ONCLOSE_EVENT_TYPE)
|| eventType.equals(WebsocketConstants.ONERROR_EVENT_TYPE)) {
                 exchange.getIn().setBody("Error. This place should never be reached.");
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/2d77c3a3/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
new file mode 100644
index 0000000..13e3e77
--- /dev/null
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/WebsocketRouteWithInitParamTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.atmosphere.websocket;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class WebsocketRouteWithInitParamTest extends WebsocketCamelRouterWithInitParamTestSupport
{
+
+    @Test
+    public void testWebsocketEventsResendingEnabled() throws Exception {
+        TestClient wsclient = new TestClient("ws://localhost:" + PORT + "/hola");
+        wsclient.connect();
+        wsclient.close();
+    }
+
+    // START SNIPPET: payload
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // route for events resending enabled
+                from("atmosphere-websocket:///hola").to("log:info").process(new Processor()
{
+                    public void process(final Exchange exchange) throws Exception {
+                        checkEventsResendingEnabled(exchange);
+                    }
+                });
+            }
+        };
+    }
+
+    private static void checkEventsResendingEnabled(Exchange exchange) {
+        Object connectionKey = exchange.getIn().getHeader(WebsocketConstants.CONNECTION_KEY);
+        Object eventType = exchange.getIn().getHeader(WebsocketConstants.EVENT_TYPE);
+        Object msg = exchange.getIn().getBody();
+
+        assertEquals(null, msg);
+        assertTrue(connectionKey != null);
+
+        if (eventType instanceof Integer) {
+            assertTrue(eventType.equals(WebsocketConstants.ONOPEN_EVENT_TYPE) || eventType.equals(WebsocketConstants.ONCLOSE_EVENT_TYPE)
|| eventType.equals(WebsocketConstants.ONERROR_EVENT_TYPE));
+        }
+    }
+    // END SNIPPET: payload
+}


Mime
View raw message