From 28190c805e774b271f628f36ea4b7717e11b0f4c Mon Sep 17 00:00:00 2001 From: Akashdeep Singh Jassal Date: Thu, 7 Nov 2024 10:02:23 +0100 Subject: [PATCH 1/2] fix #620 : support sending null headers in POST send message request --- .../main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java b/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java index 359c871d6..e7abbad90 100644 --- a/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java +++ b/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java @@ -31,7 +31,7 @@ public ProducerRecord create(String topic, private Iterable
createHeaders(Map clientHeaders) { RecordHeaders headers = new RecordHeaders(); - clientHeaders.forEach((k, v) -> headers.add(new RecordHeader(k, v.getBytes()))); + clientHeaders.forEach((k, v) -> headers.add(new RecordHeader(k, v == null ? null : v.getBytes()))); return headers; } From ebfd8e19cc7f59cedfd17527eba8f1cd0ec3cf5a Mon Sep 17 00:00:00 2001 From: Akashdeep Singh Jassal Date: Thu, 7 Nov 2024 10:03:57 +0100 Subject: [PATCH 2/2] tests : added a send messsage test that verify null values in headers is functional --- .../kafbat/ui/service/SendAndReadTests.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java b/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java index cdf304509..fac5a5f59 100644 --- a/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java +++ b/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java @@ -19,6 +19,7 @@ import io.kafbat.ui.serdes.builtin.StringSerde; import io.kafbat.ui.serdes.builtin.sr.SchemaRegistrySerde; import java.time.Duration; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -425,6 +426,25 @@ void topicMessageMetadataJson() { }); } + @Test + void headerValueNullPresentTest() { + new SendAndReadSpec() + .withKeySchema(JSON_SCHEMA) + .withValueSchema(JSON_SCHEMA) + .withMsgToSend( + new CreateTopicMessageDTO() + .key(JSON_SCHEMA_RECORD) + .keySerde(SchemaRegistrySerde.name()) + .content(JSON_SCHEMA_RECORD) + .valueSerde(SchemaRegistrySerde.name()) + .headers(Collections.singletonMap("header123", null)) + ) + .doAssert(polled -> { + assertThat(polled.getHeaders().get("header123")).isNull(); + }); + } + + @Test void noKeyAndNoContentPresentTest() { new SendAndReadSpec()