Skip to content

Commit

Permalink
Check requests received are CONFIRMABLE message
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 14, 2023
1 parent 87d3013 commit 6441d53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.mbed.coap.packet.Code;
import com.mbed.coap.packet.MediaTypes;
import com.mbed.coap.packet.Opaque;
import com.mbed.coap.transport.TransportContext;
import com.mbed.coap.utils.Service;

public abstract class LwM2mCoapResource implements Service<CoapRequest, CoapResponse> {
Expand All @@ -48,6 +49,12 @@ public LwM2mCoapResource(String uri) {
@Override
public CompletableFuture<CoapResponse> apply(CoapRequest coapRequest) {
try {
// The LWM2M transport spec v1.1.1 (section 6.4) all operation must be confirmable message except notify and
// execute which may be NON
if (coapRequest.getTransContext().get(TransportContext.NON_CONFIRMABLE)) {
return handleInvalidRequest(coapRequest, "CON CoAP type expected");
}

return handleRequest(coapRequest);
} catch (InvalidRequestException e) {
return handleInvalidRequest(coapRequest, e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ public RegistrationResource(UplinkRequestReceiver receiver, LinkParser linkParse
public CompletableFuture<CoapResponse> handlePOST(CoapRequest coapRequest) {
LOG.trace("POST received : {}", coapRequest);

// The LWM2M spec (section 8.2) mandates the usage of confirmable messages
// TODO how to check is request is confirmable message ?
// if (!CON.equals(coapRequest.getType())) {
// handleInvalidRequest(coapRequest, "CON CoAP type expected");
// return;
// }

// validate URI
List<String> uri = getUriPart(coapRequest);
if (uri == null || uri.size() == 0 || !RESOURCE_NAME.equals(uri.get(0))) {
Expand Down

0 comments on commit 6441d53

Please sign in to comment.