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/27 08:17:32 UTC

[camel] 02/02: CAMEL-12030: Add CoAP response code header

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

commit af62f9ecf62604be0cea82b3afba57fbf9eb93d7
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Nov 27 07:59:54 2017 +0000

    CAMEL-12030: Add CoAP response code header
---
 components/camel-coap/src/main/docs/coap-component.adoc                | 3 +++
 .../camel-coap/src/main/java/org/apache/camel/coap/CoAPConstants.java  | 1 +
 .../camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java   | 1 +
 .../src/test/java/org/apache/camel/coap/CoAPComponentTest.java         | 2 ++
 4 files changed, 7 insertions(+)

diff --git a/components/camel-coap/src/main/docs/coap-component.adoc b/components/camel-coap/src/main/docs/coap-component.adoc
index e0f1481..80a435f 100644
--- a/components/camel-coap/src/main/docs/coap-component.adoc
+++ b/components/camel-coap/src/main/docs/coap-component.adoc
@@ -69,6 +69,9 @@ with the following path and query parameters:
 |`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.
 
+|`CamelCoapResponseCode` |`String` |The CoAP response code sent by the external server. See RFC 7252 for details
+of what each code means.
+
 |`CamelCoapUri` |`String` |The URI of a CoAP server to call. Will override any existing URI configured directly on the endpoint.
 |=======================================================================
 
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
index bf44a20..9507186 100644
--- 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
@@ -39,5 +39,6 @@ public interface CoAPConstants {
      * CoAP exchange header names
      */
     String COAP_METHOD = "CamelCoapMethod";
+    String COAP_RESPONSE_CODE = "CamelCoapResponseCode";
     String COAP_URI = "CamelCoapUri";
 }
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 99e46d5..4837193 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
@@ -74,6 +74,7 @@ public class CoAPProducer extends DefaultProducer {
             Message resp = exchange.getOut();
             String mt = MediaTypeRegistry.toString(response.getOptions().getContentFormat());
             resp.setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt);
+            resp.setHeader(CoAPConstants.COAP_RESPONSE_CODE, response.getCode().toString());
             resp.setBody(response.getPayload());
         }
 
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 7e44884..a01b52d 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
@@ -25,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.CoAP;
 import org.eclipse.californium.core.coap.MediaTypeRegistry;
 import org.eclipse.californium.core.network.config.NetworkConfig;
 import org.junit.Test;
@@ -46,6 +47,7 @@ public class CoAPComponentTest extends CamelTestSupport {
         mock.expectedMinimumMessageCount(1);
         mock.expectedBodiesReceived("Hello Camel CoAP");
         mock.expectedHeaderReceived(Exchange.CONTENT_TYPE, MediaTypeRegistry.toString(MediaTypeRegistry.APPLICATION_OCTET_STREAM));
+        mock.expectedHeaderReceived(CoAPConstants.COAP_RESPONSE_CODE, CoAP.ResponseCode.CONTENT.toString());
         sender.sendBody("Camel CoAP");
         assertMockEndpointsSatisfied();
     }

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