From 72302396092053fa648ab7d0300843634f66c73d Mon Sep 17 00:00:00 2001 From: Pierre Adam Date: Wed, 20 Mar 2024 19:45:53 +0100 Subject: [PATCH] Fixes #39586. Properly use headers from RestMulti when the datasource is empty. Signed-off-by: Pierre Adam --- .../deployment/test/streams/StreamResource.java | 13 +++++++++++++ .../deployment/test/streams/StreamTestCase.java | 8 ++++++++ .../server/handlers/PublisherResponseHandler.java | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamResource.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamResource.java index 01895dfbe7026..97292e3956c68 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamResource.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamResource.java @@ -199,6 +199,19 @@ public Multi multiNdJson2() { Wrapper::getStatus); } + @Path("restmulti/empty") + @GET + @Produces(RestMediaType.APPLICATION_JSON) + public Multi restMultiEmptyJson() { + return RestMulti.fromUniResponse( + Uni.createFrom().item( + () -> new Wrapper(Multi.createFrom().empty(), + new AbstractMap.SimpleEntry<>("foo", "bar"), 222)), + Wrapper::getData, + Wrapper::getHeaders, + Wrapper::getStatus); + } + @Path("stream-json/multi") @GET @Produces(RestMediaType.APPLICATION_STREAM_JSON) diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamTestCase.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamTestCase.java index 915ad45721cf7..737390d382051 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamTestCase.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/streams/StreamTestCase.java @@ -174,6 +174,14 @@ public void testNdJsonMultiFromMulti2() { .header("foo", "bar"); } + @Test + public void testRestMultiEmptyJson() { + when().get(uri.toString() + "streams/restmulti/empty") + .then().statusCode(222) + .body(is("[]")) + .header("foo", "bar"); + } + @Test public void testStreamJsonMultiFromMulti() { when().get(uri.toString() + "streams/stream-json/multi") diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java index c1af678260549..20110476a41f8 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/PublisherResponseHandler.java @@ -151,7 +151,7 @@ private List determineCustomizers(boolean isFirst) @Override public void onComplete() { if (!hadItem) { - StreamingUtil.setHeaders(requestContext, requestContext.serverResponse(), staticCustomizers); + StreamingUtil.setHeaders(requestContext, requestContext.serverResponse(), this.determineCustomizers(true)); } if (json) { String postfix = onCompleteText();