Browse Source

lwm2m refactoring

pull/5583/head
YevhenBondarenko 5 years ago
parent
commit
a4c9f8e78e
  1. 4
      application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java
  2. 65
      application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java
  3. 2
      common/queue/src/main/java/org/thingsboard/server/queue/util/TbLwM2mBootstrapTransportComponent.java
  4. 2
      common/queue/src/main/java/org/thingsboard/server/queue/util/TbLwM2mTransportComponent.java
  5. 4
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2mDefaultBootstrapSessionManager.java
  6. 30
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MBootstrapConfigStoreTaskProvider.java
  7. 3
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MBootstrapSecurityStore.java
  8. 1
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MInMemoryBootstrapConfigStore.java
  9. 6
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java
  10. 3
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/ResourceValue.java
  11. 20
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/downlink/TbLwM2MReadCallback.java
  12. 1
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/rpc/DefaultLwM2MRpcRequestHandler.java
  13. 30
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2mUplinkMsgHandler.java
  14. 2
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2MTransportUtil.java
  15. 2
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/config/ssl/AbstractSslCredentials.java
  16. 5
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/util/JsonUtils.java

4
application/src/main/java/org/thingsboard/server/service/install/update/DefaultCacheCleanupService.java

@ -59,7 +59,9 @@ public class DefaultCacheCleanupService implements CacheCleanupService {
break;
case "3.3.2":
log.info("Clear cache to upgrade from version 3.3.2 to 3.3.3 ...");
clearAllCaches();
clearCacheByName("devices");
clearCacheByName("deviceProfiles");
clearCacheByName("tenantProfiles");
break;
default:
//Do nothing, since cache cleanup is optional.

65
application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java

@ -35,8 +35,8 @@ import org.thingsboard.server.common.data.TbResource;
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials;
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredential;
import org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials;
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredential;
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecBootstrapClientCredential;
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredential;
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.device.profile.DisabledDeviceProfileProvisionConfiguration;
@ -57,6 +57,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd;
import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate;
import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
@ -141,7 +142,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
this.defaultBootstrapCredentials.setLwm2mServer(serverCredentials);
}
public void init () throws Exception{
public void init () throws Exception{
executor = Executors.newScheduledThreadPool(10, ThingsBoardThreadFactory.forName("test-lwm2m-scheduled"));
loginTenantAdmin();
@ -167,46 +168,46 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
@After
public void after() {
executor.shutdownNow();
wsClient.close();
clientDestroy();
executor.shutdownNow();
}
public void basicTestConnectionObserveTelemetry(Security security,
LwM2MClientCredential credentials,
NetworkConfig coapConfig,
String endpoint) throws Exception {
createDeviceProfile(transportConfiguration);
Device device = createDevice(credentials);
createDeviceProfile(transportConfiguration);
Device device = createDevice(credentials);
SingleEntityFilter sef = new SingleEntityFilter();
sef.setSingleEntity(device.getId());
LatestValueCmd latestCmd = new LatestValueCmd();
latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "batteryLevel")));
EntityDataQuery edq = new EntityDataQuery(sef, new EntityDataPageLink(1, 0, null, null),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
SingleEntityFilter sef = new SingleEntityFilter();
sef.setSingleEntity(device.getId());
LatestValueCmd latestCmd = new LatestValueCmd();
latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.TIME_SERIES, "batteryLevel")));
EntityDataQuery edq = new EntityDataQuery(sef, new EntityDataPageLink(1, 0, null, null),
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
wrapper.setEntityDataCmds(Collections.singletonList(cmd));
EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
wrapper.setEntityDataCmds(Collections.singletonList(cmd));
wsClient.send(mapper.writeValueAsString(wrapper));
wsClient.waitForReply();
wsClient.send(mapper.writeValueAsString(wrapper));
wsClient.waitForReply();
wsClient.registerWaitForUpdate();
this.endpoint = endpoint;
createNewClient (security, coapConfig, false);
String msg = wsClient.waitForUpdate();
wsClient.registerWaitForUpdate();
this.endpoint = endpoint;
createNewClient(security, coapConfig, false);
String msg = wsClient.waitForUpdate();
EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
Assert.assertEquals(1, update.getCmdId());
List<EntityData> eData = update.getUpdate();
Assert.assertNotNull(eData);
Assert.assertEquals(1, eData.size());
Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES));
var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("batteryLevel");
Assert.assertEquals(42, Long.parseLong(tsValue.getValue()));
EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
Assert.assertEquals(1, update.getCmdId());
List<EntityData> eData = update.getUpdate();
Assert.assertNotNull(eData);
Assert.assertEquals(1, eData.size());
Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES));
var tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("batteryLevel");
Assert.assertEquals(42, Long.parseLong(tsValue.getValue()));
}
protected void createDeviceProfile(String transportConfiguration) throws Exception {
@ -256,15 +257,15 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest
return clientCredentials;
}
public void setResources (String[] resources) {
public void setResources(String[] resources) {
this.resources = resources;
}
public void setEndpoint (String endpoint) {
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public void createNewClient (Security security, NetworkConfig coapConfig, boolean isRpc) throws Exception {
public void createNewClient(Security security, NetworkConfig coapConfig, boolean isRpc) throws Exception {
clientDestroy();
client = new LwM2MTestClient(this.executor, this.endpoint);
int clientPort = SocketUtils.findAvailableTcpPort();

2
common/queue/src/main/java/org/thingsboard/server/queue/util/TbLwM2mBootstrapTransportComponent.java

@ -21,6 +21,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' || '${service.type:}'=='monolith') && '${transport.lwm2m.enabled:false}'=='true' && '${transport.lwm2m.bootstrap.enabled:false}'=='true'")
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.lwm2m.enabled}'=='true')) && '${transport.lwm2m.bootstrap.enabled:false}'=='true'")
public @interface TbLwM2mBootstrapTransportComponent {
}

2
common/queue/src/main/java/org/thingsboard/server/queue/util/TbLwM2mTransportComponent.java

@ -21,6 +21,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' || '${service.type:}'=='monolith') && '${transport.lwm2m.enabled:false}'=='true'")
@ConditionalOnExpression("'${service.type:null}'=='tb-transport' || ('${service.type:null}'=='monolith' && '${transport.api_enabled:true}'=='true' && '${transport.lwm2m.enabled}'=='true')")
public @interface TbLwM2mTransportComponent {
}

4
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2mDefaultBootstrapSessionManager.java

@ -107,7 +107,9 @@ public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSession
@Override
public boolean hasConfigFor(BootstrapSession session) {
BootstrapTaskProvider.Tasks firstTasks = tasksProvider.getTasks(session, null);
if (firstTasks == null) return false;
if (firstTasks == null) {
return false;
}
initTasks(session, firstTasks);
return true;
}

30
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MBootstrapConfigStoreTaskProvider.java

@ -19,7 +19,11 @@ import lombok.extern.slf4j.Slf4j;
import org.eclipse.leshan.core.Link;
import org.eclipse.leshan.core.node.LwM2mObject;
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.request.*;
import org.eclipse.leshan.core.request.BootstrapDeleteRequest;
import org.eclipse.leshan.core.request.BootstrapDiscoverRequest;
import org.eclipse.leshan.core.request.BootstrapDownlinkRequest;
import org.eclipse.leshan.core.request.BootstrapReadRequest;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.response.BootstrapDiscoverResponse;
import org.eclipse.leshan.core.response.BootstrapReadResponse;
import org.eclipse.leshan.core.response.LwM2mResponse;
@ -29,10 +33,15 @@ import org.eclipse.leshan.server.bootstrap.BootstrapSession;
import org.eclipse.leshan.server.bootstrap.BootstrapTaskProvider;
import org.eclipse.leshan.server.bootstrap.BootstrapUtil;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.eclipse.leshan.server.bootstrap.BootstrapUtil.toWriteRequest;
@ -57,7 +66,6 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
@Override
public Tasks getTasks(BootstrapSession session, List<LwM2mResponse> previousResponse) {
BootstrapConfig config = store.get(session.getEndpoint(), session.getIdentity(), session);
if (config == null) {
return null;
@ -72,7 +80,6 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
Tasks tasks = new Tasks();
if (this.supportedObjects == null) {
initSupportedObjectsDefault();
}
// add supportedObjects
tasks.supportedObjects = this.supportedObjects;
@ -114,7 +121,6 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
// create requests from config
tasks.requestsToSend = BootstrapUtil.toRequests(config,
config.contentFormat != null ? config.contentFormat : session.getContentFormat());
}
return tasks;
}
@ -133,18 +139,18 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
LwM2mPath path = new LwM2mPath(link.getUrl());
if (path.isObjectInstance()) {
if (link.getAttributes().containsKey("ssid")) {
int serverId = Integer.valueOf(link.getAttributes().get("ssid"));
int serverId = Integer.parseInt(link.getAttributes().get("ssid"));
if (!this.securityInstances.containsKey(serverId)) {
this.securityInstances.put(serverId, path.getObjectInstanceId());
} else {
log.error(String.format("Invalid lwm2mSecurityInstance by [{}]", path.getObjectInstanceId()));
log.error("Invalid lwm2mSecurityInstance by [{}]", path.getObjectInstanceId());
}
this.securityInstances.put(Integer.valueOf(link.getAttributes().get("ssid")), path.getObjectInstanceId());
} else {
if (!this.securityInstances.containsKey(0)) {
this.securityInstances.put(0, path.getObjectInstanceId());
} else {
log.error(String.format("Invalid bootstrapSecurityInstance by [{}]", path.getObjectInstanceId()));
log.error("Invalid bootstrapSecurityInstance by [{}]", path.getObjectInstanceId());
}
}
}
@ -183,7 +189,7 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
Link[] links = response.getObjectLinks();
Arrays.stream(links).forEach(link -> {
LwM2mPath path = new LwM2mPath(link.getUrl());
if (path != null && !path.isRoot() && path.getObjectId() < 3) {
if (!path.isRoot() && path.getObjectId() < 3) {
if (path.isObject()) {
String ver = link.getAttributes().get("ver") != null ? link.getAttributes().get("ver") : "1.0";
this.supportedObjects.put(path.getObjectId(), ver);
@ -256,7 +262,7 @@ public class LwM2MBootstrapConfigStoreTaskProvider implements BootstrapTaskProvi
requestsWrite.add(toWriteRequest(acl.getKey(), acl.getValue(), contentFormat));
}
// handle delete
if (isBsServer & isLwServer) {
if (isBsServer && isLwServer) {
requests.add(new BootstrapDeleteRequest("/0"));
requests.add(new BootstrapDeleteRequest("/1"));
} else {

3
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MBootstrapSecurityStore.java

@ -68,7 +68,6 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
@Override
public Iterator<SecurityInfo> getAllByEndpoint(String endPoint) {
// TODO
TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(endPoint, BOOTSTRAP);
if (store.getBootstrapCredentialConfig() != null) {
/* add value to store from BootstrapJson */
@ -79,7 +78,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
try {
boolean bootstrapServerUpdateEnable = ((Lwm2mDeviceProfileTransportConfiguration)store.getDeviceProfile().getProfileData().getTransportConfiguration()).isBootstrapServerUpdateEnable();
if (!bootstrapServerUpdateEnable) {
Optional<Map.Entry<Integer, BootstrapConfig.ServerSecurity>> securities = bsConfigNew.security.entrySet().stream().filter(sec -> ((BootstrapConfig.ServerSecurity)sec.getValue()).bootstrapServer==true).findAny();
Optional<Map.Entry<Integer, BootstrapConfig.ServerSecurity>> securities = bsConfigNew.security.entrySet().stream().filter(sec -> sec.getValue().bootstrapServer).findAny();
if (securities.isPresent()) {
bsConfigNew.security.entrySet().remove(securities.get());
int serverSortId = securities.get().getValue().serverId;

1
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/store/LwM2MInMemoryBootstrapConfigStore.java

@ -75,7 +75,6 @@ public class LwM2MInMemoryBootstrapConfigStore extends InMemoryBootstrapConfigSt
}
public void addToStore(String endpoint, BootstrapConfig config) throws InvalidConfigurationException {
configChecker.verify(config);
// Check PSK identity uniqueness for bootstrap server:
PskByServer pskToAdd = getBootstrapPskIdentity(config);

6
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java

@ -330,7 +330,7 @@ public class LwM2mClient implements Serializable {
Collection<LwM2mResource> resources = ConcurrentHashMap.newKeySet();
Map<Integer, ResourceModel> resourceModels = modelProvider.getObjectModel(registration)
.getObjectModel(pathIds.getObjectId()).resources;
if (params != null && params instanceof Map && ((Map<?, ?>) params).size() > 0) {
if (params instanceof Map && ((Map) params).size() > 0) {
Map paramsMap = (Map) params;
resourceModels.forEach((resourceId, resourceModel) -> {
if (paramsMap.containsKey(String.valueOf(resourceId))) {
@ -338,8 +338,8 @@ public class LwM2mClient implements Serializable {
LwM2mResource resource;
if (resourceModel.multiple) {
try {
Map values = convertMultiResourceValuesFromRpcBody(value, resourceModel.type, pathRezIdVer);
resource = LwM2mMultipleResource.newResource(resourceId, (Map<Integer, ?>) values, resourceModel.type);
Map<Integer, Object> values = convertMultiResourceValuesFromRpcBody(value, resourceModel.type, pathRezIdVer);
resource = LwM2mMultipleResource.newResource(resourceId, values, resourceModel.type);
} catch (Exception e) {
throw new IllegalArgumentException("Resource id=" + resourceId + ", class = " +
value.getClass().getSimpleName() + ", value = " + value + " is bad. Value of Multi-Instance Resource must be in Json format!");

3
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/ResourceValue.java

@ -46,14 +46,13 @@ public class ResourceValue implements Serializable {
public void updateLwM2mResource(LwM2mResource lwM2mResource, Mode mode) {
if (lwM2mResource instanceof LwM2mSingleResource) {
this.lwM2mResource = new TbLwM2MSingleResource(lwM2mResource.getId(), lwM2mResource.getValue(), lwM2mResource.getType());
} else if (lwM2mResource instanceof LwM2mMultipleResource) {
if (lwM2mResource.getInstances().values().size() > 0) {
Set <TbLwM2MResourceInstance> instancesSet = lwM2mResource.getInstances().values().stream().map(ResourceValue::toTbLwM2MResourceInstance).collect(Collectors.toSet());
if (Mode.REPLACE.equals(mode) && this.lwM2mResource != null) {
Map<Integer, LwM2mResourceInstance> oldInstances = this.lwM2mResource.getInstances();
oldInstances.values().forEach(v -> {
if (instancesSet.stream().filter(vIns -> v.getId() == vIns.getId()).collect(Collectors.toList()).size() == 0){
if (instancesSet.stream().noneMatch(vIns -> v.getId() == vIns.getId())){
instancesSet.add(toTbLwM2MResourceInstance(v));
}
});

20
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/downlink/TbLwM2MReadCallback.java

@ -16,6 +16,7 @@
package org.thingsboard.server.transport.lwm2m.server.downlink;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.leshan.core.model.ResourceModel;
import org.eclipse.leshan.core.node.LwM2mSingleResource;
import org.eclipse.leshan.core.request.ReadRequest;
import org.eclipse.leshan.core.response.ReadResponse;
@ -33,26 +34,25 @@ public class TbLwM2MReadCallback extends TbLwM2MUplinkTargetedCallback<ReadReque
@Override
public void onSuccess(ReadRequest request, ReadResponse response) {
logForBadResponse(response.getCode().getCode(), responseToString (response), request.getClass().getSimpleName());
logForBadResponse(response.getCode().getCode(), responseToString(response), request.getClass().getSimpleName());
super.onSuccess(request, response);
handler.onUpdateValueAfterReadResponse(client.getRegistration(), versionedId, response);
}
private String responseToString (ReadResponse response) {
private String responseToString(ReadResponse response) {
if (response.getContent() instanceof LwM2mSingleResource) {
if (((LwM2mSingleResource) response.getContent()).getType().name().equals("OPAQUE")) {
if (((byte[])((LwM2mSingleResource) response.getContent()).getValue()).length > 0) {
int len = ((byte[])((LwM2mSingleResource) response.getContent()).getValue()).length;
LwM2mSingleResource singleResource = (LwM2mSingleResource) response.getContent();
if (ResourceModel.Type.OPAQUE.equals(singleResource.getType())) {
byte[] valueInBytes = (byte[]) singleResource.getValue();
int len = valueInBytes.length;
if (len > 0) {
String valueReplace = len + "Bytes";
String valueStr = Hex.encodeHexString((byte[]) (((LwM2mSingleResource) response.getContent()).getValue()));
String valueStr = Hex.encodeHexString(valueInBytes);
return response.toString().replace(valueReplace, valueStr);
}
}
return response.toString();
}
else {
return response.toString();
}
return response.toString();
}
}

1
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/rpc/DefaultLwM2MRpcRequestHandler.java

@ -86,7 +86,6 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler {
private final TransportService transportService;
private final LwM2mClientContext clientContext;
private final LwM2MTransportServerConfig config;
private final LwM2mUplinkMsgHandler uplinkHandler;
private final LwM2mDownlinkMsgHandler downlinkHandler;
private final LwM2MTelemetryLogService logService;

30
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2mUplinkMsgHandler.java

@ -25,6 +25,7 @@ import org.eclipse.leshan.core.ResponseCode;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.model.ResourceModel;
import org.eclipse.leshan.core.node.LwM2mMultipleResource;
import org.eclipse.leshan.core.node.LwM2mNode;
import org.eclipse.leshan.core.node.LwM2mObject;
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
import org.eclipse.leshan.core.node.LwM2mPath;
@ -329,19 +330,21 @@ public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService impl
*/
@Override
public void onUpdateValueAfterReadResponse(Registration registration, String path, ReadResponse response) {
if (response.getContent() != null) {
LwM2mNode content = response.getContent();
if (content != null) {
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint());
ObjectModel objectModelVersion = lwM2MClient.getObjectModel(path, modelProvider);
if (objectModelVersion != null) {
if (response.getContent() instanceof LwM2mObject) {
LwM2mObject lwM2mObject = (LwM2mObject) response.getContent();
this.updateObjectResourceValue(lwM2MClient, lwM2mObject, path, response.getCode().getCode());
} else if (response.getContent() instanceof LwM2mObjectInstance) {
LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) response.getContent();
this.updateObjectInstanceResourceValue(lwM2MClient, lwM2mObjectInstance, path, response.getCode().getCode());
} else if (response.getContent() instanceof LwM2mResource) {
LwM2mResource lwM2mResource = (LwM2mResource) response.getContent();
this.updateResourcesValue(lwM2MClient, lwM2mResource, path, Mode.UPDATE, response.getCode().getCode());
int responseCode = response.getCode().getCode();
if (content instanceof LwM2mObject) {
LwM2mObject lwM2mObject = (LwM2mObject) content;
this.updateObjectResourceValue(lwM2MClient, lwM2mObject, path, responseCode);
} else if (content instanceof LwM2mObjectInstance) {
LwM2mObjectInstance lwM2mObjectInstance = (LwM2mObjectInstance) content;
this.updateObjectInstanceResourceValue(lwM2MClient, lwM2mObjectInstance, path, responseCode);
} else if (content instanceof LwM2mResource) {
LwM2mResource lwM2mResource = (LwM2mResource) content;
this.updateResourcesValue(lwM2MClient, lwM2mResource, path, Mode.UPDATE, responseCode);
}
}
if (clientContext.awake(lwM2MClient)) {
@ -359,12 +362,13 @@ public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService impl
LwM2mClient lwM2MClient = clientContext.getClientByEndpoint(registration.getEndpoint());
response.getContent().forEach((k, v) -> {
if (v != null) {
int responseCode = response.getCode().getCode();
if (v instanceof LwM2mObject) {
this.updateObjectResourceValue(lwM2MClient, (LwM2mObject) v, k.toString(), response.getCode().getCode());
this.updateObjectResourceValue(lwM2MClient, (LwM2mObject) v, k.toString(), responseCode);
} else if (v instanceof LwM2mObjectInstance) {
this.updateObjectInstanceResourceValue(lwM2MClient, (LwM2mObjectInstance) v, k.toString(), response.getCode().getCode());
this.updateObjectInstanceResourceValue(lwM2MClient, (LwM2mObjectInstance) v, k.toString(), responseCode);
} else if (v instanceof LwM2mResource) {
this.updateResourcesValue(lwM2MClient, (LwM2mResource) v, k.toString(), Mode.UPDATE, response.getCode().getCode());
this.updateResourcesValue(lwM2MClient, (LwM2mResource) v, k.toString(), Mode.UPDATE, responseCode);
}
}
});

2
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2MTransportUtil.java

@ -352,7 +352,7 @@ public class LwM2MTransportUtil {
}
public static Map<Integer, Object> convertMultiResourceValuesFromRpcBody(Object value, ResourceModel.Type type, String versionedId) throws Exception {
String valueJsonStr = JsonUtils.writeValueAsString(value);
String valueJsonStr = JacksonUtil.toString(value);
JsonElement element = JsonUtils.parse(valueJsonStr);
return convertMultiResourceValuesFromJson(element, type, versionedId);
}

2
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/config/ssl/AbstractSslCredentials.java

@ -115,7 +115,6 @@ public abstract class AbstractSslCredentials implements SslCredentials {
return this.trusts;
}
@Override
public TrustManagerFactory createTrustManagerFactory() throws NoSuchAlgorithmException, KeyStoreException {
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
@ -130,7 +129,6 @@ public abstract class AbstractSslCredentials implements SslCredentials {
return kmf;
}
@Override
public String getValueFromSubjectNameByKey(String subjectName, String key) {
String[] dns = subjectName.split(",");

5
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/util/JsonUtils.java

@ -15,7 +15,6 @@
*/
package org.thingsboard.server.common.transport.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -57,8 +56,4 @@ public class JsonUtils {
return jsonParser.parse(params);
}
public static String writeValueAsString(Object value) throws JsonProcessingException {
return json.writeValueAsString(value);
}
}

Loading…
Cancel
Save