Browse Source

Merge branch 'master' into Lwm2m_Composite

pull/4791/head
nickAS21 5 years ago
parent
commit
83bfa14d58
  1. 27
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java
  2. 26
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2MUplinkMsgHandler.java
  3. 4
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

27
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java

@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
@Getter @Getter
@Value("${transport.lwm2m.security.key_store:}") @Value("${transport.lwm2m.security.key_store:}")
private String keyStorePathFile; private String keyStoreFilePath;
@Getter @Getter
@Setter @Setter
@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
public void init() { public void init() {
URI uri = null; URI uri = null;
try { try {
uri = Resources.getResource(keyStorePathFile).toURI(); InputStream keyStoreInputStream;
log.info("URI: {}", uri); File keyStoreFile = new File(keyStoreFilePath);
File keyStoreFile = new File(uri); if (keyStoreFile.exists()) {
InputStream inKeyStore = new FileInputStream(keyStoreFile); log.info("Reading key store from file {}", keyStoreFilePath);
keyStoreInputStream = new FileInputStream(keyStoreFile);
} else {
InputStream classPathStream = this.getClass().getClassLoader().getResourceAsStream(keyStoreFilePath);
if (classPathStream != null) {
log.info("Reading key store from class path {}", keyStoreFilePath);
keyStoreInputStream = classPathStream;
} else {
uri = Resources.getResource(keyStoreFilePath).toURI();
log.info("Reading key store from URI {}", keyStoreFilePath);
keyStoreInputStream = new FileInputStream(new File(uri));
}
}
keyStoreValue = KeyStore.getInstance(keyStoreType); keyStoreValue = KeyStore.getInstance(keyStoreType);
keyStoreValue.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray()); keyStoreValue.load(keyStoreInputStream, keyStorePassword == null ? null : keyStorePassword.toCharArray());
} catch (Exception e) { } catch (Exception e) {
log.info("Unable to lookup LwM2M keystore. Reason: {}, {}" , uri, e.getMessage()); log.info("Unable to lookup LwM2M keystore. Reason: {}, {}", uri, e.getMessage());
} }
} }
} }

26
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2MUplinkMsgHandler.java

@ -372,20 +372,28 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
*/ */
@Override @Override
public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) { public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) {
List<LwM2mClient> clients = clientContext.getLwM2mClients() try {
.stream().filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList()); List<LwM2mClient> clients = clientContext.getLwM2mClients()
clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile)); .stream().filter(e -> e.getProfileId() != null)
if (clients.size() > 0) { .filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList());
this.onDeviceProfileUpdate(clients, deviceProfile); clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile));
if (clients.size() > 0) {
this.onDeviceProfileUpdate(clients, deviceProfile);
}
} catch (Exception e) {
log.warn("[{}] failed to update profile: {}", deviceProfile.getId(), deviceProfile);
} }
} }
@Override @Override
public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) { public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) {
//TODO: check, maybe device has multiple sessions/registrations? Is this possible according to the standard. try {
LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId()); LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId());
if (client != null) { if (client != null) {
this.onDeviceUpdate(client, device, deviceProfileOpt); this.onDeviceUpdate(client, device, deviceProfileOpt);
}
} catch (Exception e) {
log.warn("[{}] failed to update device: {}", device.getId(), device);
} }
} }

4
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

@ -210,7 +210,6 @@ public class DefaultTransportService implements TransportService {
} }
records.forEach(record -> { records.forEach(record -> {
try { try {
log.info("[{}] SessionIdMSB, [{}] SessionIdLSB, records", record.getValue().getSessionIdMSB(), record.getValue().getSessionIdLSB());
processToTransportMsg(record.getValue()); processToTransportMsg(record.getValue());
} catch (Throwable e) { } catch (Throwable e) {
log.warn("Failed to process the notification.", e); log.warn("Failed to process the notification.", e);
@ -771,6 +770,7 @@ public class DefaultTransportService implements TransportService {
UUID sessionId = new UUID(toSessionMsg.getSessionIdMSB(), toSessionMsg.getSessionIdLSB()); UUID sessionId = new UUID(toSessionMsg.getSessionIdMSB(), toSessionMsg.getSessionIdLSB());
SessionMetaData md = sessions.get(sessionId); SessionMetaData md = sessions.get(sessionId);
if (md != null) { if (md != null) {
log.trace("[{}] Processing notification: {}", sessionId, toSessionMsg);
SessionMsgListener listener = md.getListener(); SessionMsgListener listener = md.getListener();
transportCallbackExecutor.submit(() -> { transportCallbackExecutor.submit(() -> {
if (toSessionMsg.hasGetAttributesResponse()) { if (toSessionMsg.hasGetAttributesResponse()) {
@ -798,12 +798,14 @@ public class DefaultTransportService implements TransportService {
deregisterSession(md.getSessionInfo()); deregisterSession(md.getSessionInfo());
} }
} else { } else {
log.trace("Processing broadcast notification: {}", toSessionMsg);
if (toSessionMsg.hasEntityUpdateMsg()) { if (toSessionMsg.hasEntityUpdateMsg()) {
TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg(); TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg();
EntityType entityType = EntityType.valueOf(msg.getEntityType()); EntityType entityType = EntityType.valueOf(msg.getEntityType());
if (EntityType.DEVICE_PROFILE.equals(entityType)) { if (EntityType.DEVICE_PROFILE.equals(entityType)) {
DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData()); DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData());
if (deviceProfile != null) { if (deviceProfile != null) {
log.info("On device profile update: {}", deviceProfile);
onProfileUpdate(deviceProfile); onProfileUpdate(deviceProfile);
} }
} else if (EntityType.TENANT_PROFILE.equals(entityType)) { } else if (EntityType.TENANT_PROFILE.equals(entityType)) {

Loading…
Cancel
Save