@Override public final String toString() { return String.format("ReadRequest [path=%s format=%s]", getPath(), format); }
@Override public void visit(ReadRequest request) { coapRequest = Request.newGet(); setTarget(coapRequest, destination, request.getPath()); }
@Override protected ReadResponse doRead(ServerIdentity identity, ReadRequest request) { LwM2mPath path = request.getPath(); // Manage Object case if (path.isObject()) { List<LwM2mObjectInstance> lwM2mObjectInstances = new ArrayList<>(); for (Entry<Integer, LwM2mInstanceEnabler> entry : instances.entrySet()) { lwM2mObjectInstances.add(getLwM2mObjectInstance(entry.getKey(), entry.getValue(), identity, false)); } return ReadResponse.success(new LwM2mObject(getId(), lwM2mObjectInstances)); } // Manage Instance case LwM2mInstanceEnabler instance = instances.get(path.getObjectInstanceId()); if (instance == null) return ReadResponse.notFound(); if (path.getResourceId() == null) { return ReadResponse.success(getLwM2mObjectInstance(path.getObjectInstanceId(), instance, identity, false)); } // Manage Resource case return instance.read(path.getResourceId()); }
@Override public void visit(ReadRequest request) { coapRequest = Request.newGet(); if (request.getContentFormat() != null) coapRequest.getOptions().setAccept(request.getContentFormat().getCode()); setTarget(coapRequest, request.getPath()); }
@Override public void visit(final ReadRequest request) { switch (coapResponse.getCode()) { case CONTENT: lwM2mresponse = buildContentResponse(request.getPath(), coapResponse); break; case UNAUTHORIZED: case NOT_FOUND: case METHOD_NOT_ALLOWED: lwM2mresponse = new ValueResponse(fromCoapCode(coapResponse.getCode().value)); break; default: handleUnexpectedResponseCode(client.getEndpoint(), coapRequest, coapResponse); } }
@Override public synchronized ReadResponse read(ServerIdentity identity, ReadRequest request) { LwM2mPath path = request.getPath(); // read is not supported for bootstrap if (identity.isLwm2mBootstrapServer()) { return ReadResponse.methodNotAllowed(); } if (!identity.isSystem()) { // read the security object is forbidden if (id == LwM2mId.SECURITY) { return ReadResponse.notFound(); } // check if the resource is readable. if (path.isResource()) { ResourceModel resourceModel = objectModel.resources.get(path.getResourceId()); if (resourceModel != null && !resourceModel.operations.isReadable()) { return ReadResponse.methodNotAllowed(); } } } return doRead(identity, request); // TODO we could do a validation of response.getContent by comparing with the spec. }
@Override public void visit(ReadRequest request) { if (coapResponse.isError()) { // handle error response: lwM2mresponse = new ReadResponse(toLwM2mResponseCode(coapResponse.getCode()), null, coapResponse.getPayloadString(), coapResponse); } else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT) { // handle success response: LwM2mNode content = decodeCoapResponse(request.getPath(), coapResponse, request, registration.getEndpoint()); lwM2mresponse = new ReadResponse(ResponseCode.CONTENT, content, null, coapResponse); } else { // handle unexpected response: handleUnexpectedResponseCode(registration.getEndpoint(), request, coapResponse); } }