Commit 0a7b73d1 authored by Björn Butzin's avatar Björn Butzin
Browse files

Fixes #1 Changed Error code from "Forbidden"(403) to "Method not allowed"...

Fixes #1 Changed Error code from "Forbidden"(403) to "Method not allowed" (405) when a resource does not accept a certain method
parent cb612094
......@@ -190,7 +190,7 @@ public class CoapResourceServer implements ResourceServer {
response = channel.createResponse(request, CoapResponseCode.Valid_203, CoapMediaType.text_plain);
response.setETag(request.getETag().get(eTagMatch));
} else if (!resource.isReadable()) {
response = channel.createResponse(request, CoapResponseCode.Forbidden_403);
response = channel.createResponse(request, CoapResponseCode.Method_Not_Allowed_405);
} else {
// Accept Formats?
boolean matchAccept = true;
......@@ -238,7 +238,7 @@ public class CoapResourceServer implements ResourceServer {
deleteResource(targetPath);
response = channel.createResponse(request, CoapResponseCode.Deleted_202);
} else {
response = channel.createResponse(request, CoapResponseCode.Forbidden_403);
response = channel.createResponse(request, CoapResponseCode.Method_Not_Allowed_405);
}
break;
case POST:
......@@ -251,7 +251,7 @@ public class CoapResourceServer implements ResourceServer {
resource.post(request.getPayload(), request.getContentType());
response = channel.createResponse(request, CoapResponseCode.Changed_204);
} else {
response = channel.createResponse(request, CoapResponseCode.Forbidden_403);
response = channel.createResponse(request, CoapResponseCode.Method_Not_Allowed_405);
}
break;
case PUT:
......@@ -265,7 +265,7 @@ public class CoapResourceServer implements ResourceServer {
response = channel.createResponse(request, CoapResponseCode.Precondition_Failed_412);
} else if (!this.allowCreate) {
// it is not allowed to create resources
response = channel.createResponse(request, CoapResponseCode.Forbidden_403);
response = channel.createResponse(request, CoapResponseCode.Method_Not_Allowed_405);
} else {
// all fine, create resource
createResource(createResourceFromRequest(request));
......@@ -280,7 +280,7 @@ public class CoapResourceServer implements ResourceServer {
response = channel.createResponse(request, CoapResponseCode.Precondition_Failed_412);
} else if (!resource.isPutable()) {
// resource did not accept put requests
response = channel.createResponse(request, CoapResponseCode.Forbidden_403);
response = channel.createResponse(request, CoapResponseCode.Method_Not_Allowed_405);
} else {
updateResource(resource, request);
response = channel.createResponse(request, CoapResponseCode.Changed_204);
......
......@@ -211,7 +211,7 @@ public class PlugTest {
request.setPayload("1".getBytes());
clientChannel.sendMessage(request);
while (null == receivedResponse)Thread.sleep(10);
Assert.assertEquals(CoapResponseCode.Forbidden_403,receivedResponse.getResponseCode());
Assert.assertEquals(CoapResponseCode.Method_Not_Allowed_405,receivedResponse.getResponseCode());
}
//UNRELIABLE PUT NONEXISTING NOT-ALLOWED
......@@ -223,7 +223,7 @@ public class PlugTest {
request.setPayload("2".getBytes());
clientChannel.sendMessage(request);
while (null == receivedResponse)Thread.sleep(10);
Assert.assertEquals(CoapResponseCode.Forbidden_403,receivedResponse.getResponseCode());
Assert.assertEquals(CoapResponseCode.Method_Not_Allowed_405,receivedResponse.getResponseCode());
}
// RELIABLE DELETE EXISTING ALLOWED
......@@ -273,7 +273,7 @@ public class PlugTest {
request.setPayload("2".getBytes());
clientChannel.sendMessage(request);
while (null == receivedResponse)Thread.sleep(10);
Assert.assertEquals(CoapResponseCode.Forbidden_403,receivedResponse.getResponseCode());
Assert.assertEquals(CoapResponseCode.Method_Not_Allowed_405,receivedResponse.getResponseCode());
}
// TIMEOUT -> Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment