Commit 7ea6c7163a48dea51e82b474c035a96c136557f2

Authored by nickAS21
Committed by GitHub
1 parent e5c4feaa

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

... ... @@ -151,11 +151,13 @@ public class LwM2mTransportRequest {
151 151 case POST_TYPE_OPER_WRITE_REPLACE:
152 152 // Request to write a <b>String Single-Instance Resource</b> using the TLV content format.
153 153 if (resource != null && contentFormat != null) {
154   - if (contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
  154 +// if (contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
  155 + if (contentFormat.equals(ContentFormat.TLV)) {
155 156 request = this.getWriteRequestSingleResource(null, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration);
156 157 }
157 158 // Mode.REPLACE && Request to write a <b>String Single-Instance Resource</b> using the given content format (TEXT, TLV, JSON)
158   - else if (!contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
  159 +// else if (!contentFormat.equals(ContentFormat.TLV) && !resource.multiple) {
  160 + else if (!contentFormat.equals(ContentFormat.TLV)) {
159 161 request = this.getWriteRequestSingleResource(contentFormat, resultIds.getObjectId(), resultIds.getObjectInstanceId(), resultIds.getResourceId(), params, resource.type, registration);
160 162 }
161 163 }
... ...
... ... @@ -549,7 +549,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
549 549 */
550 550 private boolean validatePathInAttrProfile(LwM2mClientProfile clientProfile, String path) {
551 551 try {
552   - List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(), new TypeToken<>() {
  552 + List<String> attributesSet = new Gson().fromJson(clientProfile.getPostAttributeProfile(), new TypeToken<List<String>>() {
553 553 }.getType());
554 554 return attributesSet.stream().anyMatch(p -> p.equals(path));
555 555 } catch (Exception e) {
... ... @@ -565,7 +565,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
565 565 */
566 566 private boolean validatePathInTelemetryProfile(LwM2mClientProfile clientProfile, String path) {
567 567 try {
568   - List<String> telemetriesSet = new Gson().fromJson(clientProfile.getPostTelemetryProfile(), new TypeToken<>() {
  568 + List<String> telemetriesSet = new Gson().fromJson(clientProfile.getPostTelemetryProfile(), new TypeToken<List<String>>() {
569 569 }.getType());
570 570 return telemetriesSet.stream().anyMatch(p -> p.equals(path));
571 571 } catch (Exception e) {
... ... @@ -821,10 +821,8 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
821 821
822 822 // #5.1
823 823 if (!observeOld.equals(observeNew)) {
824   - Set<String> observeSetOld = new Gson().fromJson(observeOld, new TypeToken<>() {
825   - }.getType());
826   - Set<String> observeSetNew = new Gson().fromJson(observeNew, new TypeToken<>() {
827   - }.getType());
  824 + Set<String> observeSetOld = new Gson().fromJson(observeOld, new TypeToken<Set<String>>() {}.getType());
  825 + Set<String> observeSetNew = new Gson().fromJson(observeNew, new TypeToken<Set<String>>() {}.getType());
828 826 //#5.2 add
829 827 // path Attr/Telemetry includes newObserve
830 828 attributeSetOld.addAll(telemetrySetOld);
... ... @@ -846,7 +844,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
846 844 }
847 845
848 846 private Set<String> convertJsonArrayToSet(JsonArray jsonArray) {
849   - List<String> attributeListOld = new Gson().fromJson(jsonArray, new TypeToken<>() {
  847 + List<String> attributeListOld = new Gson().fromJson(jsonArray, new TypeToken<List<String>>() {
850 848 }.getType());
851 849 return Sets.newConcurrentHashSet(attributeListOld);
852 850 }
... ... @@ -886,7 +884,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
886 884 */
887 885 private void readResourceValueObserve(Registration registration, Set<String> targets, String typeOper) {
888 886 targets.forEach(target -> {
889   - LwM2mPath pathIds = new LwM2mPath(target);
  887 + LwM2mPath pathIds = new LwM2mPath(convertToObjectIdFromIdVer(target));
890 888 if (pathIds.isResource()) {
891 889 if (GET_TYPE_OPER_READ.equals(typeOper)) {
892 890 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,
... ... @@ -913,7 +911,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
913 911 LwM2mClient lwM2MClient = lwM2mClientContext.getLwM2mClientWithReg(registration, null);
914 912 paramAnallyzer.forEach(p -> {
915 913 if (this.returnResourceValueFromLwM2MClient(lwM2MClient, p) != null) {
916   - this.setCancelObservationRecourse(registration, p);
  914 + this.setCancelObservationRecourse(registration, convertToObjectIdFromIdVer(p));
917 915 }
918 916 }
919 917 );
... ...
... ... @@ -145,6 +145,8 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
145 145 }
146 146 DateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
147 147 return formatter.format(new Date(timeValue));
  148 + case OPAQUE:
  149 + return Hex.encodeHexString((byte[])value);
148 150 default:
149 151 break;
150 152 }
... ... @@ -155,7 +157,7 @@ public class LwM2mValueConverterImpl implements LwM2mValueConverter {
155 157 log.debug("Trying to convert hexadecimal string [{}] to byte array", value);
156 158 // TODO check if we shouldn't instead assume that the string contains Base64 encoded data
157 159 try {
158   - return Hex.decodeHex(((String) value).toCharArray());
  160 + return Hex.decodeHex(((String)value).toCharArray());
159 161 } catch (IllegalArgumentException e) {
160 162 throw new CodecException("Unable to convert hexastring [%s] to byte array for resource %s", value,
161 163 resourcePath);
... ...