From 7ae941e290e8172abda7c5627cb56d806e5d7ad0 Mon Sep 17 00:00:00 2001 From: Stefan Behl Date: Tue, 31 Jul 2018 12:01:14 +0200 Subject: [PATCH] Hotfix for DMF UPDATE_ATTRIBUTES message --- .../hawkbit/amqp/AmqpMessageHandlerService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 7ec9bb943..7001f8500 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -252,6 +252,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { private void updateAttributes(final Message message) { final DmfAttributeUpdate attributeUpdate = convertMessage(message, DmfAttributeUpdate.class); final String thingId = getStringHeaderKey(message, MessageHeaderKey.THING_ID, "ThingId is null"); + // reject messages with invalid attributes if (attributeUpdate.getAttributes().entrySet().stream() .anyMatch(e -> !AmqpMessageHandlerService.isAttributeEntryValid(e))) { throw new MessageConversionException( @@ -262,9 +263,18 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } private static boolean isAttributeEntryValid(final Entry e) { - if (e == null) return true; - return e.getKey() != null && e.getKey().length() <= 32 && (e.getValue() == null || (e.getValue() != null - && e.getValue().length() <= 128)); + if (e == null) { + return true; + } + return isAttributeKeyValid(e.getKey()) && isAttributeValueValid(e.getValue()); + } + + private static boolean isAttributeKeyValid(final String key) { + return key != null && key.length() <= 32; + } + + private static boolean isAttributeValueValid(final String value) { + return value == null || value.length() <= 128; } /**