From ca15e3d2011bbea9c05779bdbf1dfd75eeac5ced Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Wed, 26 Jun 2019 15:39:39 +0200 Subject: [PATCH] Enhance the way we handle InvalidRequest from foreign peer. --- leshan-bsserver-demo/logback-config.xml | 1 + .../californium/impl/BootstrapResource.java | 7 +- .../californium/impl/ObjectResource.java | 43 ++------ .../client/californium/impl/RootResource.java | 7 +- .../main/resources/simplelogger.properties | 1 + .../core/californium/EndpointContextUtil.java | 45 +++++++-- .../core/californium/LwM2mCoapResource.java | 98 +++++++++++++++++++ .../californium/impl/BootstrapResource.java | 21 +--- .../californium/impl/RegisterResource.java | 43 +++----- leshan-server-demo/logback-config.xml | 1 + 10 files changed, 171 insertions(+), 96 deletions(-) create mode 100644 leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/LwM2mCoapResource.java diff --git a/leshan-bsserver-demo/logback-config.xml b/leshan-bsserver-demo/logback-config.xml index 1f4aa77850..39c021a9a6 100644 --- a/leshan-bsserver-demo/logback-config.xml +++ b/leshan-bsserver-demo/logback-config.xml @@ -26,6 +26,7 @@ Contributors: + diff --git a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/BootstrapResource.java b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/BootstrapResource.java index 4aa3511449..431ab899fc 100644 --- a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/BootstrapResource.java +++ b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/BootstrapResource.java @@ -18,7 +18,6 @@ import static org.eclipse.leshan.core.californium.ResponseCodeUtil.toCoapResponseCode; -import org.eclipse.californium.core.CoapResource; import org.eclipse.californium.core.coap.MediaTypeRegistry; import org.eclipse.californium.core.coap.MessageObserverAdapter; import org.eclipse.californium.core.coap.Response; @@ -26,6 +25,7 @@ import org.eclipse.californium.core.server.resources.Resource; import org.eclipse.leshan.client.request.ServerIdentity; import org.eclipse.leshan.client.servers.BootstrapHandler; +import org.eclipse.leshan.core.californium.LwM2mCoapResource; import org.eclipse.leshan.core.request.BootstrapFinishRequest; import org.eclipse.leshan.core.response.BootstrapFinishResponse; import org.eclipse.leshan.core.response.SendableResponse; @@ -33,12 +33,13 @@ /** * A CoAP {@link Resource} in charge of handling the Bootstrap Finish indication from the bootstrap server. */ -public class BootstrapResource extends CoapResource { +public class BootstrapResource extends LwM2mCoapResource { private final BootstrapHandler bootstrapHandler; public BootstrapResource(BootstrapHandler bootstrapHandler) { - super("bs", false); + super("bs"); + this.setVisible(false); this.bootstrapHandler = bootstrapHandler; } diff --git a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/ObjectResource.java b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/ObjectResource.java index 314a075851..480186a2b7 100644 --- a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/ObjectResource.java +++ b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/ObjectResource.java @@ -24,11 +24,8 @@ import java.util.List; -import org.eclipse.californium.core.CoapResource; import org.eclipse.californium.core.coap.CoAP.ResponseCode; import org.eclipse.californium.core.coap.MediaTypeRegistry; -import org.eclipse.californium.core.coap.Response; -import org.eclipse.californium.core.network.Exchange; import org.eclipse.californium.core.server.resources.CoapExchange; import org.eclipse.californium.core.server.resources.Resource; import org.eclipse.leshan.Link; @@ -37,6 +34,7 @@ import org.eclipse.leshan.client.resource.NotifySender; import org.eclipse.leshan.client.servers.BootstrapHandler; import org.eclipse.leshan.core.attributes.AttributeSet; +import org.eclipse.leshan.core.californium.LwM2mCoapResource; import org.eclipse.leshan.core.model.LwM2mModel; import org.eclipse.leshan.core.node.LwM2mNode; import org.eclipse.leshan.core.node.LwM2mObjectInstance; @@ -57,7 +55,6 @@ import org.eclipse.leshan.core.request.WriteAttributesRequest; import org.eclipse.leshan.core.request.WriteRequest; import org.eclipse.leshan.core.request.WriteRequest.Mode; -import org.eclipse.leshan.core.request.exception.InvalidRequestException; import org.eclipse.leshan.core.response.BootstrapDeleteResponse; import org.eclipse.leshan.core.response.BootstrapWriteResponse; import org.eclipse.leshan.core.response.CreateResponse; @@ -68,15 +65,11 @@ import org.eclipse.leshan.core.response.ReadResponse; import org.eclipse.leshan.core.response.WriteAttributesResponse; import org.eclipse.leshan.core.response.WriteResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A CoAP {@link Resource} in charge of handling requests for of a lwM2M Object. */ -public class ObjectResource extends CoapResource implements NotifySender { - - private static final Logger LOG = LoggerFactory.getLogger(ObjectResource.class); +public class ObjectResource extends LwM2mCoapResource implements NotifySender { private final LwM2mObjectEnabler nodeEnabler; private final BootstrapHandler bootstrapHandler; @@ -94,25 +87,6 @@ public ObjectResource(LwM2mObjectEnabler nodeEnabler, BootstrapHandler bootstrap setObservable(true); } - @Override - public void handleRequest(Exchange exchange) { - try { - super.handleRequest(exchange); - } catch (InvalidRequestException e) { - if (LOG.isDebugEnabled()) { - LOG.debug(String.format("InvalidRequestException while handling request(%s) on the %s resource", - exchange.getRequest(), getURI()), e); - } - Response response = new Response(ResponseCode.BAD_REQUEST); - response.setPayload(e.getMessage()); - exchange.sendResponse(response); - } catch (Exception e) { - LOG.error(String.format("Exception while handling request(%s) on the %s resource", exchange.getRequest(), - getURI()), e); - exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR)); - } - } - @Override public void handleGET(CoapExchange exchange) { ServerIdentity identity = extractServerIdentity(exchange, bootstrapHandler); @@ -214,7 +188,7 @@ public void handlePUT(CoapExchange coapExchange) { LwM2mPath path = new LwM2mPath(URI); if (!coapExchange.getRequestOptions().hasContentFormat()) { - coapExchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory"); + handleInvalidRequest(coapExchange, "Content Format is mandatory"); return; } @@ -247,8 +221,7 @@ public void handlePUT(CoapExchange coapExchange) { return; } catch (CodecException e) { - LOG.warn("Unable to decode payload to write", e); - coapExchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(coapExchange.advanced(), "Unable to decode payload on WRITE", e); return; } @@ -277,7 +250,7 @@ public void handlePOST(CoapExchange exchange) { // handle content format for Write (Update) and Create request if (!exchange.getRequestOptions().hasContentFormat()) { - exchange.respond(ResponseCode.BAD_REQUEST, "Content Format is mandatory"); + handleInvalidRequest(exchange, "Content Format is mandatory"); return; } @@ -300,8 +273,7 @@ public void handlePOST(CoapExchange exchange) { exchange.respond(toCoapResponseCode(response.getCode())); } } catch (CodecException e) { - LOG.warn("Unable to decode payload to write", e); - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange.advanced(), "Unable to decode payload on WRITE", e); } return; } @@ -332,8 +304,7 @@ public void handlePOST(CoapExchange exchange) { return; } } catch (CodecException e) { - LOG.warn("Unable to decode payload to create", e); - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange.advanced(), "Unable to decode payload on CREATE", e); return; } } diff --git a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/RootResource.java b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/RootResource.java index 9c1626cc87..c8189cb589 100644 --- a/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/RootResource.java +++ b/leshan-client-cf/src/main/java/org/eclipse/leshan/client/californium/impl/RootResource.java @@ -23,18 +23,21 @@ import org.eclipse.californium.core.server.resources.CoapExchange; import org.eclipse.leshan.client.request.ServerIdentity; import org.eclipse.leshan.client.servers.BootstrapHandler; +import org.eclipse.leshan.core.californium.LwM2mCoapResource; import org.eclipse.leshan.core.request.BootstrapDeleteRequest; import org.eclipse.leshan.core.response.BootstrapDeleteResponse; import org.eclipse.leshan.util.StringUtils; + /** * A {@link CoapResource} resource in charge of handling Bootstrap Delete requests targeting the "/" URI. */ -public class RootResource extends CoapResource { +public class RootResource extends LwM2mCoapResource { private final BootstrapHandler bootstrapHandler; public RootResource(BootstrapHandler bootstrapHandler) { - super("", false); + super(""); + setVisible(false); this.bootstrapHandler = bootstrapHandler; } diff --git a/leshan-client-demo/src/main/resources/simplelogger.properties b/leshan-client-demo/src/main/resources/simplelogger.properties index 0ffcfa2822..3018a6a9e0 100644 --- a/leshan-client-demo/src/main/resources/simplelogger.properties +++ b/leshan-client-demo/src/main/resources/simplelogger.properties @@ -4,5 +4,6 @@ org.slf4j.simpleLogger.showShortLogName=true org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss,SSS org.slf4j.simpleLogger.defaultLogLevel=WARN org.slf4j.simpleLogger.log.org.eclipse.leshan=INFO +org.slf4j.simpleLogger.log.org.eclipse.leshan.core.californium.LwM2mCoapResource=DEBUG org.slf4j.simpleLogger.log.org.eclipse.leshan.server.security.SecurityCheck=DEBUG org.slf4j.simpleLogger.log.org.eclipse.leshan.core.model.LwM2mModel=TRACE \ No newline at end of file diff --git a/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/EndpointContextUtil.java b/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/EndpointContextUtil.java index 5f74b8bda2..e56293def4 100644 --- a/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/EndpointContextUtil.java +++ b/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/EndpointContextUtil.java @@ -31,9 +31,25 @@ import org.eclipse.californium.elements.auth.RawPublicKeyIdentity; import org.eclipse.californium.elements.auth.X509CertPath; import org.eclipse.leshan.core.request.Identity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +/** + * Utility class used to handle Californium {@link EndpointContext} in Leshan. + *

+ * Able to translate Californium {@link EndpointContext} to Leshan {@link Identity} and vice-versa. + */ public class EndpointContextUtil { + private static final Logger LOG = LoggerFactory.getLogger(EndpointContextUtil.class); + + /** + * Create Leshan {@link Identity} from Californium {@link EndpointContext}. + * + * @param context The Californium {@link EndpointContext} to convert. + * @return The corresponding Leshan {@link Identity}. + * @throws IllegalStateException if we are not able to extract {@link Identity}. + */ public static Identity extractIdentity(EndpointContext context) { InetSocketAddress peerAddress = context.getPeerAddress(); Principal senderIdentity = context.getPeerIdentity(); @@ -48,16 +64,33 @@ public static Identity extractIdentity(EndpointContext context) { String x509CommonName = extractCN(senderIdentity.getName()); return Identity.x509(peerAddress, x509CommonName); } - throw new IllegalStateException("Unable to extract sender identity : unexpected type of Principal"); + throw new IllegalStateException( + String.format("Unable to extract sender identity : unexpected type of Principal %s [%s]", + senderIdentity.getClass(), senderIdentity.toString())); } return Identity.unsecure(peerAddress); } /** - * Create californium endpoint context from leshan identity. + * Create Leshan {@link Identity} from Californium {@link EndpointContext}. + * + * @param context The Californium {@link EndpointContext} to convert. + * @return The corresponding Leshan {@link Identity} or null if we didn't succeed to extract Identity. + */ + public static Identity extractIdentitySafely(EndpointContext context) { + try { + return extractIdentity(context); + } catch (RuntimeException e) { + LOG.error("Unable to extract identity", e); + return null; + } + } + + /** + * Create Californium {@link EndpointContext} from Leshan {@link Identity}. * - * @param identity leshan identity received on last registration. - * @return californium endpoint context for leshan identity + * @param identity The Leshan {@link Identity} to convert. + * @return The corresponding Californium {@link EndpointContext}. */ public static EndpointContext extractContext(Identity identity) { Principal peerIdentity = null; @@ -77,8 +110,8 @@ public static EndpointContext extractContext(Identity identity) { /** * Extract "common name" from "distinguished name". * - * @param dn distinguished name - * @return common name + * @param dn The distinguished name. + * @return The extracted common name. * @throws IllegalStateException if no CN is contained in DN. */ public static String extractCN(String dn) { diff --git a/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/LwM2mCoapResource.java b/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/LwM2mCoapResource.java new file mode 100644 index 0000000000..fc4342ab51 --- /dev/null +++ b/leshan-core-cf/src/main/java/org/eclipse/leshan/core/californium/LwM2mCoapResource.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2019 Sierra Wireless and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.html. + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.leshan.core.californium; + +import org.eclipse.californium.core.CoapResource; +import org.eclipse.californium.core.coap.CoAP.ResponseCode; +import org.eclipse.californium.core.coap.MediaTypeRegistry; +import org.eclipse.californium.core.coap.Request; +import org.eclipse.californium.core.coap.Response; +import org.eclipse.californium.core.network.Exchange; +import org.eclipse.californium.core.server.resources.CoapExchange; +import org.eclipse.leshan.core.request.exception.InvalidRequestException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A Common {@link CoapResource} used to handle LWM2M request. + *

+ * It provides mainly features about error handling. + */ +public class LwM2mCoapResource extends CoapResource { + + private static final Logger LOG = LoggerFactory.getLogger(LwM2mCoapResource.class); + + /** + * @see CoapResource#CoapResource(String) + */ + public LwM2mCoapResource(String name) { + super(name); + } + + @Override + public void handleRequest(Exchange exchange) { + try { + super.handleRequest(exchange); + } catch (InvalidRequestException e) { + handleInvalidRequest(exchange, e.getMessage(), e); + } catch (RuntimeException e) { + Request request = exchange.getRequest(); + LOG.error("Exception while handling request [{}] on the resource {} from {}", request, getURI(), + EndpointContextUtil.extractIdentitySafely(request.getSourceContext()), e); + exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR)); + } + } + + /** + * Handle an Invalid Request by sending a BAD_REQUEST response and logging the error using debug level. + * + * @param exchange The CoAP exchange linked to the invalid request. + * @param message The error message describing why the request is invalid. + */ + protected void handleInvalidRequest(CoapExchange exchange, String message) { + handleInvalidRequest(exchange.advanced(), message, null); + } + + /** + * Handle an Invalid Request by sending a BAD_REQUEST response and logging the error using debug level. + * + * @param exchange The exchange linked to the invalid request. + * @param message The error message describing why the request is invalid. + * @param error An {@link Throwable} raised while we handle try create a LWM2M request from CoAP request. + */ + protected void handleInvalidRequest(Exchange exchange, String message, Throwable error) { + Request request = exchange.getRequest(); + + // Log error + if (LOG.isDebugEnabled()) { + if (error != null) { + LOG.debug("Invalid request [{}] received on the resource {} from {}", request, getURI(), + EndpointContextUtil.extractIdentitySafely(request.getSourceContext()), error); + } else { + LOG.debug("Invalid request [{}] received on the resource {} from {} : {}", request, getURI(), + EndpointContextUtil.extractIdentitySafely(request.getSourceContext()), message); + } + } + + // Send Response + Response response = new Response(ResponseCode.BAD_REQUEST); + if (message != null) { + response.setPayload(message); + response.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN); + } + exchange.sendResponse(response); + } +} \ No newline at end of file diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/BootstrapResource.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/BootstrapResource.java index f674ca5333..19f9e2c905 100644 --- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/BootstrapResource.java +++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/BootstrapResource.java @@ -17,14 +17,11 @@ import static org.eclipse.leshan.core.californium.ResponseCodeUtil.toCoapResponseCode; -import org.eclipse.californium.core.CoapResource; -import org.eclipse.californium.core.coap.CoAP.ResponseCode; import org.eclipse.californium.core.coap.CoAP.Type; import org.eclipse.californium.core.coap.Request; -import org.eclipse.californium.core.coap.Response; -import org.eclipse.californium.core.network.Exchange; import org.eclipse.californium.core.server.resources.CoapExchange; import org.eclipse.leshan.core.californium.EndpointContextUtil; +import org.eclipse.leshan.core.californium.LwM2mCoapResource; import org.eclipse.leshan.core.request.BootstrapRequest; import org.eclipse.leshan.core.request.Identity; import org.eclipse.leshan.core.response.BootstrapResponse; @@ -33,7 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BootstrapResource extends CoapResource { +public class BootstrapResource extends LwM2mCoapResource { private static final Logger LOG = LoggerFactory.getLogger(BootstrapResource.class); private static final String QUERY_PARAM_ENDPOINT = "ep="; @@ -45,25 +42,15 @@ public BootstrapResource(BootstrapHandler handler) { bootstrapHandler = handler; } - @Override - public void handleRequest(Exchange exchange) { - try { - super.handleRequest(exchange); - } catch (Exception e) { - LOG.error("Exception while handling a request on the /bs resource", e); - exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR)); - } - } - @Override public void handlePOST(CoapExchange exchange) { Request request = exchange.advanced().getRequest(); - LOG.debug("POST received : {}", request); + LOG.trace("POST received : {}", request); // The LW M2M spec (section 8.2) mandates the usage of Confirmable // messages if (!Type.CON.equals(request.getType())) { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "CON CoAP type expected"); return; } diff --git a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/RegisterResource.java b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/RegisterResource.java index 9f69794847..84cae65e50 100644 --- a/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/RegisterResource.java +++ b/leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/RegisterResource.java @@ -23,21 +23,18 @@ import java.util.List; import java.util.Map; -import org.eclipse.californium.core.CoapResource; import org.eclipse.californium.core.coap.CoAP.ResponseCode; import org.eclipse.californium.core.coap.CoAP.Type; import org.eclipse.californium.core.coap.Request; -import org.eclipse.californium.core.coap.Response; -import org.eclipse.californium.core.network.Exchange; import org.eclipse.californium.core.server.resources.CoapExchange; import org.eclipse.californium.core.server.resources.Resource; import org.eclipse.leshan.Link; +import org.eclipse.leshan.core.californium.LwM2mCoapResource; import org.eclipse.leshan.core.request.BindingMode; import org.eclipse.leshan.core.request.DeregisterRequest; import org.eclipse.leshan.core.request.Identity; import org.eclipse.leshan.core.request.RegisterRequest; import org.eclipse.leshan.core.request.UpdateRequest; -import org.eclipse.leshan.core.request.exception.InvalidRequestException; import org.eclipse.leshan.core.response.DeregisterResponse; import org.eclipse.leshan.core.response.RegisterResponse; import org.eclipse.leshan.core.response.SendableResponse; @@ -54,7 +51,7 @@ * {@link RegistrationService}. *

*/ -public class RegisterResource extends CoapResource { +public class RegisterResource extends LwM2mCoapResource { private static final String QUERY_PARAM_ENDPOINT = "ep="; @@ -79,37 +76,20 @@ public RegisterResource(RegistrationHandler registrationHandler) { getAttributes().addResourceType("core.rd"); } - @Override - public void handleRequest(Exchange exchange) { - try { - super.handleRequest(exchange); - } catch (InvalidRequestException e) { - LOG.debug("InvalidRequestException while handling request({}) on the /rd resource", exchange.getRequest(), - e); - Response response = new Response(ResponseCode.BAD_REQUEST); - response.setPayload(e.getMessage()); - exchange.sendResponse(response); - } catch (RuntimeException e) { - LOG.error("Exception while handling request({}) on the /rd resource", exchange.getRequest(), e); - exchange.sendResponse(new Response(ResponseCode.INTERNAL_SERVER_ERROR)); - } - } - @Override public void handlePOST(CoapExchange exchange) { Request request = exchange.advanced().getRequest(); - - LOG.debug("POST received : {}", request); + LOG.trace("POST received : {}", request); // The LWM2M spec (section 8.2) mandates the usage of confirmable messages if (!Type.CON.equals(request.getType())) { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "CON CoAP type expected"); return; } List uri = exchange.getRequestOptions().getUriPath(); if (uri == null || uri.size() == 0 || !RESOURCE_NAME.equals(uri.get(0))) { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "Bad URI"); return; } @@ -120,22 +100,21 @@ public void handlePOST(CoapExchange exchange) { handleUpdate(exchange, request, uri.get(1)); return; } else { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "Bad URI"); return; } } @Override public void handleDELETE(CoapExchange exchange) { - LOG.debug("DELETE received : {}", exchange.advanced().getRequest()); + LOG.trace("DELETE received : {}", exchange.advanced().getRequest()); List uri = exchange.getRequestOptions().getUriPath(); if (uri != null && uri.size() == 2 && RESOURCE_NAME.equals(uri.get(0))) { handleDeregister(exchange, uri.get(1)); } else { - LOG.debug("Invalid deregistration"); - exchange.respond(ResponseCode.NOT_FOUND); + handleInvalidRequest(exchange, "Bad URI"); } } @@ -272,15 +251,15 @@ private void handleDeregister(CoapExchange exchange, String registrationId) { public void handlePUT(CoapExchange exchange) { Request request = exchange.advanced().getRequest(); - LOG.debug("UPDATE received : {}", request); + LOG.trace("UPDATE received : {}", request); if (!Type.CON.equals(request.getType())) { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "CON CoAP type expected"); return; } List uri = exchange.getRequestOptions().getUriPath(); if (uri == null || uri.size() != 2 || !RESOURCE_NAME.equals(uri.get(0))) { - exchange.respond(ResponseCode.BAD_REQUEST); + handleInvalidRequest(exchange, "Bad URI"); return; } diff --git a/leshan-server-demo/logback-config.xml b/leshan-server-demo/logback-config.xml index 411f52addd..a1f29e6d4b 100644 --- a/leshan-server-demo/logback-config.xml +++ b/leshan-server-demo/logback-config.xml @@ -26,6 +26,7 @@ Contributors: + \ No newline at end of file