diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformer.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformer.java index ebc5ee326e..65f84b46b3 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformer.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformer.java @@ -236,6 +236,7 @@ private static Set getUserPropertiesOrEmptySet( ) { return externalMessageHeaders.stream() .filter(header -> !KNOWN_MQTT_HEADER_NAMES.contains(header.getKey())) + .filter(header -> header.getValue() != null && !header.getValue().isBlank()) .map(header -> { final var headerKey = header.getKey(); final String headerValue; diff --git a/connectivity/service/src/test/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformerTest.java b/connectivity/service/src/test/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformerTest.java index 7b10149aef..b6c4ff97a7 100644 --- a/connectivity/service/src/test/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformerTest.java +++ b/connectivity/service/src/test/java/org/eclipse/ditto/connectivity/service/messaging/mqtt/hivemq/publishing/ExternalMessageToMqttPublishTransformerTest.java @@ -276,4 +276,32 @@ public void transformExternalMessageWithInvalidRetainValueYieldsTransformationFa .hasCauseInstanceOf(InvalidHeaderValueException.class); } + @Test + public void transformFullyFledgedExternalMessageWithBlankHeaderReturnsExpectedTransformationSuccessResult() { + final var correlationId = testNameCorrelationId.getCorrelationId(); + final var genericMqttPublish = GenericMqttPublish.builder(MQTT_TOPIC, MQTT_QOS) + .retain(RETAIN) + .payload(PAYLOAD) + .correlationData(ByteBufferUtils.fromUtf8String(correlationId.toString())) + .contentType(CONTENT_TYPE.getValue()) + .responseTopic(REPLY_TO_TOPIC) + .userProperties(USER_PROPERTIES) + .build(); + Mockito.when(externalMessage.getHeaders()) + .thenReturn(DittoHeaders.newBuilder() + .putHeader(MqttHeader.MQTT_TOPIC.getName(), MQTT_TOPIC.toString()) + .putHeader(MqttHeader.MQTT_QOS.getName(), String.valueOf(MQTT_QOS.getCode())) + .putHeader(MqttHeader.MQTT_RETAIN.getName(), String.valueOf(genericMqttPublish.isRetain())) + .putHeader("ablankheader", "") + .correlationId(correlationId) + .putHeader(ExternalMessage.REPLY_TO_HEADER, REPLY_TO_TOPIC.toString()) + .contentType(CONTENT_TYPE) + .putHeaders(USER_PROPERTIES.stream() + .collect(Collectors.toMap(UserProperty::name, UserProperty::value))) + .build()); + Mockito.when(externalMessage.getBytePayload()).thenReturn(genericMqttPublish.getPayload()); + + assertThat(ExternalMessageToMqttPublishTransformer.transform(externalMessage, mqttPublishTarget)) + .isEqualTo(TransformationSuccess.of(externalMessage, genericMqttPublish)); + } } \ No newline at end of file