@Override public void visit(WriteRequest request) { coapRequest = request.isReplaceRequest() ? Request.newPut() : Request.newPost(); coapRequest.getOptions().setContentFormat(request.getContentFormat().getCode()); coapRequest .setPayload(LwM2mNodeEncoder.encode(request.getNode(), request.getContentFormat(), request.getPath())); setTarget(coapRequest, destination, request.getPath()); }
@Override public void visit(WriteRequest request) { o.add("kind", "write"); o.add("contentFormat", request.getContentFormat().getCode()); o.add("mode", request.isPartialUpdateRequest() ? "UPDATE" : "REPLACE"); o.add("node", LwM2mNodeSerDes.jSerialize(request.getNode())); }
/** * A generic constructor to write request. * * @param mode the mode of the request : replace or update. * @param contentFormat Format of the payload (TLV,JSON,TEXT,OPAQUE ..). * @param path the path of the LWM2M node to write (object instance or resource). * @param node the {@link LwM2mNode} to write. * @exception InvalidRequestException if parameters are invalid. */ public WriteRequest(Mode mode, ContentFormat contentFormat, String path, LwM2mNode node) throws InvalidRequestException { this(mode, contentFormat, newPath(path), node); }
@Override protected WriteResponse doWrite(ServerIdentity identity, WriteRequest request) { LwM2mPath path = request.getPath(); Map<Integer, LwM2mResource> writeResources = ((LwM2mObjectInstance) request.getNode()).getResources(); if (request.isReplaceRequest()) { return instance.write(path.getResourceId(), (LwM2mResource) request.getNode());
WriteRequest request = new WriteRequest(Mode.REPLACE, contentFormat, target, node); WriteResponse cResponse = server.send(registration, request, TIMEOUT); processDeviceResponse(req, resp, cResponse);
@Override public String toString() { return String.format("WriteRequest [mode=%s, path=%s, format=%s, node=%s]", mode, getPath(), contentFormat, node); }
@Override public synchronized WriteResponse write(ServerIdentity identity, WriteRequest request) { LwM2mPath path = request.getPath(); for (Integer writeResourceId : ((LwM2mObjectInstance) request.getNode()).getResources().keySet()) { ResourceModel resourceModel = model.resources.get(writeResourceId); if (null != resourceModel && !resourceModel.operations.isWritable()) { if (request.isReplaceRequest()) { for (Integer writeResourceId : ((LwM2mObjectInstance) request.getNode()).getResources().keySet()) { mandatoryResources.remove(writeResourceId);
doCreate(new CreateRequest(path.getObjectId(), instanceNode)); } else { doWrite(identity, new WriteRequest(Mode.REPLACE, path.getObjectId(), path.getObjectInstanceId(), instanceNode.getResources().values())); doCreate(new CreateRequest(path.getObjectId(), instanceNode)); } else { doWrite(identity, new WriteRequest(Mode.REPLACE, request.getContentFormat(), path.getObjectId(), path.getObjectInstanceId(), instanceNode.getResources().values()));
if (getPath().isResource() && mode == Mode.UPDATE) throw new InvalidRequestException("Invalid mode for '%s': update is not allowed on resource", target); if (getPath().isResource()) { if (!(node instanceof LwM2mResource)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target, node.getClass().getSimpleName()); } else if (getPath().isObjectInstance()) { if (!(node instanceof LwM2mObjectInstance)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target, node.getClass().getSimpleName()); } else if (getPath().isObject()) { throw new InvalidRequestException("write request %s cannot target an object", target); if (!getPath().isResource()) { throw new InvalidRequestException( "Invalid format for %s: %s format must be used only for single resources", target, format);
@Override public void visit(WriteRequest request) { coapRequest = request.isReplaceRequest() ? Request.newPut() : Request.newPost(); ContentFormat format = request.getContentFormat(); coapRequest.getOptions().setContentFormat(format.getCode()); coapRequest.setPayload(encoder.encode(request.getNode(), format, request.getPath(), model)); setTarget(coapRequest, request.getPath()); }
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);
@Override public void visit(WriteRequest request) { o.add("kind", "write"); o.add("contentFormat", request.getContentFormat().getCode()); o.add("mode", request.isPartialUpdateRequest() ? "UPDATE" : "REPLACE"); o.add("node", LwM2mNodeSerDes.jSerialize(request.getNode())); }
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);
LwM2mNode lwM2mNode = decoder.decode(exchange.getRequestPayload(), contentFormat, path, model); WriteResponse response = nodeEnabler.write(identity, new WriteRequest(Mode.UPDATE, contentFormat, URI, lwM2mNode)); if (response.getCode().isError()) { exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage());
new WriteRequest(Mode.REPLACE, contentFormat, URI, lwM2mNode)); if (response.getCode().isError()) { coapExchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage());