|
|
@ -16,13 +16,13 @@ |
|
|
package org.thingsboard.server.transport.lwm2m.server; |
|
|
package org.thingsboard.server.transport.lwm2m.server; |
|
|
/** |
|
|
/** |
|
|
* Copyright © 2016-2020 The Thingsboard Authors |
|
|
* Copyright © 2016-2020 The Thingsboard Authors |
|
|
* |
|
|
* <p> |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
* you may not use this file except in compliance with the License. |
|
|
* you may not use this file except in compliance with the License. |
|
|
* You may obtain a copy of the License at |
|
|
* You may obtain a copy of the License at |
|
|
* |
|
|
* <p> |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
* |
|
|
* <p> |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* Unless required by applicable law or agreed to in writing, software |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
@ -34,9 +34,13 @@ import com.google.gson.JsonElement; |
|
|
import com.google.gson.JsonObject; |
|
|
import com.google.gson.JsonObject; |
|
|
import lombok.Getter; |
|
|
import lombok.Getter; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.eclipse.leshan.core.model.DDFFileParser; |
|
|
|
|
|
import org.eclipse.leshan.core.model.DefaultDDFFileValidator; |
|
|
|
|
|
import org.eclipse.leshan.core.model.InvalidDDFFileException; |
|
|
import org.eclipse.leshan.core.model.ObjectModel; |
|
|
import org.eclipse.leshan.core.model.ObjectModel; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.thingsboard.server.common.transport.TransportContext; |
|
|
import org.thingsboard.server.common.transport.TransportContext; |
|
|
|
|
|
import org.thingsboard.server.common.transport.TransportResourceCache; |
|
|
import org.thingsboard.server.common.transport.TransportService; |
|
|
import org.thingsboard.server.common.transport.TransportService; |
|
|
import org.thingsboard.server.common.transport.TransportServiceCallback; |
|
|
import org.thingsboard.server.common.transport.TransportServiceCallback; |
|
|
import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
|
|
import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
|
|
@ -48,7 +52,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCreden |
|
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
|
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
|
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; |
|
|
import org.thingsboard.server.transport.lwm2m.server.adaptors.LwM2MJsonAdaptor; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_TELEMETRY; |
|
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_TELEMETRY; |
|
|
|
|
|
|
|
|
@ -62,14 +67,16 @@ public class LwM2mTransportContextServer extends TransportContext { |
|
|
|
|
|
|
|
|
private final TransportService transportService; |
|
|
private final TransportService transportService; |
|
|
|
|
|
|
|
|
private List<ObjectModel> modelsValueServer; |
|
|
private final TransportResourceCache transportResourceCache; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
private final LwM2MJsonAdaptor adaptor; |
|
|
private final LwM2MJsonAdaptor adaptor; |
|
|
|
|
|
|
|
|
public LwM2mTransportContextServer(LwM2MTransportConfigServer lwM2MTransportConfigServer, TransportService transportService, LwM2MJsonAdaptor adaptor) { |
|
|
public LwM2mTransportContextServer(LwM2MTransportConfigServer lwM2MTransportConfigServer, TransportService transportService, TransportResourceCache transportResourceCache, LwM2MJsonAdaptor adaptor) { |
|
|
this.lwM2MTransportConfigServer = lwM2MTransportConfigServer; |
|
|
this.lwM2MTransportConfigServer = lwM2MTransportConfigServer; |
|
|
this.transportService = transportService; |
|
|
this.transportService = transportService; |
|
|
|
|
|
this.transportResourceCache = transportResourceCache; |
|
|
this.adaptor = adaptor; |
|
|
this.adaptor = adaptor; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -77,6 +84,10 @@ public class LwM2mTransportContextServer extends TransportContext { |
|
|
return this.lwM2MTransportConfigServer; |
|
|
return this.lwM2MTransportConfigServer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TransportResourceCache getTransportResourceCache() { |
|
|
|
|
|
return this.transportResourceCache; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Sent to Thingsboard Attribute || Telemetry |
|
|
* Sent to Thingsboard Attribute || Telemetry |
|
|
* |
|
|
* |
|
|
@ -139,59 +150,13 @@ public class LwM2mTransportContextServer extends TransportContext { |
|
|
.build(); |
|
|
.build(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ObjectModel parseFromXmlToObjectModel(byte[] xmlByte, String streamName, DefaultDDFFileValidator ddfValidator) { |
|
|
|
|
|
try { |
|
|
|
|
|
DDFFileParser ddfFileParser = new DDFFileParser(ddfValidator); |
|
|
// /**
|
|
|
return ddfFileParser.parseEx(new ByteArrayInputStream(xmlByte), streamName).get(0); |
|
|
// * ResourcesRequestMsg
|
|
|
} catch (IOException | InvalidDDFFileException e) { |
|
|
// *
|
|
|
log.error("Could not parse the XML file [{}]", streamName, e); |
|
|
// * @param resourceType
|
|
|
return null; |
|
|
// * @return
|
|
|
} |
|
|
// */
|
|
|
} |
|
|
// public GetResourcesResponseMsg getResourceTenant (UUID tenantId, String resourceType) {
|
|
|
|
|
|
// CountDownLatch latch = new CountDownLatch(1);
|
|
|
|
|
|
// GetResourcesResponseMsg responseMsg =
|
|
|
|
|
|
// this.getTransportService()
|
|
|
|
|
|
// .getResources(GetResourcesRequestMsg.newBuilder()
|
|
|
|
|
|
// .setResourceType(resourceType)
|
|
|
|
|
|
// .setTenantIdLSB(tenantId.getLeastSignificantBits())
|
|
|
|
|
|
// .setTenantIdMSB(tenantId.getMostSignificantBits())
|
|
|
|
|
|
// .build());
|
|
|
|
|
|
// latch.countDown();
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// latch.await(this.getLwM2MTransportConfigServer().getTimeout(), TimeUnit.MILLISECONDS);
|
|
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
|
|
// log.error("Failed to await credentials!", e);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// return responseMsg;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// public GetResourcesResponseMsg getResourceTenantProcess (UUID tenantId, String resourceType) {
|
|
|
|
|
|
// CountDownLatch latch = new CountDownLatch(2);
|
|
|
|
|
|
// final GetResourcesResponseMsg[] responseMsg = {null};
|
|
|
|
|
|
// this.getTransportService().process(GetResourcesRequestMsg.newBuilder()
|
|
|
|
|
|
// .setResourceType(resourceType)
|
|
|
|
|
|
// .setTenantIdLSB(tenantId.getLeastSignificantBits())
|
|
|
|
|
|
// .setTenantIdMSB(tenantId.getMostSignificantBits())
|
|
|
|
|
|
// .build(),
|
|
|
|
|
|
// new TransportServiceCallback<>() {
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
// public void onSuccess(GetResourcesResponseMsg msg) { responseMsg[0] = msg;
|
|
|
|
|
|
// latch.countDown();
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
// public void onError(Throwable e) {
|
|
|
|
|
|
// log.trace("[{}] [{}] Failed to process credentials ", tenantId, e);
|
|
|
|
|
|
// latch.countDown();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// latch.await(this.getLwM2MTransportConfigServer().getTimeout(), TimeUnit.MILLISECONDS);
|
|
|
|
|
|
// } catch (InterruptedException e) {
|
|
|
|
|
|
// log.error("Failed to await credentials!", e);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return responseMsg[0];
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|
|