lwm2m: update version: leshan = M15, californium = 3.12.1

This commit is contained in:
nick 2024-10-02 13:12:53 +03:00
parent f6eb2d922b
commit 8d6768009d
7 changed files with 72 additions and 71 deletions

View File

@ -49,13 +49,13 @@ public class LwM2mAttributesTest {
@ParameterizedTest(name = "Tests {index} : {0}") @ParameterizedTest(name = "Tests {index} : {0}")
@MethodSource("doesntSupportAttributesWithoutValue") @MethodSource("doesntSupportAttributesWithoutValue")
public void check_attribute_can_not_be_created_without_value(LwM2mAttributeModel<?> model) { public void check_attribute_can_not_be_created_without_value(LwM2mAttributeModel<?> model) {
assertThrows(UnsupportedOperationException.class, () -> LwM2mAttributes.create(model)); assertThrows(IllegalArgumentException.class, () -> LwM2mAttributes.create(model));
} }
@ParameterizedTest(name = "Tests {index} : {0}") @ParameterizedTest(name = "Tests {index} : {0}")
@MethodSource("doesntSupportAttributesWithValueNull") @MethodSource("doesntSupportAttributesWithValueNull")
public void check_attribute_can_not_be_created_with_null(LwM2mAttributeModel<?> model) { public void check_attribute_can_not_be_created_with_null(LwM2mAttributeModel<?> model) {
assertThrows(NullPointerException.class, () -> LwM2mAttributes.create(model, null)); assertThrows(IllegalArgumentException.class, () -> LwM2mAttributes.create(model, null));
} }
private static Stream<Arguments> supportNullAttributes() throws InvalidAttributeException { private static Stream<Arguments> supportNullAttributes() throws InvalidAttributeException {

View File

@ -69,7 +69,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -88,6 +87,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
private LinkFormatHelper tbLinkFormatHelper; private LinkFormatHelper tbLinkFormatHelper;
protected Map<LwM2mPath, LwM2mAttributeSet> lwM2mAttributes; protected Map<LwM2mPath, LwM2mAttributeSet> lwM2mAttributes;
public TbLwm2mObjectEnabler(int id, ObjectModel objectModel, Map<Integer, LwM2mInstanceEnabler> instances, public TbLwm2mObjectEnabler(int id, ObjectModel objectModel, Map<Integer, LwM2mInstanceEnabler> instances,
LwM2mInstanceEnablerFactory instanceFactory, ContentFormat defaultContentFormat) { LwM2mInstanceEnablerFactory instanceFactory, ContentFormat defaultContentFormat) {
super(id, objectModel); super(id, objectModel);
@ -643,7 +643,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
LwM2mPath path = request.getPath(); LwM2mPath path = request.getPath();
if (path.isObject()) { if (path.isObject()) {
LwM2mLink[] ObjectLinks = linkUpdateAttributes(this.tbLinkFormatHelper.getObjectDescription(this, null), server); LwM2mLink[] ObjectLinks = linkAddUpdateAttributes(this.tbLinkFormatHelper.getObjectDescription(server, this, null), server);
return DiscoverResponse.success(ObjectLinks); return DiscoverResponse.success(ObjectLinks);
} else if (path.isObjectInstance()) { } else if (path.isObjectInstance()) {
@ -651,7 +651,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
if (!getAvailableInstanceIds().contains(path.getObjectInstanceId())) if (!getAvailableInstanceIds().contains(path.getObjectInstanceId()))
return DiscoverResponse.notFound(); return DiscoverResponse.notFound();
LwM2mLink[] instanceLink = linkUpdateAttributes(this.tbLinkFormatHelper.getInstanceDescription(this, path.getObjectInstanceId(), null), server); LwM2mLink[] instanceLink = linkAddUpdateAttributes(this.tbLinkFormatHelper.getInstanceDescription(server, this, path.getObjectInstanceId(), null), server);
return DiscoverResponse.success(instanceLink); return DiscoverResponse.success(instanceLink);
} else if (path.isResource()) { } else if (path.isResource()) {
@ -666,21 +666,16 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
if (!getAvailableResourceIds(path.getObjectInstanceId()).contains(path.getResourceId())) if (!getAvailableResourceIds(path.getObjectInstanceId()).contains(path.getResourceId()))
return DiscoverResponse.notFound(); return DiscoverResponse.notFound();
LwM2mLink resourceLink = linkAddAttribute( LwM2mLink[] resourceLink = linkAddUpdateAttributes(this.tbLinkFormatHelper.getResourceDescription(server,
this.tbLinkFormatHelper.getResourceDescription(this, path.getObjectInstanceId(), path.getResourceId(), null), this, path.getObjectInstanceId(), path.getResourceId(), null), server);
server); return DiscoverResponse.success(resourceLink);
return DiscoverResponse.success(new LwM2mLink[] { resourceLink });
} }
return DiscoverResponse.badRequest(null); return DiscoverResponse.badRequest(null);
} }
private LwM2mLink[] linkUpdateAttributes(LwM2mLink[] links, LwM2mServer server) { private LwM2mLink[] linkAddUpdateAttributes(LwM2mLink[] links, LwM2mServer server) {
return Arrays.stream(links) ArrayList<LwM2mLink> resourceLinkList = new ArrayList<>();
.map(link -> linkAddAttribute(link, server)) for (LwM2mLink link : links) {
.toArray(LwM2mLink[]::new);
}
private LwM2mLink linkAddAttribute(LwM2mLink link, LwM2mServer server) {
LwM2mAttributeSet lwM2mAttributeSetDop = null; LwM2mAttributeSet lwM2mAttributeSetDop = null;
if (this.lwM2mAttributes.get(link.getPath()) != null) { if (this.lwM2mAttributes.get(link.getPath()) != null) {
@ -702,7 +697,9 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
if (resourceAttributeDim != null) { if (resourceAttributeDim != null) {
attributes.put(resourceAttributeDim.getName(), resourceAttributeDim); attributes.put(resourceAttributeDim.getName(), resourceAttributeDim);
} }
return new LwM2mLink(link.getRootPath(), link.getPath(), attributes.values()); resourceLinkList.add(new LwM2mLink(link.getRootPath(), link.getPath(), attributes.values()));
}
return resourceLinkList.toArray(LwM2mLink[]::new);
} }
protected LwM2mAttribute getResourceAttributes(LwM2mServer server, LwM2mPath path) { protected LwM2mAttribute getResourceAttributes(LwM2mServer server, LwM2mPath path) {

View File

@ -49,6 +49,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
String actual = rpcActualResult.get("error").asText(); String actual = rpcActualResult.get("error").asText();
assertTrue(actual.equals(expected)); assertTrue(actual.equals(expected));
} }
/** /**
* WriteAttributes {"id":"/3_1.2/0/6","attributes":{"pmax":100, "pmin":10}} * WriteAttributes {"id":"/3_1.2/0/6","attributes":{"pmax":100, "pmin":10}}
* if not implemented: * if not implemented:
@ -114,7 +115,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
String expected = "</3/0/6>;dim=3"; String expected = "</3/0/6>;dim=3";
assertTrue(rpcActualResult.get("value").asText().equals(expected)); assertTrue(rpcActualResult.get("value").asText().contains(expected));
} }
@ -187,7 +188,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText());
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_7; expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_7;
expectedValue ="{\"gt\":50, \"lt\":42.2, \"st\":0.5}"; expectedValue = "{\"gt\":50.0, \"lt\":42.2, \"st\":0.5}";
actualResult = sendRPCExecuteWithValueById(expectedPath, expectedValue); actualResult = sendRPCExecuteWithValueById(expectedPath, expectedValue);
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText());
@ -196,20 +197,23 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
actualResult = sendDiscover(expectedPath); actualResult = sendDiscover(expectedPath);
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
// String expected = "</3>;ver=1.2,</3/0>;pmax=60,</3/0/0>,</3/0/1>,</3/0/2>,</3/0/3>,</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50.0,</3/0/8>,</3/0/9>,</3/0/10>,</3/0/11>;dim=1,</3/0/13>,</3/0/14>,</3/0/15>,</3/0/16>,</3/0/17>,</3/0/18>,</3/0/19>,</3/0/20>,</3/0/21>"; String actualValue = rpcActualResult.get("value").asText();
String expected = "</3>;ver=1.2,</3/0>;pmax=65"; String expected = "</3>;ver=1.2,</3/0>;pmax=65";
assertTrue(rpcActualResult.get("value").asText().contains(expected)); assertTrue(actualValue.contains(expected));
expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50.0"; expected = "</3/0/6>;dim=3";
assertTrue(rpcActualResult.get("value").asText().contains(expected)); assertTrue(actualValue.contains(expected));
expected = "</3/0/7>;st=0.5;lt=42.2;gt=50";
assertTrue(actualValue.contains(expected));
// ObjectInstanceId // ObjectInstanceId
expectedPath = objectInstanceIdVer_3; expectedPath = objectInstanceIdVer_3;
actualResult = sendDiscover(expectedPath); actualResult = sendDiscover(expectedPath);
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
actualValue = rpcActualResult.get("value").asText();
expected = "</3/0>;pmax=65"; expected = "</3/0>;pmax=65";
assertTrue(rpcActualResult.get("value").asText().contains(expected)); assertTrue(actualValue.contains(expected));
expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50.0"; expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50";
assertTrue(rpcActualResult.get("value").asText().contains(expected)); assertTrue(actualValue.contains(expected));
// ResourceId // ResourceId
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6; expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6;
actualResult = sendDiscover(expectedPath); actualResult = sendDiscover(expectedPath);
@ -221,7 +225,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
actualResult = sendDiscover(expectedPath); actualResult = sendDiscover(expectedPath);
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class); rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText()); assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
expected = "</3/0/7>;st=0.5;lt=42.2;gt=50.0"; expected = "</3/0/7>;st=0.5;lt=42.2;gt=50";
assertTrue(rpcActualResult.get("value").asText().contains(expected)); assertTrue(rpcActualResult.get("value").asText().contains(expected));
// ResourceInstanceId // ResourceInstanceId
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6 + "/1"; expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6 + "/1";

View File

@ -18,7 +18,7 @@ package org.thingsboard.server.transport.lwm2m.secure;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.DecoderException;
import org.eclipse.leshan.core.util.SecurityUtil; import org.eclipse.leshan.core.security.util.SecurityUtil;
import org.eclipse.leshan.server.security.SecurityInfo; import org.eclipse.leshan.server.security.SecurityInfo;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;

View File

@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.leshan.core.SecurityMode; import org.eclipse.leshan.core.SecurityMode;
import org.eclipse.leshan.core.util.SecurityUtil; import org.eclipse.leshan.core.security.util.SecurityUtil;
import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.ConstraintViolationException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.event.TransactionalEventListener; import org.springframework.transaction.event.TransactionalEventListener;

View File

@ -18,7 +18,7 @@ package org.thingsboard.server.dao.service.validator;
import com.google.protobuf.Descriptors; import com.google.protobuf.Descriptors;
import com.google.protobuf.DynamicMessage; import com.google.protobuf.DynamicMessage;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.leshan.core.util.SecurityUtil; import org.eclipse.leshan.core.security.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;

View File

@ -74,8 +74,8 @@
<fasterxml-classmate.version>1.7.0</fasterxml-classmate.version> <fasterxml-classmate.version>1.7.0</fasterxml-classmate.version>
<auth0-jwt.version>4.4.0</auth0-jwt.version> <auth0-jwt.version>4.4.0</auth0-jwt.version>
<json-schema-validator.version>2.2.14</json-schema-validator.version> <json-schema-validator.version>2.2.14</json-schema-validator.version>
<californium.version>3.11.0</californium.version> <californium.version>3.12.1</californium.version>
<leshan.version>2.0.0-M14</leshan.version> <leshan.version>2.0.0-M15</leshan.version>
<gson.version>2.10.1</gson.version> <gson.version>2.10.1</gson.version>
<freemarker.version>2.3.32</freemarker.version> <freemarker.version>2.3.32</freemarker.version>
<mail.version>2.0.1</mail.version> <mail.version>2.0.1</mail.version>