Merge branch 'master' into Lwm2m_Composite
This commit is contained in:
commit
83bfa14d58
@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
|
||||
|
||||
@Getter
|
||||
@Value("${transport.lwm2m.security.key_store:}")
|
||||
private String keyStorePathFile;
|
||||
private String keyStoreFilePath;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
|
||||
public void init() {
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = Resources.getResource(keyStorePathFile).toURI();
|
||||
log.info("URI: {}", uri);
|
||||
File keyStoreFile = new File(uri);
|
||||
InputStream inKeyStore = new FileInputStream(keyStoreFile);
|
||||
InputStream keyStoreInputStream;
|
||||
File keyStoreFile = new File(keyStoreFilePath);
|
||||
if (keyStoreFile.exists()) {
|
||||
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.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray());
|
||||
keyStoreValue.load(keyStoreInputStream, keyStorePassword == null ? null : keyStorePassword.toCharArray());
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -372,20 +372,28 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
|
||||
*/
|
||||
@Override
|
||||
public void onDeviceProfileUpdate(SessionInfoProto sessionInfo, DeviceProfile deviceProfile) {
|
||||
List<LwM2mClient> clients = clientContext.getLwM2mClients()
|
||||
.stream().filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList());
|
||||
clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile));
|
||||
if (clients.size() > 0) {
|
||||
this.onDeviceProfileUpdate(clients, deviceProfile);
|
||||
try {
|
||||
List<LwM2mClient> clients = clientContext.getLwM2mClients()
|
||||
.stream().filter(e -> e.getProfileId() != null)
|
||||
.filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList());
|
||||
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
|
||||
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.
|
||||
LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId());
|
||||
if (client != null) {
|
||||
this.onDeviceUpdate(client, device, deviceProfileOpt);
|
||||
try {
|
||||
LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId());
|
||||
if (client != null) {
|
||||
this.onDeviceUpdate(client, device, deviceProfileOpt);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("[{}] failed to update device: {}", device.getId(), device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -210,7 +210,6 @@ public class DefaultTransportService implements TransportService {
|
||||
}
|
||||
records.forEach(record -> {
|
||||
try {
|
||||
log.info("[{}] SessionIdMSB, [{}] SessionIdLSB, records", record.getValue().getSessionIdMSB(), record.getValue().getSessionIdLSB());
|
||||
processToTransportMsg(record.getValue());
|
||||
} catch (Throwable 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());
|
||||
SessionMetaData md = sessions.get(sessionId);
|
||||
if (md != null) {
|
||||
log.trace("[{}] Processing notification: {}", sessionId, toSessionMsg);
|
||||
SessionMsgListener listener = md.getListener();
|
||||
transportCallbackExecutor.submit(() -> {
|
||||
if (toSessionMsg.hasGetAttributesResponse()) {
|
||||
@ -798,12 +798,14 @@ public class DefaultTransportService implements TransportService {
|
||||
deregisterSession(md.getSessionInfo());
|
||||
}
|
||||
} else {
|
||||
log.trace("Processing broadcast notification: {}", toSessionMsg);
|
||||
if (toSessionMsg.hasEntityUpdateMsg()) {
|
||||
TransportProtos.EntityUpdateMsg msg = toSessionMsg.getEntityUpdateMsg();
|
||||
EntityType entityType = EntityType.valueOf(msg.getEntityType());
|
||||
if (EntityType.DEVICE_PROFILE.equals(entityType)) {
|
||||
DeviceProfile deviceProfile = deviceProfileCache.put(msg.getData());
|
||||
if (deviceProfile != null) {
|
||||
log.info("On device profile update: {}", deviceProfile);
|
||||
onProfileUpdate(deviceProfile);
|
||||
}
|
||||
} else if (EntityType.TENANT_PROFILE.equals(entityType)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user