Commit 4ac52b10d8d041611d62ee38fb69c4e45b4f5350
1 parent
b04949c6
fixed sessions updating on lwm2m transport start
Showing
3 changed files
with
13 additions
and
7 deletions
... | ... | @@ -17,7 +17,6 @@ package org.thingsboard.server.transport.lwm2m.server; |
17 | 17 | |
18 | 18 | import lombok.RequiredArgsConstructor; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | -import org.eclipse.californium.elements.util.SslContextUtil; | |
21 | 20 | import org.eclipse.californium.scandium.config.DtlsConnectorConfig; |
22 | 21 | import org.eclipse.californium.scandium.dtls.cipher.CipherSuite; |
23 | 22 | import org.eclipse.leshan.core.node.codec.DefaultLwM2mNodeDecoder; |
... | ... | @@ -29,6 +28,7 @@ import org.springframework.stereotype.Component; |
29 | 28 | import org.thingsboard.server.cache.ota.OtaPackageDataCache; |
30 | 29 | import org.thingsboard.server.common.data.DataConstants; |
31 | 30 | import org.thingsboard.server.common.transport.config.ssl.SslCredentials; |
31 | +import org.thingsboard.server.queue.util.AfterStartUp; | |
32 | 32 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
33 | 33 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
34 | 34 | import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MAuthorizer; |
... | ... | @@ -37,10 +37,7 @@ import org.thingsboard.server.transport.lwm2m.server.store.TbSecurityStore; |
37 | 37 | import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2MUplinkMsgHandler; |
38 | 38 | import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; |
39 | 39 | |
40 | -import javax.annotation.PostConstruct; | |
41 | 40 | import javax.annotation.PreDestroy; |
42 | -import java.security.PrivateKey; | |
43 | -import java.security.PublicKey; | |
44 | 41 | import java.security.cert.X509Certificate; |
45 | 42 | |
46 | 43 | import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256; |
... | ... | @@ -71,7 +68,7 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService { |
71 | 68 | |
72 | 69 | private LeshanServer server; |
73 | 70 | |
74 | - @PostConstruct | |
71 | + @AfterStartUp | |
75 | 72 | public void init() { |
76 | 73 | this.server = getLhServer(); |
77 | 74 | /* | ... | ... |
... | ... | @@ -22,7 +22,10 @@ import org.eclipse.leshan.core.model.ResourceModel; |
22 | 22 | import org.eclipse.leshan.core.node.LwM2mPath; |
23 | 23 | import org.eclipse.leshan.server.registration.Registration; |
24 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | +import org.springframework.boot.context.event.ApplicationReadyEvent; | |
25 | 26 | import org.springframework.context.annotation.Lazy; |
27 | +import org.springframework.context.event.EventListener; | |
28 | +import org.springframework.core.annotation.Order; | |
26 | 29 | import org.springframework.stereotype.Service; |
27 | 30 | import org.thingsboard.server.common.data.DeviceProfile; |
28 | 31 | import org.thingsboard.server.common.data.device.data.PowerMode; |
... | ... | @@ -33,7 +36,6 @@ import org.thingsboard.server.common.transport.TransportDeviceProfileCache; |
33 | 36 | import org.thingsboard.server.common.transport.TransportServiceCallback; |
34 | 37 | import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse; |
35 | 38 | import org.thingsboard.server.gen.transport.TransportProtos; |
36 | -import org.thingsboard.server.queue.util.AfterStartUp; | |
37 | 39 | import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
38 | 40 | import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
39 | 41 | import org.thingsboard.server.transport.lwm2m.config.LwM2mVersion; |
... | ... | @@ -88,7 +90,8 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { |
88 | 90 | private final Map<String, LwM2mClient> lwM2mClientsByRegistrationId = new ConcurrentHashMap<>(); |
89 | 91 | private final Map<UUID, Lwm2mDeviceProfileTransportConfiguration> profiles = new ConcurrentHashMap<>(); |
90 | 92 | |
91 | - @AfterStartUp | |
93 | + @EventListener(ApplicationReadyEvent.class) | |
94 | + @Order(Integer.MAX_VALUE - 1) | |
92 | 95 | public void init() { |
93 | 96 | String nodeId = context.getNodeId(); |
94 | 97 | Set<LwM2mClient> fetchedClients = clientStore.getAll(); | ... | ... |
... | ... | @@ -87,6 +87,12 @@ public class DefaultLwM2MRpcRequestHandler implements LwM2MRpcRequestHandler { |
87 | 87 | return; |
88 | 88 | } |
89 | 89 | LwM2mClient client = clientContext.getClientBySessionInfo(sessionInfo); |
90 | + | |
91 | + if (client == null) { | |
92 | + log.warn("Missing client for session: [{}]", sessionInfo); | |
93 | + return; | |
94 | + } | |
95 | + | |
90 | 96 | if (client.getRegistration() == null) { |
91 | 97 | this.sendErrorRpcResponse(sessionInfo, rpcRequest.getRequestId(), ResponseCode.INTERNAL_SERVER_ERROR, "Registration is empty"); |
92 | 98 | return; | ... | ... |