You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/04/12 19:56:26 UTC

[07/11] camel git commit: refactor component and upgrade PubNub library

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubOperationsExample.java
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubOperationsExample.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubOperationsExample.java
deleted file mode 100644
index 10db410..0000000
--- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubOperationsExample.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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.pubnub.example;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.main.Main;
-import org.json.JSONObject;
-
-//@formatter:off
-/**
- * Just a small http server hack to try out pubnub method calls. 
- * HERE_NOW, WHERE_NOW, GET_STATE, SET_STATE, GET_HISTORY, PUBLISH; 
- * usage : 
- * do a GET with http param CamelPubNubOperation=METHOD_TO_ACTIVATE eg. HERE_NOW 
- * 
- * SET_STATE requires a http param 'body' with some json that is used as pubnub state object. 
- * Can be any valid json string.
- *
- */
-//@formatter:on
-public final class PubNubOperationsExample {
-
-    private PubNubOperationsExample() {
-    }
-
-    public static void main(String[] args) throws Exception {
-        Main main = new Main();
-        main.addRouteBuilder(new RestRoute());
-        main.run();
-    }
-
-    static class RestRoute extends RouteBuilder {
-        private String pubnub = "pubnub://pubsub:iot?publisherKey=" + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY + "&subscriberKey="
-                                + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY;
-
-        @Override
-        public void configure() throws Exception {
-            //@formatter:off
-            from("netty-http:http://0.0.0.0:8080?urlDecodeHeaders=true")
-                .setBody(simple("${header.body}"))
-                .convertBodyTo(JSONObject.class)
-                .to(pubnub);
-            //@formatter:on
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
index 2122bf0..faac12c 100644
--- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
+++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubPresenseExample.java
@@ -19,6 +19,8 @@ package org.apache.camel.component.pubnub.example;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.main.Main;
 
+import static org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY;
+
 public final class PubNubPresenseExample {
 
     private PubNubPresenseExample() {
@@ -33,11 +35,9 @@ public final class PubNubPresenseExample {
     static class PresensRoute extends RouteBuilder {
         @Override
         public void configure() throws Exception {
-            //@formatter:off
-            from("pubnub://presence:iot?subscriberKey=" + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY)
+            from("pubnub:iot?withPresence=true&subscriberKey=" + PUBNUB_SUBSCRIBER_KEY)
                 .log("${body}")
                 .to("mock:result");
-            //@formatter:on
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
index 9794b0b..e962a4a 100644
--- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
+++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.html
@@ -15,73 +15,92 @@
  * limitations under the License.
 -->
 <html>
-  <head>
+<head>
 
-    <link rel="stylesheet" type="text/css" href="http://pubnub.github.io/eon/lib/eon.css">
-    <script src="http://cdn.pubnub.com/pubnub-3.7.1.min.js"></script>
-    <script src="http://pubnub.github.io/eon/lib/eon-chart.js"></script>
+<link rel="stylesheet" type="text/css" href="https://pubnub.github.io/eon/v/eon/1.0.0/eon.css">
+<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.6.0.min.js"></script>
+<script src="https://pubnub.github.io/eon/v/eon/1.0.0/eon.js"></script>
 
 
-    <style>
-      .c3-region-1 {
-        fill: #dd3333;
-        fill-opacity: 0.8
-      }
-    </style>
+<style>
+.c3-region-1 {
+    fill: #dd3333;
+    fill-opacity: 0.8
+}
+</style>
 
-  </head>
-  <body>
-  	<div>
-  		<div align="center">
-  		<h1>Description</h1>
-  		</div>
-  		<br/>
-  		This is a example of PubNub EON charts displaying stream data using the camel-pubnub component.
-  		<br/>
-  		To see live data you have to:
-  		<ul>
-  			<li>Sign up for a PubNub acount</li>
-  			<li>Replace the 'subscribe_key' in this html.</li>
-  			<li>Update the constants PUBNUB_SUBSCRIBER_KEY and PUBNUB_PUBLISHER_KEY in the class PubNubExampleConstants</li>
-  			<li>Run the class PubNubSensor2Example</li>
-  			
-  		</ul>
-  	</div>
+</head>
+<body>
+    <div>
+        <div align="center">
+            <h1>Description</h1>
+        </div>
+        <br /> This is a example of PubNub EON charts displaying stream data
+        using the camel-pubnub component. <br /> To see live data you have
+        to:
+        <ul>
+            <li>Sign up for a PubNub acount</li>
+            <li>Replace 'mySubscriberKey' in this html with a subscriberkey obtained from PubNub.</li>
+            <li>Update the constants PUBNUB_SUBSCRIBER_KEY and PUBNUB_PUBLISHER_KEY in the class PubNubExampleConstants</li>
+            <li>Run the class PubNubSensor2Example</li>
+            <li>Open this html page in your web browser</li>
+        </ul>
+    </div>
     <div id="chart"></div>
-    <script>
+<script>
 
-    var pubnub = PUBNUB.init({
-		subscribe_key: 'mysubscriberkey'
-	});
-    eon.chart({
-    	pubnub: pubnub,
-    	history: false,
-	    channel: 'iot',
-    	flow: true,
-    	generate: {
-    	    bindto: '#chart',
-    	    data: {
-				x: 'x',
-				labels: true
-    	    },
-    	    axis: {
-    	      	x: {
-	    	        type: 'timeseries',
-	    	        tick: {
-	    	            format: '%Y-%m-%d'
-	    	        }
-    	      	}
-    	    }
-    	},
-	    transform: function(m) {
-	    	var response = {columns: [
-	    		['x', new Date().getTime()],
-	    		['Humidity', m.humidity],
-	    		['Temperature', m.temperature]
-	    	]};
-	    	return response;
-	    }
-	});
+    var pubnub = new PubNub({
+        subscribeKey: 'mySubscriberKey'
+    });
+
+eon.chart({
+    channels: ["iot"],
+    generate: {
+        bindto: '#chart',
+        data: {
+            type:'spline',
+            colors: {
+                value0:'#ffaaaa',
+                value1:'#cc8888',
+            },
+            names: {
+                value0: "Temperature",
+                value1: "Humidity",
+            }
+        },
+        point: {
+            show: false
+        },
+        axis: {
+            x: {
+                type: 'timeseries',
+                tick: {
+                    format: '%H:%m:%S'
+                }
+            },
+            y: {
+                label: {
+                    text: 'Values',
+                    position: 'outer-middle'
+                }
+            }
+        },
+        tooltip: {
+            show: false
+        }
+    },
+    history:false,
+    pubnub: pubnub,
+    limit: 100,
+    transform: function(m) {
+      return { eon: {
+        temperature: m.temperature,
+        humidity: m.humidity
+      }}
+    }
+    
+});
+	
     </script>
-  </body>
+</body>
 </html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
index 01d51fa..7389193 100644
--- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
+++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java
@@ -21,14 +21,18 @@ import java.util.Map;
 import java.util.Random;
 import java.util.concurrent.ConcurrentHashMap;
 
+import com.pubnub.api.models.consumer.pubsub.PNMessageResult;
+
 import org.apache.camel.EndpointInject;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.pubnub.PubNubConstants;
 import org.apache.camel.main.Main;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+
+import static org.apache.camel.component.pubnub.PubNubConstants.OPERATION;
+import static org.apache.camel.component.pubnub.PubNubConstants.UUID;
+import static org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_PUBLISHER_KEY;
+import static org.apache.camel.component.pubnub.example.PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY;
 
 public final class PubNubSensor2Example {
 
@@ -43,37 +47,29 @@ public final class PubNubSensor2Example {
     }
 
     static class SimulatedDeviceEventGeneratorRoute extends RouteBuilder {
-        private final String deviceEP = "pubnub://pubsub:iot?uuid=device2&publisherKey=" + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY + "&subscriberKey="
-                                        + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY;
-        private final String devicePrivateEP = "pubnub://pubsub:device2private?uuid=device2&publisherKey=" + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY + "&subscriberKey="
-                                               + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY;
+        private final String deviceEP = "pubnub:iot?uuid=device2&publisherKey=" + PUBNUB_PUBLISHER_KEY + "&subscriberKey=" + PUBNUB_SUBSCRIBER_KEY;
+        private final String devicePrivateEP = "pubnub:device2private?uuid=device2&publisherKey=" + PUBNUB_PUBLISHER_KEY + "&subscriberKey=" + PUBNUB_SUBSCRIBER_KEY;
 
         @Override
         public void configure() throws Exception {
-            //@formatter:off
             from("timer:device2").routeId("device-event-route")
                 .bean(PubNubSensor2Example.EventGeneratorBean.class, "getRandomEvent('device2')")
-                .convertBodyTo(JSONObject.class)
                 .to(deviceEP);
             
             from(devicePrivateEP)
                 .routeId("device-unicast-route")
                 .log("Message from master to device2 : ${body}");
-            //@formatter:on
         }
     }
 
     static class PubsubRoute extends RouteBuilder {
-        private static String masterEP = "pubnub://pubsub:iot?uuid=master&subscriberKey=" + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY + "&publisherKey="
-                                         + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY;
+        private static String masterEP = "pubnub:iot?uuid=master&subscriberKey=" + PUBNUB_SUBSCRIBER_KEY + "&publisherKey=" + PUBNUB_PUBLISHER_KEY;
         private static Map<String, String> devices = new ConcurrentHashMap<String, String>();
 
         @Override
         public void configure() throws Exception {
-            //@formatter:off
             from(masterEP)
                 .routeId("master-route")
-                .convertBodyTo(JSONObject.class)
                 .bean(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class, "doSomethingInteresting(${body})")
                 .log("${body} headers : ${headers}").to("mock:result");
             
@@ -82,11 +78,10 @@ public final class PubNubSensor2Example {
                 .setHeader(PubNubConstants.CHANNEL, method(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class, "getUnicastChannelOfDevice()"))
                 .setBody(constant("Hello device"))
                 .to(masterEP);
-            //@formatter:on
         }
 
-        static class DataProcessorBean {
-            @EndpointInject(uri = "pubnub://pubsub:iot?uuid=master&subscriberKey=" + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY)
+        public static class DataProcessorBean {
+            @EndpointInject(uri = "pubnub:iot?uuid=master&subscriberKey=" + PUBNUB_SUBSCRIBER_KEY)
             private static ProducerTemplate template;
 
             public static String getUnicastChannelOfDevice() {
@@ -94,29 +89,50 @@ public final class PubNubSensor2Example {
                 return devices.values().iterator().next();
             }
 
-            public static void doSomethingInteresting(JSONObject message) {
+            public static void doSomethingInteresting(PNMessageResult message) {
                 String deviceUUID;
-                try {
-                    deviceUUID = message.getString("uuid");
-                    if (devices.get(deviceUUID) == null) {
-                        Map<String, Object> headers = new HashMap<String, Object>();
-                        headers.put(PubNubConstants.OPERATION, "WHERE_NOW");
-                        headers.put(PubNubConstants.UUID, deviceUUID);
-                        JSONObject response = (JSONObject)template.requestBodyAndHeaders(null, headers);
-                        JSONArray listofDeviceChannels = response.getJSONArray("channels");
-                        devices.put(deviceUUID, listofDeviceChannels.getString(0));
-                    }
-                } catch (JSONException e) {
+                deviceUUID = message.getPublisher();
+                if (devices.get(deviceUUID) == null) {
+                    Map<String, Object> headers = new HashMap<String, Object>();
+                    headers.put(OPERATION, "WHERE_NOW");
+                    headers.put(UUID, deviceUUID);
+                    @SuppressWarnings("unchecked")
+                    java.util.List<String> channels = (java.util.List<String>) template.requestBodyAndHeaders(null, headers);
+                    devices.put(deviceUUID, channels.get(0));
                 }
             }
         }
     }
 
-    public static class EventGeneratorBean {
-        public static String getRandomEvent(String device) throws JSONException {
+    static class DeviceWeatherInfo {
+        private String device;
+        private int humidity;
+        private int temperature;
+
+        DeviceWeatherInfo(String device) {
             Random rand = new Random();
-            String s = "{uuid:" + device + ", humidity:" + rand.nextInt(100) + ", temperature:" + rand.nextInt(40) + "}";
-            return s;
+            this.device = device;
+            this.humidity = rand.nextInt(100);
+            this.temperature = rand.nextInt(40);
+        }
+
+        public String getDevice() {
+            return device;
+        }
+
+        public int getHumidity() {
+            return humidity;
+        }
+
+        public int getTemperature() {
+            return temperature;
+        }
+
+    }
+
+    public static class EventGeneratorBean {
+        public static DeviceWeatherInfo getRandomEvent(String device) {
+            return new DeviceWeatherInfo(device);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
index 0625453..f5cff83 100644
--- a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
+++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java
@@ -33,7 +33,7 @@ public final class PubNubSensorExample {
     static class SensorRoute extends RouteBuilder {
         @Override
         public void configure() throws Exception {
-            from("pubnub://pubsub:pubnub-sensor-network?subscriberKey=sub-c-5f1b7c8e-fbee-11e3-aa40-02ee2ddab7fe").log("${body}").to("mock:result");
+            from("pubnub:pubnub-sensor-network?subscriberKey=sub-c-5f1b7c8e-fbee-11e3-aa40-02ee2ddab7fe").log("${body}").to("mock:result");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/components/camel-pubnub/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-pubnub/src/test/resources/log4j2.properties b/components/camel-pubnub/src/test/resources/log4j2.properties
index 25b59c8..fbb9b06 100644
--- a/components/camel-pubnub/src/test/resources/log4j2.properties
+++ b/components/camel-pubnub/src/test/resources/log4j2.properties
@@ -25,4 +25,4 @@ appender.out.name = out
 appender.out.layout.type = PatternLayout
 appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
 rootLogger.level = INFO
-rootLogger.appenderRef.file.ref = file
+rootLogger.appenderRef.file.ref = out

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 546f7ce..0b46f85 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -517,7 +517,7 @@
     <pgjdbc-ng-driver-version>0.7.1</pgjdbc-ng-driver-version>
     <powermock-version>1.6.6</powermock-version>
     <protobuf-version>3.1.0</protobuf-version>
-    <pubnub-version>3.7.4</pubnub-version>
+    <pubnub-version>4.6.0</pubnub-version>
     <qpid-bundle-version>0.28_1</qpid-bundle-version>
     <qpid-proton-j-version>0.16.0</qpid-proton-j-version>
     <qpid-proton-j-bundle-version>0.14.0</qpid-proton-j-bundle-version>

http://git-wip-us.apache.org/repos/asf/camel/blob/13042923/platforms/spring-boot/components-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml
index 78ca1c2..b0f7a5a 100644
--- a/platforms/spring-boot/components-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/pom.xml
@@ -236,6 +236,7 @@
     <module>camel-pgevent-starter</module>
     <module>camel-printer-starter</module>
     <module>camel-protobuf-starter</module>
+    <module>camel-pubnub-starter</module>
     <module>camel-quartz2-starter</module>
     <module>camel-quickfix-starter</module>
     <module>camel-rabbitmq-starter</module>