lwm2m: update version: leshan = M15, californium = 3.12.1
This commit is contained in:
parent
f6eb2d922b
commit
8d6768009d
@ -49,13 +49,13 @@ public class LwM2mAttributesTest {
|
||||
@ParameterizedTest(name = "Tests {index} : {0}")
|
||||
@MethodSource("doesntSupportAttributesWithoutValue")
|
||||
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}")
|
||||
@MethodSource("doesntSupportAttributesWithValueNull")
|
||||
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 {
|
||||
|
||||
@ -69,7 +69,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -88,6 +87,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
|
||||
private LinkFormatHelper tbLinkFormatHelper;
|
||||
protected Map<LwM2mPath, LwM2mAttributeSet> lwM2mAttributes;
|
||||
|
||||
public TbLwm2mObjectEnabler(int id, ObjectModel objectModel, Map<Integer, LwM2mInstanceEnabler> instances,
|
||||
LwM2mInstanceEnablerFactory instanceFactory, ContentFormat defaultContentFormat) {
|
||||
super(id, objectModel);
|
||||
@ -586,10 +586,10 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
* - Less Than lt (def = -- ) Float Resource Numerical&Readable Resource
|
||||
* - Step st (def = -- ) Float Resource Numerical&Readable Resource
|
||||
*/
|
||||
public WriteAttributesResponse doWriteAttributes(LwM2mServer server, WriteAttributesRequest request) {
|
||||
public WriteAttributesResponse doWriteAttributes(LwM2mServer server, WriteAttributesRequest request) {
|
||||
LwM2mPath lwM2mPath = request.getPath();
|
||||
LwM2mAttributeSet attributeSet = lwM2mAttributes.get(lwM2mPath);
|
||||
Map <String, LwM2mAttribute<?>> attributes = new HashMap<>();
|
||||
Map<String, LwM2mAttribute<?>> attributes = new HashMap<>();
|
||||
|
||||
for (LwM2mAttribute attr : request.getAttributes().getLwM2mAttributes()) {
|
||||
if (attr.getName().equals("pmax") || attr.getName().equals("pmin")) {
|
||||
@ -606,12 +606,12 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attributes.size()>0){
|
||||
if (attributes.size() > 0) {
|
||||
if (attributeSet == null) {
|
||||
attributeSet = new LwM2mAttributeSet(attributes.values());
|
||||
} else {
|
||||
Iterable<LwM2mAttribute<?>> lwM2mAttributeIterable = attributeSet.getLwM2mAttributes();
|
||||
Map <String, LwM2mAttribute<?>> attributesOld = new HashMap<>();
|
||||
Map<String, LwM2mAttribute<?>> attributesOld = new HashMap<>();
|
||||
for (LwM2mAttribute<?> attr : lwM2mAttributeIterable) {
|
||||
attributesOld.put(attr.getName(), attr);
|
||||
}
|
||||
@ -643,7 +643,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
|
||||
LwM2mPath path = request.getPath();
|
||||
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);
|
||||
|
||||
} else if (path.isObjectInstance()) {
|
||||
@ -651,7 +651,7 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
if (!getAvailableInstanceIds().contains(path.getObjectInstanceId()))
|
||||
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);
|
||||
|
||||
} else if (path.isResource()) {
|
||||
@ -666,46 +666,43 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
if (!getAvailableResourceIds(path.getObjectInstanceId()).contains(path.getResourceId()))
|
||||
return DiscoverResponse.notFound();
|
||||
|
||||
LwM2mLink resourceLink = linkAddAttribute(
|
||||
this.tbLinkFormatHelper.getResourceDescription(this, path.getObjectInstanceId(), path.getResourceId(), null),
|
||||
server);
|
||||
return DiscoverResponse.success(new LwM2mLink[] { resourceLink });
|
||||
LwM2mLink[] resourceLink = linkAddUpdateAttributes(this.tbLinkFormatHelper.getResourceDescription(server,
|
||||
this, path.getObjectInstanceId(), path.getResourceId(), null), server);
|
||||
return DiscoverResponse.success(resourceLink);
|
||||
}
|
||||
return DiscoverResponse.badRequest(null);
|
||||
}
|
||||
|
||||
private LwM2mLink[] linkUpdateAttributes(LwM2mLink[] links, LwM2mServer server) {
|
||||
return Arrays.stream(links)
|
||||
.map(link -> linkAddAttribute(link, server))
|
||||
.toArray(LwM2mLink[]::new);
|
||||
private LwM2mLink[] linkAddUpdateAttributes(LwM2mLink[] links, LwM2mServer server) {
|
||||
ArrayList<LwM2mLink> resourceLinkList = new ArrayList<>();
|
||||
for (LwM2mLink link : links) {
|
||||
|
||||
LwM2mAttributeSet lwM2mAttributeSetDop = null;
|
||||
if (this.lwM2mAttributes.get(link.getPath()) != null) {
|
||||
lwM2mAttributeSetDop = this.lwM2mAttributes.get(link.getPath());
|
||||
}
|
||||
LwM2mAttribute resourceAttributeDim = getResourceAttributes(server, link.getPath());
|
||||
|
||||
Map<String, LwM2mAttribute<?>> attributes = new HashMap<>();
|
||||
if (link.getAttributes() != null) {
|
||||
for (LwM2mAttribute attr : link.getAttributes().getLwM2mAttributes()) {
|
||||
attributes.put(attr.getName(), attr);
|
||||
}
|
||||
}
|
||||
if (lwM2mAttributeSetDop != null) {
|
||||
for (LwM2mAttribute attr : lwM2mAttributeSetDop.getLwM2mAttributes()) {
|
||||
attributes.put(attr.getName(), attr);
|
||||
}
|
||||
}
|
||||
if (resourceAttributeDim != null) {
|
||||
attributes.put(resourceAttributeDim.getName(), resourceAttributeDim);
|
||||
}
|
||||
resourceLinkList.add(new LwM2mLink(link.getRootPath(), link.getPath(), attributes.values()));
|
||||
}
|
||||
return resourceLinkList.toArray(LwM2mLink[]::new);
|
||||
}
|
||||
|
||||
private LwM2mLink linkAddAttribute(LwM2mLink link, LwM2mServer server) {
|
||||
|
||||
LwM2mAttributeSet lwM2mAttributeSetDop = null;
|
||||
if (this.lwM2mAttributes.get(link.getPath())!= null){
|
||||
lwM2mAttributeSetDop = this.lwM2mAttributes.get(link.getPath());
|
||||
}
|
||||
LwM2mAttribute resourceAttributeDim = getResourceAttributes (server, link.getPath());
|
||||
|
||||
Map <String, LwM2mAttribute<?>> attributes = new HashMap<>();
|
||||
if (link.getAttributes() != null) {
|
||||
for (LwM2mAttribute attr : link.getAttributes().getLwM2mAttributes()) {
|
||||
attributes.put(attr.getName(), attr);
|
||||
}
|
||||
}
|
||||
if (lwM2mAttributeSetDop != null) {
|
||||
for (LwM2mAttribute attr : lwM2mAttributeSetDop.getLwM2mAttributes()) {
|
||||
attributes.put(attr.getName(), attr);
|
||||
}
|
||||
}
|
||||
if (resourceAttributeDim != null) {
|
||||
attributes.put(resourceAttributeDim.getName(), resourceAttributeDim);
|
||||
}
|
||||
return new LwM2mLink(link.getRootPath(), link.getPath(), attributes.values());
|
||||
}
|
||||
|
||||
protected LwM2mAttribute getResourceAttributes (LwM2mServer server, LwM2mPath path) {
|
||||
protected LwM2mAttribute getResourceAttributes(LwM2mServer server, LwM2mPath path) {
|
||||
ResourceModel resourceModel = getObjectModel().resources.get(path.getResourceId());
|
||||
if (path.isResource() && resourceModel.multiple) {
|
||||
return getResourceAttributeDim(path, server);
|
||||
@ -717,13 +714,13 @@ public class TbLwm2mObjectEnabler extends BaseObjectEnabler implements Destroyab
|
||||
LwM2mInstanceEnabler instance = instances.get(path.getObjectInstanceId());
|
||||
try {
|
||||
ReadResponse readResponse = instance.read(server, path.getResourceId());
|
||||
if (readResponse.getCode().getCode()==205 && readResponse.getContent() instanceof LwM2mMultipleResource) {
|
||||
long valueDim = ((LwM2mMultipleResource)readResponse.getContent()).getInstances().size();
|
||||
if (readResponse.getCode().getCode() == 205 && readResponse.getContent() instanceof LwM2mMultipleResource) {
|
||||
long valueDim = ((LwM2mMultipleResource) readResponse.getContent()).getInstances().size();
|
||||
return LwM2mAttributes.create(LwM2mAttributes.DIMENSION, valueDim);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e ){
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
String actual = rpcActualResult.get("error").asText();
|
||||
assertTrue(actual.equals(expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* WriteAttributes {"id":"/3_1.2/0/6","attributes":{"pmax":100, "pmin":10}}
|
||||
* if not implemented:
|
||||
@ -82,7 +83,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
|
||||
@Test
|
||||
public void testWriteAttributesResourceServerUriWithParametersById_Result_BAD_REQUEST() throws Exception {
|
||||
String expectedPath = objectInstanceIdVer_1;
|
||||
String expectedPath = objectInstanceIdVer_1;
|
||||
String actualResult = sendRPCReadById(expectedPath);
|
||||
String expectedValue = "{\"uri\":\"coaps://localhost:5690\"}";
|
||||
actualResult = sendRPCExecuteWithValueById(expectedPath, expectedValue);
|
||||
@ -108,13 +109,13 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
* "ver" only for objectId
|
||||
*/
|
||||
@Test
|
||||
public void testReadDIM_3_0_6_Only_R () throws Exception {
|
||||
public void testReadDIM_3_0_6_Only_R() throws Exception {
|
||||
String path = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6;
|
||||
String actualResult = sendDiscover(path);
|
||||
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
|
||||
String expected = "</3/0/6>;dim=3";
|
||||
assertTrue(rpcActualResult.get("value").asText().equals(expected));
|
||||
assertTrue(rpcActualResult.get("value").asText().contains(expected));
|
||||
|
||||
}
|
||||
|
||||
@ -126,7 +127,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
* "ver" only for objectId
|
||||
*/
|
||||
@Test
|
||||
public void testReadVer () throws Exception {
|
||||
public void testReadVer() throws Exception {
|
||||
String path = objectIdVer_3;
|
||||
String actualResult = sendDiscover(path);
|
||||
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
@ -149,7 +150,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
String actualResult = sendRPCExecuteWithValueById(expectedPath, expectedValue);
|
||||
ObjectNode rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText());
|
||||
// result changed
|
||||
// result changed
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
|
||||
@ -175,7 +176,7 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
* <3/0/6>;dim=8,<3/0/7>;gt=50;lt=42.2;st=0.5,<3/0/8>;...
|
||||
*/
|
||||
@Test
|
||||
public void testWriteAttributesPeriodLtGt () throws Exception {
|
||||
public void testWriteAttributesPeriodLtGt() throws Exception {
|
||||
String expectedPath = objectInstanceIdVer_3;
|
||||
String expectedValue = "{\"pmax\":60}";
|
||||
String actualResult = sendRPCExecuteWithValueById(expectedPath, expectedValue);
|
||||
@ -187,30 +188,33 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText());
|
||||
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);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CHANGED.getName(), rpcActualResult.get("result").asText());
|
||||
// ObjectId
|
||||
// ObjectId
|
||||
expectedPath = objectIdVer_3;
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
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";
|
||||
assertTrue(rpcActualResult.get("value").asText().contains(expected));
|
||||
expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50.0";
|
||||
assertTrue(rpcActualResult.get("value").asText().contains(expected));
|
||||
// ObjectInstanceId
|
||||
assertTrue(actualValue.contains(expected));
|
||||
expected = "</3/0/6>;dim=3";
|
||||
assertTrue(actualValue.contains(expected));
|
||||
expected = "</3/0/7>;st=0.5;lt=42.2;gt=50";
|
||||
assertTrue(actualValue.contains(expected));
|
||||
// ObjectInstanceId
|
||||
expectedPath = objectInstanceIdVer_3;
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.CONTENT.getName(), rpcActualResult.get("result").asText());
|
||||
actualValue = rpcActualResult.get("value").asText();
|
||||
expected = "</3/0>;pmax=65";
|
||||
assertTrue(rpcActualResult.get("value").asText().contains(expected));
|
||||
expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50.0";
|
||||
assertTrue(rpcActualResult.get("value").asText().contains(expected));
|
||||
// ResourceId
|
||||
assertTrue(actualValue.contains(expected));
|
||||
expected = "</3/0/6>;dim=3,</3/0/7>;st=0.5;lt=42.2;gt=50";
|
||||
assertTrue(actualValue.contains(expected));
|
||||
// ResourceId
|
||||
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6;
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
@ -221,10 +225,10 @@ public class RpcLwm2mIntegrationDiscoverWriteAttributesTest extends AbstractRpcL
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
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));
|
||||
// ResourceInstanceId
|
||||
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6+ "/1";
|
||||
// ResourceInstanceId
|
||||
expectedPath = objectInstanceIdVer_3 + "/" + RESOURCE_ID_6 + "/1";
|
||||
actualResult = sendDiscover(expectedPath);
|
||||
rpcActualResult = JacksonUtil.fromString(actualResult, ObjectNode.class);
|
||||
assertEquals(ResponseCode.INTERNAL_SERVER_ERROR.getName(), rpcActualResult.get("result").asText());
|
||||
|
||||
@ -18,7 +18,7 @@ package org.thingsboard.server.transport.lwm2m.secure;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.springframework.stereotype.Component;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
|
||||
@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.event.TransactionalEventListener;
|
||||
|
||||
@ -18,7 +18,7 @@ package org.thingsboard.server.dao.service.validator;
|
||||
import com.google.protobuf.Descriptors;
|
||||
import com.google.protobuf.DynamicMessage;
|
||||
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.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
4
pom.xml
4
pom.xml
@ -74,8 +74,8 @@
|
||||
<fasterxml-classmate.version>1.7.0</fasterxml-classmate.version>
|
||||
<auth0-jwt.version>4.4.0</auth0-jwt.version>
|
||||
<json-schema-validator.version>2.2.14</json-schema-validator.version>
|
||||
<californium.version>3.11.0</californium.version>
|
||||
<leshan.version>2.0.0-M14</leshan.version>
|
||||
<californium.version>3.12.1</californium.version>
|
||||
<leshan.version>2.0.0-M15</leshan.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<freemarker.version>2.3.32</freemarker.version>
|
||||
<mail.version>2.0.1</mail.version>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user