From e3af72eb88cc15fd4bf6f8d36fa1140e01457913 Mon Sep 17 00:00:00 2001 From: YevhenBondarenko Date: Mon, 24 Jan 2022 17:54:28 +0200 Subject: [PATCH] Registration is not Serializable --- .../transport/lwm2m/server/client/LwM2mClient.java | 13 +++++++------ .../lwm2m/server/client/LwM2mClientContextImpl.java | 9 +++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java index 04b8f858c6..9b04efa646 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClient.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.extern.slf4j.Slf4j; +import org.eclipse.leshan.core.link.LinkParamValue; import org.eclipse.leshan.core.model.ObjectModel; import org.eclipse.leshan.core.model.ResourceModel; import org.eclipse.leshan.core.node.LwM2mMultipleResource; @@ -108,7 +109,7 @@ public class LwM2mClient implements Serializable { @Getter private Long edrxCycle; @Getter - private Registration registration; + private transient Registration registration; @Getter @Setter private boolean asleep; @@ -121,9 +122,9 @@ public class LwM2mClient implements Serializable { private boolean firstEdrxDownlink = true; @Getter - private Set clientSupportContentFormats; + private transient Set clientSupportContentFormats; @Getter - private ContentFormat defaultContentFormat; + private transient ContentFormat defaultContentFormat; @Getter private final AtomicInteger retryAttempts; @@ -430,9 +431,9 @@ public class LwM2mClient implements Serializable { static private Set clientSupportContentFormat(Registration registration) { Set contentFormats = new HashSet<>(); contentFormats.add(ContentFormat.DEFAULT); - String code = Arrays.stream(registration.getObjectLinks()).filter(link -> link.getUriReference().equals("/")).findFirst().get().getLinkParams().get("ct").getUnquoted(); - if (code != null) { - Set codes = Stream.of(code.replaceAll("\"", "").split(" ", -1)) + LinkParamValue ct = Arrays.stream(registration.getObjectLinks()).filter(link -> link.getUriReference().equals("/")).findFirst().get().getLinkParams().get("ct"); + if (ct != null) { + Set codes = Stream.of(ct.getUnquoted().replaceAll("\"", "").split(" ", -1)) .map(String::trim) .map(Integer::parseInt) .map(ContentFormat::fromCode) diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java index eb675c9461..a4c92de9b1 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.leshan.core.SecurityMode; import org.eclipse.leshan.core.node.LwM2mPath; import org.eclipse.leshan.server.registration.Registration; +import org.eclipse.leshan.server.registration.RegistrationStore; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -72,6 +73,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { private final LwM2MSessionManager sessionManager; private final TransportDeviceProfileCache deviceProfileCache; private final LwM2MModelConfigService modelConfigService; + private final RegistrationStore registrationStore; @Autowired @Lazy @@ -118,8 +120,11 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { private void updateFetchedClient(String nodeId, LwM2mClient client) { boolean updated = false; - if (client.getRegistration() != null) { - lwM2mClientsByRegistrationId.put(client.getRegistration().getId(), client); + Registration registration = registrationStore.getRegistrationByEndpoint(client.getEndpoint()); + + if (registration != null) { + client.setRegistration(registration); + lwM2mClientsByRegistrationId.put(registration.getId(), client); } if (client.getSession() != null) { client.refreshSessionId(nodeId);