private BootstrapDeleteRequest(LwM2mPath target) { super(target); if (target.isResource() || target.isResourceInstance()) throw new InvalidRequestException("Invalid path %s : Only objects or object instances can be deleted", target); }
public static Class<? extends LwM2mNode> nodeClassFromPath(LwM2mPath path) { if (path.isObject()) { return LwM2mObject.class; } else if (path.isObjectInstance()) { return LwM2mObjectInstance.class; } else if (path.isResource()) { return LwM2mResource.class; } throw new IllegalArgumentException("invalid path level: " + path); }
@Override public void visit(LwM2mResource resource) { LOG.trace("Encoding resource {} into JSON", resource); if (!requestPath.isResource()) { throw new CodecException("Invalid request path %s for JSON resource encoding", requestPath); } resourceList = lwM2mResourceToJsonArrayEntry("", timestamp, resource); }
if (!nodePath.isResourceInstance() && !nodePath.isResource()) { throw new CodecException( "Invalid path [%s] for resource, it should be a resource or a resource instance path",
private ExecuteRequest(LwM2mPath path, String parameters) { super(path); if (path.isRoot()) throw new InvalidRequestException("Execute request cannot target root path"); if (!path.isResource()) throw new InvalidRequestException("Invalid path %s : Only resource can be executed.", path); this.parameters = parameters; }
previousResInstance, resourceElt, nodePath.getResourceInstanceId(), nodePath); } else if (nodePath.isResource()) { if (lwM2mResourceMap.isEmpty() && baseName.isResource()) { ResourceModel resourceModel = model.getResourceModel(baseName.getObjectId(), baseName.getResourceId());
public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws CodecException { if (!path.isResource()) throw new CodecException("Invalid path %s : TextDecoder decodes resource only", path); ResourceModel rDesc = model.getResourceModel(path.getObjectId(), path.getResourceId()); String strValue = content != null ? new String(content, StandardCharsets.UTF_8) : ""; if (rDesc != null && rDesc.type != null) { return LwM2mSingleResource.newResource(path.getResourceId(), parseTextValue(strValue, rDesc.type, path), rDesc.type); } else { // unknown resource, returning a default string value return LwM2mSingleResource.newStringResource(path.getResourceId(), strValue); } }
public static LwM2mNode decode(byte[] content, LwM2mPath path, LwM2mModel model) throws CodecException { if (!path.isResource()) throw new CodecException("Invalid path %s : OpaqueDecoder decodes resource only", path); ResourceModel desc = model.getResourceModel(path.getObjectId(), path.getResourceId()); if (desc != null && desc.type != Type.OPAQUE) { throw new CodecException( "Invalid content format [%s] for path [%s], OPAQUE can only be used for single OPAQUE resource", desc.type, path); } return LwM2mSingleResource.newBinaryResource(path.getResourceId(), content); }
@Override public synchronized ObserveResponse observe(ServerIdentity identity, ObserveRequest request) { LwM2mPath path = request.getPath(); // observe is not supported for bootstrap if (identity.isLwm2mBootstrapServer()) return ObserveResponse.methodNotAllowed(); if (!identity.isSystem()) { // observe or read of the security object is forbidden if (id == LwM2mId.SECURITY) return ObserveResponse.notFound(); // check if the resource is readable. if (path.isResource()) { ResourceModel resourceModel = objectModel.resources.get(path.getResourceId()); if (resourceModel != null && !resourceModel.operations.isReadable()) return ObserveResponse.methodNotAllowed(); } } return doObserve(identity, request); }
if (getPath().isResource()) { if (!(node instanceof LwM2mResource)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target, if (!getPath().isResource()) { throw new InvalidRequestException( "Invalid format for path %s: %s format must be used only for single resources", target, format);
@Override public synchronized ExecuteResponse execute(ServerIdentity identity, ExecuteRequest request) { LwM2mPath path = request.getPath(); // execute is not supported for bootstrap if (identity.isLwm2mBootstrapServer()) { return ExecuteResponse.methodNotAllowed(); } // execute on security object is forbidden if (id == LwM2mId.SECURITY) { return ExecuteResponse.notFound(); } // only resource could be executed if (!path.isResource()) { return ExecuteResponse.badRequest(null); } // check if the resource is writable ResourceModel resourceModel = objectModel.resources.get(path.getResourceId()); if (resourceModel != null && !resourceModel.operations.isExecutable()) { return ExecuteResponse.methodNotAllowed(); } return doExecute(request); }
if (path.isResource()) {
@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. }
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, if (!getPath().isResource()) { throw new InvalidRequestException( "Invalid format for %s: %s format must be used only for single resources", target, format);
protected DiscoverResponse doDiscover(DiscoverRequest request) { LwM2mPath path = request.getPath(); if (path.isObject()) { // Manage discover on object Link[] ObjectLinks = LinkFormatHelper.getObjectDescription(this, null); return DiscoverResponse.success(ObjectLinks); } else if (path.isObjectInstance()) { // Manage discover on instance if (!getAvailableInstanceIds().contains(path.getObjectInstanceId())) return DiscoverResponse.notFound(); Link[] instanceLink = LinkFormatHelper.getInstanceDescription(this, path.getObjectInstanceId(), null); return DiscoverResponse.success(instanceLink); } else if (path.isResource()) { // Manage discover on resource if (!getAvailableInstanceIds().contains(path.getObjectInstanceId())) return DiscoverResponse.notFound(); ResourceModel resourceModel = getObjectModel().resources.get(path.getResourceId()); if (resourceModel == null) return DiscoverResponse.notFound(); if (!getAvailableResourceIds(path.getObjectInstanceId()).contains(path.getResourceId())) return DiscoverResponse.notFound(); Link resourceLink = LinkFormatHelper.getResourceDescription(this, path.getObjectInstanceId(), path.getResourceId(), null); return DiscoverResponse.success(new Link[] { resourceLink }); } return DiscoverResponse.badRequest(null); }
tlv.getType().name(), path); if (path.isResource() && path.getResourceId() != tlv.getIdentifier()) { throw new CodecException("Id conflict between path [%s] and resource TLV [resource id=%s]", path, tlv.getIdentifier());
if (path.isResource()) { byte[] payload = exchange.getRequestPayload(); ExecuteResponse response = nodeEnabler.execute(identity,