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