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 2017/11/24 14:39:22 UTC

[camel] branch master updated: CAMEL-12030: Refactor handling of CoAP request method

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 149be76  CAMEL-12030: Refactor handling of CoAP request method
149be76 is described below

commit 149be7656d47499921abf2d475b227b572e5da94
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Nov 24 14:09:45 2017 +0000

    CAMEL-12030: Refactor handling of CoAP request method
---
 .../camel-coap/src/main/docs/coap-component.adoc   | 23 +++++-
 .../org/apache/camel/coap/CamelCoapResource.java   | 12 +--
 .../java/org/apache/camel/coap/CoAPComponent.java  |  4 +-
 .../java/org/apache/camel/coap/CoAPConstants.java  | 43 +++++++++++
 .../java/org/apache/camel/coap/CoAPEndpoint.java   | 18 ++---
 .../java/org/apache/camel/coap/CoAPHelper.java     | 64 ++++++++++++++++
 .../java/org/apache/camel/coap/CoAPProducer.java   | 29 +++----
 .../org/apache/camel/coap/CoAPComponentTest.java   |  7 +-
 .../apache/camel/coap/CoAPMethodRestrictTest.java  | 88 ++++++++++++++++++++++
 .../java/org/apache/camel/coap/CoAPMethodTest.java | 70 +++++++++++++++++
 .../java/org/apache/camel/coap/CoAPPingTest.java   |  6 +-
 11 files changed, 321 insertions(+), 43 deletions(-)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index 1b1ba80..e0f1481 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -52,10 +52,31 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *coapMethod* (common) | The CoAP method this endpoint binds to. Default is to bind to all () but can be restricted to GET POST PUT DELETE PING | * | String
 | *bridgeErrorHandler* (consumer) | 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 or ERROR level and ignored. | false | boolean
+| *coapMethodRestrict* (consumer) | Comma separated list of methods that the CoAP consumer will bind to. The default is to bind to all methods (DELETE GET POST PUT). |  | String
 | *exceptionHandler* (consumer) | 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 or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 |===
 // endpoint options: END
+
+### Message Headers
+
+[width="100%",cols="10%,20%,70%",options="header",]
+|=======================================================================
+|Name |Type |Description
+
+|`CamelCoapMethod` |`String` |The request method that the CoAP producer should use when calling the target CoAP
+server URI. Valid options are DELETE, GET, PING, POST & PUT.
+
+|`CamelCoapUri` |`String` |The URI of a CoAP server to call. Will override any existing URI configured directly on the endpoint.
+|=======================================================================
+
+#### Configuring the CoAP producer request method
+
+The following rules determine which request method the CoAP producer will use to invoke the target URI:
+
+ 1. The value of the `CamelCoapMethod` header
+ 2. **GET** if a query string is provided on the target CoAP server URI.
+ 3. **POST** if the message exchange body is not null.
+ 4. **GET** otherwise.
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CamelCoapResource.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CamelCoapResource.java
index 017fd4f..e8c08c0 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CamelCoapResource.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CamelCoapResource.java
@@ -36,7 +36,7 @@ final class CamelCoapResource extends CoapResource {
 
     CamelCoapResource(String name, CoAPConsumer consumer) {
         super(name);
-        consumers.put(consumer.getCoapEndpoint().getCoapMethod(), consumer);
+        addConsumer(consumer);
         possibles = null;
     }
 
@@ -46,7 +46,11 @@ final class CamelCoapResource extends CoapResource {
     }
     
     void addConsumer(CoAPConsumer consumer) {
-        consumers.put(consumer.getCoapEndpoint().getCoapMethod(), consumer);
+        CoAPEndpoint coapEndpoint = consumer.getCoapEndpoint();
+        String coapMethodRestrict = CoAPHelper.getDefaultMethodRestrict(coapEndpoint.getCoapMethodRestrict());
+        for (String method : coapMethodRestrict.split(",")) {
+            consumers.put(method.trim(), consumer);
+        }
     }
     
     @Override
@@ -82,10 +86,6 @@ final class CamelCoapResource extends CoapResource {
         try {
             consumer = consumers.get(exchange.getRequest().getCode().name());
             if (consumer == null) {
-                consumer = consumers.get("*");
-            }
-
-            if (consumer == null) {
                 cexchange.respond(ResponseCode.METHOD_NOT_ALLOWED);
                 return;
             }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index f24aa84..6ca54d9 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -107,7 +107,7 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
             }
         }
 
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, Object> map = new HashMap<>();
         // setup endpoint options
         if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
             map.putAll(config.getEndpointProperties());
@@ -122,7 +122,7 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
         if (uriTemplate == null) {
             uriTemplate = "";
         }
-        url += basePath + uriTemplate + "?coapMethod=" + verb.toUpperCase(Locale.US);
+        url += basePath + uriTemplate + "?coapMethodRestrict=" + verb.toUpperCase(Locale.US);
         if (!query.isEmpty()) {
             url += "&" + query;
         }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPConstants.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPConstants.java
new file mode 100644
index 0000000..bf44a20
--- /dev/null
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPConstants.java
@@ -0,0 +1,43 @@
+/**
+ * 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;
+
+/**
+ * CoAP component constants
+ */
+public interface CoAPConstants {
+
+    /**
+     * Supported request methods
+     */
+    String METHOD_DELETE = "DELETE";
+    String METHOD_GET = "GET";
+    String METHOD_PING = "PING";
+    String METHOD_POST = "POST";
+    String METHOD_PUT = "PUT";
+
+    /**
+     * Supported CoAP server methods
+     */
+    String METHOD_RESTRICT_ALL = String.format("%s,%s,%s,%s", METHOD_DELETE, METHOD_GET, METHOD_POST, METHOD_PUT);
+
+    /**
+     * CoAP exchange header names
+     */
+    String COAP_METHOD = "CamelCoapMethod";
+    String COAP_URI = "CamelCoapUri";
+}
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 7375068..bc0e2f1 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
@@ -34,8 +34,8 @@ import org.eclipse.californium.core.CoapServer;
 public class CoAPEndpoint extends DefaultEndpoint {
     @UriPath
     private URI uri;
-    @UriParam(defaultValue = "*")
-    private String coapMethod = "*";
+    @UriParam(label = "consumer")
+    private String coapMethodRestrict;
         
     private CoAPComponent component;
     
@@ -49,17 +49,17 @@ public class CoAPEndpoint extends DefaultEndpoint {
         this.component = component;
     }
 
-    public void setCoapMethod(String m) {
-        coapMethod = m;
+    public void setCoapMethodRestrict(String coapMethodRestrict) {
+        this.coapMethodRestrict = coapMethodRestrict;
     }
+
     /**
-     * The CoAP method this endpoint binds to. Default is to bind to all ("*") but can
-     * be restricted to GET, POST, PUT, DELETE, PING 
-     * @return
+     * Comma separated list of methods that the CoAP consumer will bind to. The default is to bind to all methods (DELETE, GET, POST, PUT).
      */
-    public String getCoapMethod() {
-        return coapMethod;
+    public String getCoapMethodRestrict() {
+        return this.coapMethodRestrict;
     }
+
     public Producer createProducer() throws Exception {
         return new CoAPProducer(this);
     }
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPHelper.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPHelper.java
new file mode 100644
index 0000000..9519c14
--- /dev/null
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPHelper.java
@@ -0,0 +1,64 @@
+/**
+ * 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.util.ObjectHelper;
+import org.eclipse.californium.core.CoapClient;
+
+/**
+ * Various helper methods for CoAP
+ */
+public final class CoAPHelper {
+
+    private CoAPHelper() {
+    }
+
+    /**
+     * Determines which CoAP request method to use based on the content of the target
+     * request URI, the message body or value from the CamelCoapMethod header.
+     *
+     * @param exchange the exchange
+     * @param client the CoAP client
+     * @return the CoAP request method
+     */
+    public static String getDefaultMethod(Exchange exchange, CoapClient client) {
+        String method = exchange.getIn().getHeader(CoAPConstants.COAP_METHOD, String.class);
+        if (method == null) {
+            Object body = exchange.getIn().getBody();
+            if (body == null || client.getURI().contains("?")) {
+                method = CoAPConstants.METHOD_GET;
+            } else {
+                method = CoAPConstants.METHOD_POST;
+            }
+        }
+        return method;
+    }
+
+    /**
+     * Determines which method verbs the CoAP server should be restricted to handling.
+     *
+     * @param methodRestrict
+     * @return
+     */
+    public static String getDefaultMethodRestrict(String methodRestrict) {
+        if (ObjectHelper.isNotEmpty(methodRestrict)) {
+            return methodRestrict;
+        }
+        return CoAPConstants.METHOD_RESTRICT_ALL;
+    }
+}
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 a4a17e1..99e46d5 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
@@ -44,37 +44,26 @@ public class CoAPProducer extends DefaultProducer {
             //?default?
             ct = "application/octet-stream";
         }
-        String method = exchange.getIn().getHeader(Exchange.HTTP_METHOD, String.class);
-        if (method == null) {
-            method = endpoint.getCoapMethod();
-        }
-        if (method == null) {
-            Object body = exchange.getIn().getBody();
-            if (body == null) {
-                method = "GET";
-            } else {
-                method = "POST";
-            }
-        }
+        String method = CoAPHelper.getDefaultMethod(exchange, client);
         int mediaType = MediaTypeRegistry.parse(ct);
         CoapResponse response = null;
         boolean pingResponse = false;
         switch (method) {
-        case "GET":
+        case CoAPConstants.METHOD_GET:
             response = client.get();
             break;
-        case "DELETE":
+        case CoAPConstants.METHOD_DELETE:
             response = client.delete();
             break;
-        case "POST":
+        case CoAPConstants.METHOD_POST:
             byte[] bodyPost = exchange.getIn().getBody(byte[].class);
             response = client.post(bodyPost, mediaType);
             break;
-        case "PUT":
+        case CoAPConstants.METHOD_PUT:
             byte[] bodyPut = exchange.getIn().getBody(byte[].class);
             response = client.put(bodyPut, mediaType);
             break;
-        case "PING":
+        case CoAPConstants.METHOD_PING:
             pingResponse = client.ping();
             break;
         default:
@@ -87,8 +76,8 @@ public class CoAPProducer extends DefaultProducer {
             resp.setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt);
             resp.setBody(response.getPayload());
         }
-        
-        if (method.equalsIgnoreCase("PING")) {
+
+        if (method.equalsIgnoreCase(CoAPConstants.METHOD_PING)) {
             Message resp = exchange.getOut();
             resp.setBody(pingResponse);
         }
@@ -96,7 +85,7 @@ public class CoAPProducer extends DefaultProducer {
 
     private synchronized CoapClient getClient(Exchange exchange) {
         if (client == null) {
-            URI uri = exchange.getIn().getHeader("coapUri", URI.class);
+            URI uri = exchange.getIn().getHeader(CoAPConstants.COAP_URI, URI.class);
             if (uri == null) {
                 uri = endpoint.getUri();
             }
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
index 71c538d..7e44884 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPComponentTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.coap;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
@@ -24,6 +25,7 @@ import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.eclipse.californium.core.CoapClient;
 import org.eclipse.californium.core.CoapResponse;
+import org.eclipse.californium.core.coap.MediaTypeRegistry;
 import org.eclipse.californium.core.network.config.NetworkConfig;
 import org.junit.Test;
 
@@ -42,8 +44,9 @@ public class CoAPComponentTest extends CamelTestSupport {
         
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMinimumMessageCount(1);
-        mock.expectedBodiesReceived("Hello");
-        sender.sendBody("Hello");
+        mock.expectedBodiesReceived("Hello Camel CoAP");
+        mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
+        sender.sendBody("Camel CoAP");
         assertMockEndpointsSatisfied();
     }
 
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java
new file mode 100644
index 0000000..c65d3bf
--- /dev/null
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodRestrictTest.java
@@ -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.coap;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+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 CoAPMethodRestrictTest extends CamelTestSupport {
+
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @Test
+    public void testDefaultCoAPMethodRestrict() {
+        NetworkConfig.createStandardWithoutFile();
+
+        // All request methods should be valid on this endpoint
+        assertCoAPMethodRestrictResponse("/test", CoAPConstants.METHOD_RESTRICT_ALL, "GET: /test");
+    }
+
+    @Test
+    public void testSpecifiedCoAPMethodRestrict() {
+        NetworkConfig.createStandardWithoutFile();
+
+        // Only GET is valid for /test/a
+        assertCoAPMethodRestrictResponse("/test/a", "GET", "GET: /test/a");
+
+        // Only DELETE is valid for /test/a/b
+        assertCoAPMethodRestrictResponse("/test/a/b", "DELETE", "DELETE: /test/a/b");
+
+        // Only DELETE & GET are valid for /test/a/b/c
+        assertCoAPMethodRestrictResponse("/test/a/b/c", "DELETE,GET", "DELETE & GET: /test/a/b/c");
+
+        // Only GET is valid for /test/b
+        assertCoAPMethodRestrictResponse("/test/b", "GET", "GET: /test/b");
+    }
+
+    private void assertCoAPMethodRestrictResponse(String path, String methodRestrict, String expectedResponse) {
+        for (String method : CoAPConstants.METHOD_RESTRICT_ALL.split(",")) {
+            String result = template.requestBodyAndHeader("coap://localhost:" + PORT + path, null, CoAPConstants.COAP_METHOD, method, String.class);
+            if (methodRestrict.contains(method)) {
+                assertEquals(expectedResponse, result);
+            } else {
+                assertEquals("", result);
+            }
+        }
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                fromF("coap://localhost:%d/test", PORT)
+                        .setBody(constant("GET: /test"));
+
+                fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT)
+                        .setBody(constant("GET: /test/a"));
+
+                fromF("coap://localhost:%d/test/a/b?coapMethodRestrict=DELETE", PORT)
+                        .setBody(constant("DELETE: /test/a/b"));
+
+                fromF("coap://localhost:%d/test/a/b/c?coapMethodRestrict=DELETE,GET", PORT)
+                        .setBody(constant("DELETE & GET: /test/a/b/c"));
+
+                fromF("coap://localhost:%d/test/b?coapMethodRestrict=GET", PORT)
+                        .setBody(constant("GET: /test/b"));
+            }
+        };
+    }
+}
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java
new file mode 100644
index 0000000..142e8a7
--- /dev/null
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPMethodTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+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 CoAPMethodTest extends CamelTestSupport {
+
+    private static final int PORT = AvailablePortFinder.getNextAvailable();
+
+    @Test
+    public void testCoAPMethodDefaultGet() {
+        NetworkConfig.createStandardWithoutFile();
+
+        // No body means GET
+        String result = template.requestBody("coap://localhost:" + PORT + "/test/a", null, String.class);
+        assertEquals("GET: /test/a", result);
+    }
+
+    @Test
+    public void testCoAPMethodDefaultPost() {
+        NetworkConfig.createStandardWithoutFile();
+
+        // Providing a body means POST
+        String result = template.requestBody("coap://localhost:" + PORT + "/test/b", "Camel", String.class);
+        assertEquals("Hello Camel", result);
+    }
+
+    @Test
+    public void testCoAPMethodHeader() {
+        String result = template.requestBodyAndHeader("coap://localhost:" + PORT + "/test/c", null, CoAPConstants.COAP_METHOD, "DELETE", String.class);
+        assertEquals("DELETE: /test/c", result);
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                fromF("coap://localhost:%d/test/a?coapMethodRestrict=GET", PORT)
+                        .setBody(constant("GET: /test/a"));
+
+                fromF("coap://localhost:%d/test/b?coapMethodRestrict=POST", PORT)
+                        .setBody(simple("Hello ${body}"));
+
+                fromF("coap://localhost:%d/test/c?coapMethodRestrict=DELETE", PORT)
+                        .setBody(constant("DELETE: /test/c"));
+            }
+        };
+    }
+}
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 3939c8b..c488d50 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
@@ -37,7 +37,7 @@ public class CoAPPingTest extends CamelTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMinimumMessageCount(1);
         mock.expectedBodiesReceived(true);
-        sender.sendBody("Hello");
+        sender.sendBodyAndHeader("Hello", CoAPConstants.COAP_METHOD, CoAPConstants.METHOD_PING);
         assertMockEndpointsSatisfied();
     }
 
@@ -46,12 +46,12 @@ public class CoAPPingTest extends CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception { 
-                from("coap://localhost:" + PORT + "/TestResource?coapMethod=PING")
+                from("coap://localhost:" + PORT + "/TestResource")
                     .to("log:exch")
                     .transform(body().convertTo(Boolean.class))
                     .to("log:exch");
                 
-                from("direct:start").to("coap://localhost:" + PORT + "/TestResource?coapMethod=PING").to("mock:result");
+                from("direct:start").to("coap://localhost:" + PORT + "/TestResource").to("mock:result");
             }
         };
     }

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].