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/11/24 09:33:12 UTC
[camel] branch camel-2.20.x updated: CAMEL-12029: Return 4.05
response if no consumers were found for the request method
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.20.x by this push:
new abd8ec3 CAMEL-12029: Return 4.05 response if no consumers were found for the request method
abd8ec3 is described below
commit abd8ec396fe7831331ceb98aebc2a6fa9c0c2e5d
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Nov 24 08:25:27 2017 +0000
CAMEL-12029: Return 4.05 response if no consumers were found for the request method
---
.../org/apache/camel/coap/CamelCoapResource.java | 11 ++++++++---
.../apache/camel/coap/CoAPRestComponentTest.java | 23 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
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 7c709b6..017fd4f 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
@@ -84,7 +84,12 @@ final class CamelCoapResource extends CoapResource {
if (consumer == null) {
consumer = consumers.get("*");
}
-
+
+ if (consumer == null) {
+ cexchange.respond(ResponseCode.METHOD_NOT_ALLOWED);
+ return;
+ }
+
camelExchange = consumer.getEndpoint().createExchange();
consumer.createUoW(camelExchange);
@@ -125,8 +130,8 @@ final class CamelCoapResource extends CoapResource {
byte bytes[] = exchange.getCurrentRequest().getPayload();
camelExchange.getIn().setBody(bytes);
-
- consumer.getProcessor().process(camelExchange);
+
+ consumer.getProcessor().process(camelExchange);
Message target = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn();
int format = MediaTypeRegistry.parse(target.getHeader(org.apache.camel.Exchange.CONTENT_TYPE, String.class));
diff --git a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
index e35f98f..12cfd83 100644
--- a/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
+++ b/components/camel-coap/src/test/java/org/apache/camel/coap/CoAPRestComponentTest.java
@@ -23,6 +23,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.ResponseCode;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.eclipse.californium.core.network.config.NetworkConfig;
import org.junit.Test;
@@ -39,19 +40,41 @@ public class CoAPRestComponentTest extends CamelTestSupport {
client = new CoapClient("coap://localhost:" + coapport + "/TestResource/Ducky");
client.setTimeout(1000000);
rsp = client.get();
+ assertEquals(ResponseCode.CONTENT, rsp.getCode());
assertEquals("Hello Ducky", rsp.getResponseText());
rsp = client.post("data", MediaTypeRegistry.TEXT_PLAIN);
+ assertEquals(ResponseCode.CONTENT, rsp.getCode());
assertEquals("Hello Ducky: data", rsp.getResponseText());
client = new CoapClient("coap://localhost:" + coapport + "/TestParams?id=Ducky");
client.setTimeout(1000000);
rsp = client.get();
+ assertEquals(ResponseCode.CONTENT, rsp.getCode());
assertEquals("Hello Ducky", rsp.getResponseText());
rsp = client.post("data", MediaTypeRegistry.TEXT_PLAIN);
+ assertEquals(ResponseCode.CONTENT, rsp.getCode());
assertEquals("Hello Ducky: data", rsp.getResponseText());
assertEquals(MediaTypeRegistry.TEXT_PLAIN, rsp.getOptions().getContentFormat());
}
+ @Test
+ public void testCoAPMethodNotAllowedResponse() throws Exception {
+ NetworkConfig.createStandardWithoutFile();
+ CoapClient client = new CoapClient("coap://localhost:" + coapport + "/TestResource/Ducky");
+ client.setTimeout(1000000);
+ CoapResponse rsp = client.delete();
+ assertEquals(ResponseCode.METHOD_NOT_ALLOWED, rsp.getCode());
+ }
+
+ @Test
+ public void testCoAPNotFoundResponse() throws Exception {
+ NetworkConfig.createStandardWithoutFile();
+ CoapClient client = new CoapClient("coap://localhost:" + coapport + "/foo/bar/cheese");
+ client.setTimeout(1000000);
+ CoapResponse rsp = client.get();
+ assertEquals(ResponseCode.NOT_FOUND, rsp.getCode());
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].