Browse Source

lwm2m: back transport newKey fix bug object id=19 (#4291)

pull/4293/head
nickAS21 6 years ago
committed by GitHub
parent
commit
7ea6c7163a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportRequest.java
  2. 16
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportServiceImpl.java
  3. 4
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2mValueConverterImpl.java

6
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportRequest.java

@ -151,11 +151,13 @@ public class LwM2mTransportRequest {
case POST_TYPE_OPER_WRITE_REPLACE: case POST_TYPE_OPER_WRITE_REPLACE:
// Request to write a <b>String Single-Instance Resource</b> using the TLV content format. // Request to write a <b>String Single-Instance Resource</b> using the TLV content format.
if (resource != null && contentFormat != null) { if (resource != null && contentFormat != null) {
if (contentFormat.equals(ContentFormat.TLV) && !resource.multiple) { // if (contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
if (contentFormat.equals(ContentFormat.TLV)) {
request = this.getWriteRequestSingleResource(null, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration); request = this.getWriteRequestSingleResource(null, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration);
} }
// Mode.REPLACE && Request to write a <b>String Single-Instance Resource</b> using the given content format (TEXT, TLV, JSON) // Mode.REPLACE && Request to write a <b>String Single-Instance Resource</b> using the given content format (TEXT, TLV, JSON)
else if (!contentFormat.equals(ContentFormat.TLV) && !resource.multiple) { // else if (!contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
else if (!contentFormat.equals(ContentFormat.TLV)) {
request = this.getWriteRequestSingleResource(contentFormat, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration); request = this.getWriteRequestSingleResource(contentFormat, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration);
} }
} }

16
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportServiceImpl.java

@ -549,7 +549,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
*/ */
private boolean validatePathInAttrProfile(LwM2mClientProfile clientProfile, String path) { private boolean validatePathInAttrProfile(LwM2mClientProfile clientProfile, String path) {
try { try {
List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(), new TypeToken<>() { List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(), new TypeToken<List<String>>() {
}.getType()); }.getType());
return attributesSet.stream().anyMatch(p -> p.equals(path)); return attributesSet.stream().anyMatch(p -> p.equals(path));
} catch (Exception e) { } catch (Exception e) {
@ -565,7 +565,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
*/ */
private boolean validatePathInTelemetryProfile(LwM2mClientProfile clientProfile, String path) { private boolean validatePathInTelemetryProfile(LwM2mClientProfile clientProfile, String path) {
try { try {
List<String> telemetriesSet = new Gson().fromJson(clientProfile.getPostTelemetryProfile(), new TypeToken<>() { List<String> telemetriesSet = new Gson().fromJson(clientProfile.getPostTelemetryProfile(), new TypeToken<List<String>>() {
}.getType()); }.getType());
return telemetriesSet.stream().anyMatch(p -> p.equals(path)); return telemetriesSet.stream().anyMatch(p -> p.equals(path));
} catch (Exception e) { } catch (Exception e) {
@ -821,10 +821,8 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
// #5.1 // #5.1
if (!observeOld.equals(observeNew)) { if (!observeOld.equals(observeNew)) {
Set<String> observeSetOld = new Gson().fromJson(observeOld, new TypeToken<>() { Set<String> observeSetOld = new Gson().fromJson(observeOld, new TypeToken<Set<String>>() {}.getType());
}.getType()); Set<String> observeSetNew = new Gson().fromJson(observeNew, new TypeToken<Set<String>>() {}.getType());
Set<String> observeSetNew = new Gson().fromJson(observeNew, new TypeToken<>() {
}.getType());
//#5.2 add //#5.2 add
// path Attr/Telemetry includes newObserve // path Attr/Telemetry includes newObserve
attributeSetOld.addAll(telemetrySetOld); attributeSetOld.addAll(telemetrySetOld);
@ -846,7 +844,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
} }
private Set<String> convertJsonArrayToSet(JsonArray jsonArray) { private Set<String> convertJsonArrayToSet(JsonArray jsonArray) {
List<String> attributeListOld = new Gson().fromJson(jsonArray, new TypeToken<>() { List<String> attributeListOld = new Gson().fromJson(jsonArray, new TypeToken<List<String>>() {
}.getType()); }.getType());
return Sets.newConcurrentHashSet(attributeListOld); return Sets.newConcurrentHashSet(attributeListOld);
} }
@ -886,7 +884,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
*/ */
private void readResourceValueObserve(Registration registration, Set<String> targets, String typeOper) { private void readResourceValueObserve(Registration registration, Set<String> targets, String typeOper) {
targets.forEach(target -> { targets.forEach(target -> {
LwM2mPath pathIds = new LwM2mPath(target); LwM2mPath pathIds = new LwM2mPath(convertToObjectIdFromIdVer(target));
if (pathIds.isResource()) { if (pathIds.isResource()) {
if (GET_TYPE_OPER_READ.equals(typeOper)) { if (GET_TYPE_OPER_READ.equals(typeOper)) {
lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,
@ -913,7 +911,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
LwM2mClient lwM2MClient = lwM2mClientContext.getLwM2mClientWithReg(registration, null); LwM2mClient lwM2MClient = lwM2mClientContext.getLwM2mClientWithReg(registration, null);
paramAnallyzer.forEach(p -> { paramAnallyzer.forEach(p -> {
if (this.returnResourceValueFromLwM2MClient(lwM2MClient, p) != null) { if (this.returnResourceValueFromLwM2MClient(lwM2MClient, p) != null) {
this.setCancelObservationRecourse(registration, p); this.setCancelObservationRecourse(registration, convertToObjectIdFromIdVer(p));
} }
} }
); );

4
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2mValueConverterImpl.java

@ -145,6 +145,8 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
} }
DateFormat formatter = new SimpleDateFormat(DATE_FORMAT); DateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
return formatter.format(new Date(timeValue)); return formatter.format(new Date(timeValue));
case OPAQUE:
return Hex.encodeHexString((byte[])value);
default: default:
break; break;
} }
@ -155,7 +157,7 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
log.debug("Trying to convert hexadecimal string [{}] to byte array", value); log.debug("Trying to convert hexadecimal string [{}] to byte array", value);
// TODO check if we shouldn't instead assume that the string contains Base64 encoded data // TODO check if we shouldn't instead assume that the string contains Base64 encoded data
try { try {
return Hex.decodeHex(((String) value).toCharArray()); return Hex.decodeHex(((String)value).toCharArray());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new CodecException("Unable to convert hexastring [%s] to byte array for resource %s", value, throw new CodecException("Unable to convert hexastring [%s] to byte array for resource %s", value,
resourcePath); resourcePath);

Loading…
Cancel
Save