Commit 83bfa14d584e05a9d9a9ad656fcaadb1b2084037

Authored by nickAS21
2 parents f9db5566 c500be4e

Merge branch 'master' into Lwm2m_Composite

... ... @@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
78 78
79 79 @Getter
80 80 @Value("${transport.lwm2m.security.key_store:}")
81   - private String keyStorePathFile;
  81 + private String keyStoreFilePath;
82 82
83 83 @Getter
84 84 @Setter
... ... @@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
141 141 public void init() {
142 142 URI uri = null;
143 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 160 keyStoreValue = KeyStore.getInstance(keyStoreType);
149   - keyStoreValue.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray());
  161 + keyStoreValue.load(keyStoreInputStream, keyStorePassword == null ? null : keyStorePassword.toCharArray());
150 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 372 */
373 373 @Override
374 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 388 @Override
384 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 210 }
211 211 records.forEach(record -> {
212 212 try {
213   - log.info("[{}] SessionIdMSB, [{}] SessionIdLSB, records", record.getValue().getSessionIdMSB(), record.getValue().getSessionIdLSB());
214 213 processToTransportMsg(record.getValue());
215 214 } catch (Throwable e) {
216 215 log.warn("Failed to process the notification.", e);
... ... @@ -771,6 +770,7 @@ public class DefaultTransportService implements TransportService {
771 770 UUID sessionId = new UUID(toSessionMsg.getSessionIdMSB(), toSessionMsg.getSessionIdLSB());
772 771 SessionMetaData md = sessions.get(sessionId);
773 772 if (md != null) {
  773 + log.trace("[{}] Processing notification: {}", sessionId, toSessionMsg);
774 774 SessionMsgListener listener = md.getListener();
775 775 transportCallbackExecutor.submit(() -> {
776 776 if (toSessionMsg.hasGetAttributesResponse()) {
... ... @@ -798,12 +798,14 @@ public class DefaultTransportService implements TransportService {
798 798 deregisterSession(md.getSessionInfo());
799 799 }
800 800 } else {
  801 + log.trace("Processing broadcast notification: {}", toSessionMsg);
801 802 if (toSessionMsg.hasEntityUpdateMsg()) {
802 803 TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg();
803 804 EntityType entityType = EntityType.valueOf(msg.getEntityType());
804 805 if (EntityType.DEVICE_PROFILE.equals(entityType)) {
805 806 DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData());
806 807 if (deviceProfile != null) {
  808 + log.info("On device profile update: {}", deviceProfile);
807 809 onProfileUpdate(deviceProfile);
808 810 }
809 811 } else if (EntityType.TENANT_PROFILE.equals(entityType)) {
... ...