private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2mRequest<?> request, String endpoint) { // Get content format ContentFormat contentFormat = null; if (coapResponse.getOptions().hasContentFormat()) { contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()); } // Decode payload try { return decoder.decode(coapResponse.getPayload(), contentFormat, path, model); } catch (CodecException e) { if (LOG.isDebugEnabled()) { byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload(); LOG.debug( String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]", request, endpoint, Hex.encodeHexString(payload))); } throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]", request, endpoint); } }
private ValueResponse buildContentResponse(final LwM2mPath path, final Response coapResponse) { final ResponseCode code = ResponseCode.CONTENT; LwM2mNode content; try { content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); } catch (final InvalidValueException e) { final String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); throw new ResourceAccessException(code, path.toString(), msg, e); } return new ValueResponse(code, content); }
@Override public void onResponse(Response coapResponse) { if (coapResponse.getCode() == CoAP.ResponseCode.CHANGED || coapResponse.getCode() == CoAP.ResponseCode.CONTENT) { try { LwM2mNode content = LwM2mNodeDecoder.decode(coapResponse.getPayload(), ContentFormat.fromCode(coapResponse.getOptions().getContentFormat()), path); ValueResponse response = new ValueResponse(ResponseCode.CHANGED, content); for (ObservationListener listener : listeners) { listener.newValue(this, response.getContent()); } } catch (InvalidValueException e) { String msg = String.format("[%s] ([%s])", e.getMessage(), e.getPath().toString()); LOG.debug(msg); } } }
case "observe": { int format = o.getInt("contentFormat", ContentFormat.TLV.getCode()); return new ObserveRequest(ContentFormat.fromCode(format), path); resources.add(resource); return new CreateRequest(ContentFormat.fromCode(format), path, new LwM2mObjectInstance(instanceId, resources)); Mode mode = o.getString("mode", "REPLACE").equals("REPLACE") ? Mode.REPLACE : Mode.UPDATE; LwM2mNode node = LwM2mNodeSerDes.deserialize((JsonObject) o.get("node")); return new WriteRequest(mode, ContentFormat.fromCode(format), path, node); return new ReadRequest(ContentFormat.fromCode(format), path);
case "observe": { int format = o.getInt("contentFormat", ContentFormat.TLV.getCode()); return new ObserveRequest(ContentFormat.fromCode(format), path); resources.add(resource); return new CreateRequest(ContentFormat.fromCode(format), path, new LwM2mObjectInstance(instanceId, resources)); Mode mode = o.getString("mode", "REPLACE").equals("REPLACE") ? Mode.REPLACE : Mode.UPDATE; LwM2mNode node = LwM2mNodeSerDes.deserialize((JsonObject) o.get("node")); return new WriteRequest(mode, ContentFormat.fromCode(format), path, node); return new ReadRequest(ContentFormat.fromCode(format), path);
contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
ContentFormat contentFormat = ContentFormat.fromCode(exchange.getRequestOptions().getContentFormat()); if (!decoder.isSupported(contentFormat)) { exchange.respond(ResponseCode.UNSUPPORTED_CONTENT_FORMAT);
ContentFormat contentFormat = ContentFormat.fromCode(coapExchange.getRequestOptions().getContentFormat()); if (!decoder.isSupported(contentFormat)) { coapExchange.respond(ResponseCode.UNSUPPORTED_CONTENT_FORMAT);
if (exchange.getRequestOptions().hasAccept()) { requestedContentFormat = ContentFormat.fromCode(exchange.getRequestOptions().getAccept()); if (!encoder.isSupported(requestedContentFormat)) { exchange.respond(ResponseCode.NOT_ACCEPTABLE);