You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/07/01 10:01:33 UTC

[1/3] camel git commit: CAMEL-10112: Camel-CoAP: Add Ping operation to CoAP Producer - Updated docs

Repository: camel
Updated Branches:
  refs/heads/master 52ad12085 -> f0a7e744e


CAMEL-10112: Camel-CoAP: Add Ping operation to CoAP Producer - Updated docs


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

Branch: refs/heads/master
Commit: f0a7e744ed5744fcbee1c09433e48681abd8ea2f
Parents: 65c4051
Author: Andrea Cosentino <an...@gmail.com>
Authored: Fri Jul 1 11:59:48 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Jul 1 12:00:54 2016 +0200

----------------------------------------------------------------------
 components/camel-coap/src/main/docs/coap.adoc                    | 4 +++-
 .../src/main/java/org/apache/camel/coap/CoAPEndpoint.java        | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f0a7e744/components/camel-coap/src/main/docs/coap.adoc
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/main/docs/coap.adoc b/components/camel-coap/src/main/docs/coap.adoc
index dc2c92f..74a5b21 100644
--- a/components/camel-coap/src/main/docs/coap.adoc
+++ b/components/camel-coap/src/main/docs/coap.adoc
@@ -33,6 +33,7 @@ The CoAP component has no options.
 
 
 
+
 // endpoint options: START
 The CoAP component supports 6 endpoint options which are listed below:
 
@@ -41,7 +42,7 @@ The CoAP component supports 6 endpoint options which are listed below:
 |=======================================================================
 | Name | Group | Default | Java Type | Description
 | uri | common |  | URI | The URI for the CoAP endpoint
-| coapMethod | common | * | String | The CoAP method this endpoint binds to. Default is to bind to all () but can be restricted to GET POST PUT DELETE
+| coapMethod | common | * | String | The CoAP method this endpoint binds to. Default is to bind to all () but can be restricted to GET POST PUT DELETE PING
 | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
 | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
 | exchangePattern | advanced | InOnly | ExchangePattern | Sets the default exchange pattern when creating an exchange
@@ -50,3 +51,4 @@ The CoAP component supports 6 endpoint options which are listed below:
 {% endraw %}
 // endpoint options: END
 
+

http://git-wip-us.apache.org/repos/asf/camel/blob/f0a7e744/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
index 7976d53..f8e0f36 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPEndpoint.java
@@ -54,7 +54,7 @@ public class CoAPEndpoint extends DefaultEndpoint {
     }
     /**
      * The CoAP method this endpoint binds to. Default is to bind to all ("*") but can
-     * be restricted to GET, POST, PUT, DELETE 
+     * be restricted to GET, POST, PUT, DELETE, PING 
      * @return
      */
     public String getCoapMethod() {


[3/3] camel git commit: CAMEL-10112: Camel-CoAP: Add Ping operation to CoAP Producer

Posted by ac...@apache.org.
CAMEL-10112: Camel-CoAP: Add Ping operation to CoAP Producer


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

Branch: refs/heads/master
Commit: dd32693ecf142334fd04598d7e1e85107ba3fe51
Parents: 52ad120
Author: Andrea Cosentino <an...@gmail.com>
Authored: Fri Jul 1 11:54:56 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Jul 1 12:00:54 2016 +0200

----------------------------------------------------------------------
 .../org/apache/camel/coap/CoAPProducer.java     |  9 +++
 .../org/apache/camel/coap/CoAPPingTest.java     | 61 ++++++++++++++++++++
 2 files changed, 70 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dd32693e/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index a3fead9..0e9ec13 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -58,6 +58,7 @@ public class CoAPProducer extends DefaultProducer {
         }
         int mediaType = MediaTypeRegistry.parse(ct);
         CoapResponse response = null;
+        boolean pingResponse = false;
         switch (method) {
         case "GET":
             response = client.get();
@@ -73,6 +74,9 @@ public class CoAPProducer extends DefaultProducer {
             byte[] bodyPut = exchange.getIn().getBody(byte[].class);
             response = client.put(bodyPut, mediaType);
             break;
+        case "PING":
+        	pingResponse = client.ping();
+            break;
         default:
             break;
         }
@@ -83,6 +87,11 @@ public class CoAPProducer extends DefaultProducer {
             resp.setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt);
             resp.setBody(response.getPayload());
         }
+        
+        if (method.equalsIgnoreCase("PING")) {
+        	Message resp = exchange.getOut();
+        	resp.setBody(pingResponse);
+        }
     }
 
     private synchronized CoapClient getClient(Exchange exchange) {

http://git-wip-us.apache.org/repos/asf/camel/blob/dd32693e/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
new file mode 100644
index 0000000..9ed98c1
--- /dev/null
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.coap;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.californium.core.network.config.NetworkConfig;
+import org.junit.Test;
+
+public class CoAPPingTest extends CamelTestSupport {
+    static final int PORT = AvailablePortFinder.getNextAvailable();
+    
+    @Produce(uri = "direct:start")
+    protected ProducerTemplate sender;
+    
+    @Test
+    public void testCoAP() throws Exception {
+        NetworkConfig.createStandardWithoutFile();
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.expectedBodiesReceived(true);
+        sender.sendBody("Hello");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception { 
+                from("coap://localhost:" + PORT + "/TestResource?coapMethod=PING")
+                .to("log:exch")
+                .transform(body().convertTo(Boolean.class))
+                .to("log:exch");
+                
+                from("direct:start").to("coap://localhost:" + PORT + "/TestResource?coapMethod=PING").to("mock:result");
+            }
+        };
+    }
+}


[2/3] camel git commit: Fixed CS

Posted by ac...@apache.org.
Fixed CS


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

Branch: refs/heads/master
Commit: 65c40512765e2d805948e384455f58bc7c5504da
Parents: dd32693
Author: Andrea Cosentino <an...@gmail.com>
Authored: Fri Jul 1 11:57:12 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Jul 1 12:00:54 2016 +0200

----------------------------------------------------------------------
 .../src/main/java/org/apache/camel/coap/CoAPProducer.java      | 6 +++---
 .../src/test/java/org/apache/camel/coap/CoAPPingTest.java      | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/65c40512/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
index 0e9ec13..a4a17e1 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java
@@ -75,7 +75,7 @@ public class CoAPProducer extends DefaultProducer {
             response = client.put(bodyPut, mediaType);
             break;
         case "PING":
-        	pingResponse = client.ping();
+            pingResponse = client.ping();
             break;
         default:
             break;
@@ -89,8 +89,8 @@ public class CoAPProducer extends DefaultProducer {
         }
         
         if (method.equalsIgnoreCase("PING")) {
-        	Message resp = exchange.getOut();
-        	resp.setBody(pingResponse);
+            Message resp = exchange.getOut();
+            resp.setBody(pingResponse);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/65c40512/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
index 9ed98c1..1872951 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPPingTest.java
@@ -50,9 +50,9 @@ public class CoAPPingTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception { 
                 from("coap://localhost:" + PORT + "/TestResource?coapMethod=PING")
-                .to("log:exch")
-                .transform(body().convertTo(Boolean.class))
-                .to("log:exch");
+                    .to("log:exch")
+                    .transform(body().convertTo(Boolean.class))
+                    .to("log:exch");
                 
                 from("direct:start").to("coap://localhost:" + PORT + "/TestResource?coapMethod=PING").to("mock:result");
             }