[
https://issues.apache.org/jira/browse/CAMEL-12030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16266725#comment-16266725
]
ASF GitHub Bot commented on CAMEL-12030:
----------------------------------------
oscerd closed pull request #2121: CAMEL-12030: Add CoAP response code header
URL: https://github.com/apache/camel/pull/2121
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/components/camel-coap/src/main/docs/coap-component.adoc
b/components/camel-coap/src/main/docs/coap-component.adoc
index e0f1481edb7..80a435f6d9c 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 bf44a2071ae..9507186020e 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 @@
* 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 99e46d5268f..4837193fdb5 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 void process(Exchange exchange) throws Exception {
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 7e448849322..a01b52d7545 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.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 void testCoAP() throws Exception {
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();
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Enhance CoAP producer to set a response code header
> ---------------------------------------------------
>
> Key: CAMEL-12030
> URL: https://issues.apache.org/jira/browse/CAMEL-12030
> Project: Camel
> Issue Type: Improvement
> Components: camel-coap
> Reporter: James Netherton
> Assignee: James Netherton
> Priority: Minor
> Fix For: 2.21.0
>
>
> Currently the CoAP producer only sets a CONTENT_TYPE header. It'd be useful
> to also have the status code set on the exchange.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)