Showing
3 changed files
with
40 additions
and
17 deletions
@@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { | @@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { | ||
78 | 78 | ||
79 | @Getter | 79 | @Getter |
80 | @Value("${transport.lwm2m.security.key_store:}") | 80 | @Value("${transport.lwm2m.security.key_store:}") |
81 | - private String keyStorePathFile; | 81 | + private String keyStoreFilePath; |
82 | 82 | ||
83 | @Getter | 83 | @Getter |
84 | @Setter | 84 | @Setter |
@@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { | @@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { | ||
141 | public void init() { | 141 | public void init() { |
142 | URI uri = null; | 142 | URI uri = null; |
143 | try { | 143 | try { |
144 | - uri = Resources.getResource(keyStorePathFile).toURI(); | ||
145 | - log.info("URI: {}", uri); | ||
146 | - File keyStoreFile = new File(uri); | ||
147 | - InputStream inKeyStore = new FileInputStream(keyStoreFile); | 144 | + InputStream keyStoreInputStream; |
145 | + File keyStoreFile = new File(keyStoreFilePath); | ||
146 | + if (keyStoreFile.exists()) { | ||
147 | + log.info("Reading key store from file {}", keyStoreFilePath); | ||
148 | + keyStoreInputStream = new FileInputStream(keyStoreFile); | ||
149 | + } else { | ||
150 | + InputStream classPathStream = this.getClass().getClassLoader().getResourceAsStream(keyStoreFilePath); | ||
151 | + if (classPathStream != null) { | ||
152 | + log.info("Reading key store from class path {}", keyStoreFilePath); | ||
153 | + keyStoreInputStream = classPathStream; | ||
154 | + } else { | ||
155 | + uri = Resources.getResource(keyStoreFilePath).toURI(); | ||
156 | + log.info("Reading key store from URI {}", keyStoreFilePath); | ||
157 | + keyStoreInputStream = new FileInputStream(new File(uri)); | ||
158 | + } | ||
159 | + } | ||
148 | keyStoreValue = KeyStore.getInstance(keyStoreType); | 160 | keyStoreValue = KeyStore.getInstance(keyStoreType); |
149 | - keyStoreValue.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray()); | 161 | + keyStoreValue.load(keyStoreInputStream, keyStorePassword == null ? null : keyStorePassword.toCharArray()); |
150 | } catch (Exception e) { | 162 | } catch (Exception e) { |
151 | - log.info("Unable to lookup LwM2M keystore. Reason: {}, {}" , uri, e.getMessage()); | 163 | + log.info("Unable to lookup LwM2M keystore. Reason: {}, {}", uri, e.getMessage()); |
152 | } | 164 | } |
153 | } | 165 | } |
166 | + | ||
154 | } | 167 | } |
@@ -372,20 +372,28 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl | @@ -372,20 +372,28 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl | ||
372 | */ | 372 | */ |
373 | @Override | 373 | @Override |
374 | public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { | 374 | public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { |
375 | - List<LwM2mClient> clients = clientContext.getLwM2mClients() | ||
376 | - .stream().filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList()); | ||
377 | - clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile)); | ||
378 | - if (clients.size() > 0) { | ||
379 | - this.onDeviceProfileUpdate(clients, deviceProfile); | 375 | + try { |
376 | + List<LwM2mClient> clients = clientContext.getLwM2mClients() | ||
377 | + .stream().filter(e -> e.getProfileId() != null) | ||
378 | + .filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList()); | ||
379 | + clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile)); | ||
380 | + if (clients.size() > 0) { | ||
381 | + this.onDeviceProfileUpdate(clients, deviceProfile); | ||
382 | + } | ||
383 | + } catch (Exception e) { | ||
384 | + log.warn("[{}] failed to update profile: {}", deviceProfile.getId(), deviceProfile); | ||
380 | } | 385 | } |
381 | } | 386 | } |
382 | 387 | ||
383 | @Override | 388 | @Override |
384 | public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) { | 389 | public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) { |
385 | - //TODO: check, maybe device has multiple sessions/registrations? Is this possible according to the standard. | ||
386 | - LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId()); | ||
387 | - if (client != null) { | ||
388 | - this.onDeviceUpdate(client, device, deviceProfileOpt); | 390 | + try { |
391 | + LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId()); | ||
392 | + if (client != null) { | ||
393 | + this.onDeviceUpdate(client, device, deviceProfileOpt); | ||
394 | + } | ||
395 | + } catch (Exception e) { | ||
396 | + log.warn("[{}] failed to update device: {}", device.getId(), device); | ||
389 | } | 397 | } |
390 | } | 398 | } |
391 | 399 |
@@ -210,7 +210,6 @@ public class DefaultTransportService implements TransportService { | @@ -210,7 +210,6 @@ public class DefaultTransportService implements TransportService { | ||
210 | } | 210 | } |
211 | records.forEach(record -> { | 211 | records.forEach(record -> { |
212 | try { | 212 | try { |
213 | - log.info("[{}] SessionIdMSB, [{}] SessionIdLSB, records", record.getValue().getSessionIdMSB(), record.getValue().getSessionIdLSB()); | ||
214 | processToTransportMsg(record.getValue()); | 213 | processToTransportMsg(record.getValue()); |
215 | } catch (Throwable e) { | 214 | } catch (Throwable e) { |
216 | log.warn("Failed to process the notification.", e); | 215 | log.warn("Failed to process the notification.", e); |
@@ -771,6 +770,7 @@ public class DefaultTransportService implements TransportService { | @@ -771,6 +770,7 @@ public class DefaultTransportService implements TransportService { | ||
771 | UUID sessionId = new UUID(toSessionMsg.getSessionIdMSB(), toSessionMsg.getSessionIdLSB()); | 770 | UUID sessionId = new UUID(toSessionMsg.getSessionIdMSB(), toSessionMsg.getSessionIdLSB()); |
772 | SessionMetaData md = sessions.get(sessionId); | 771 | SessionMetaData md = sessions.get(sessionId); |
773 | if (md != null) { | 772 | if (md != null) { |
773 | + log.trace("[{}] Processing notification: {}", sessionId, toSessionMsg); | ||
774 | SessionMsgListener listener = md.getListener(); | 774 | SessionMsgListener listener = md.getListener(); |
775 | transportCallbackExecutor.submit(() -> { | 775 | transportCallbackExecutor.submit(() -> { |
776 | if (toSessionMsg.hasGetAttributesResponse()) { | 776 | if (toSessionMsg.hasGetAttributesResponse()) { |
@@ -798,12 +798,14 @@ public class DefaultTransportService implements TransportService { | @@ -798,12 +798,14 @@ public class DefaultTransportService implements TransportService { | ||
798 | deregisterSession(md.getSessionInfo()); | 798 | deregisterSession(md.getSessionInfo()); |
799 | } | 799 | } |
800 | } else { | 800 | } else { |
801 | + log.trace("Processing broadcast notification: {}", toSessionMsg); | ||
801 | if (toSessionMsg.hasEntityUpdateMsg()) { | 802 | if (toSessionMsg.hasEntityUpdateMsg()) { |
802 | TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg(); | 803 | TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg(); |
803 | EntityType entityType = EntityType.valueOf(msg.getEntityType()); | 804 | EntityType entityType = EntityType.valueOf(msg.getEntityType()); |
804 | if (EntityType.DEVICE_PROFILE.equals(entityType)) { | 805 | if (EntityType.DEVICE_PROFILE.equals(entityType)) { |
805 | DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData()); | 806 | DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData()); |
806 | if (deviceProfile != null) { | 807 | if (deviceProfile != null) { |
808 | + log.info("On device profile update: {}", deviceProfile); | ||
807 | onProfileUpdate(deviceProfile); | 809 | onProfileUpdate(deviceProfile); |
808 | } | 810 | } |
809 | } else if (EntityType.TENANT_PROFILE.equals(entityType)) { | 811 | } else if (EntityType.TENANT_PROFILE.equals(entityType)) { |