From 9c41f3331ce54d476f41bb385c9eeb4256be8a5d Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 3 Jan 2023 15:59:47 +0200 Subject: [PATCH] Properly segregate Json MessageBodyReader/Writer classes for server and client Fixes: #30089 --- .../ResteasyReactiveJsonbCommonProcessor.java | 27 +++++++++++-------- .../ResteasyReactiveJsonbProcessor.java | 12 +++++++++ .../deployment/test/sse/SseTestCase.java | 4 ++- .../RestClientReactiveJsonbProcessor.java | 18 +++++++++++++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb-common/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/common/deployment/ResteasyReactiveJsonbCommonProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb-common/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/common/deployment/ResteasyReactiveJsonbCommonProcessor.java index 1ca16e922bd1f5..1c5c4a70741dae 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb-common/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/common/deployment/ResteasyReactiveJsonbCommonProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb-common/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/common/deployment/ResteasyReactiveJsonbCommonProcessor.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; +import javax.ws.rs.RuntimeType; import javax.ws.rs.core.MediaType; import org.jboss.resteasy.reactive.common.util.RestMediaType; @@ -29,33 +30,37 @@ public class ResteasyReactiveJsonbCommonProcessor { VertxJson.JsonArrayDeserializer.class.getName()); @BuildStep - void additionalProviders(BuildProducer additionalBean, - BuildProducer additionalReaders, - BuildProducer additionalWriters) { + public void registerVertxJsonSupport( + BuildProducer serializers, + BuildProducer deserializers) { + serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS)); + deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS)); + } + + @BuildStep + public void beans(BuildProducer additionalBean) { // make these beans to they can get instantiated with the Quarkus CDI configured Jsonb object additionalBean.produce(AdditionalBeanBuildItem.builder() .addBeanClass(JsonbMessageBodyReader.class.getName()) .addBeanClass(JsonbMessageBodyWriter.class.getName()) .setUnremovable().build()); + } + + public static void additionalProviders(BuildProducer additionalReaders, + BuildProducer additionalWriters, RuntimeType runtimeType) { additionalReaders.produce( new MessageBodyReaderBuildItem.Builder(JsonbMessageBodyReader.class.getName(), Object.class.getName()) .setMediaTypeStrings(Collections.singletonList(MediaType.APPLICATION_JSON)) .setBuiltin(true) + .setRuntimeType(runtimeType) .build()); additionalWriters.produce( new MessageBodyWriterBuildItem.Builder(JsonbMessageBodyWriter.class.getName(), Object.class.getName()) .setMediaTypeStrings(List.of(MediaType.APPLICATION_JSON, RestMediaType.APPLICATION_NDJSON, RestMediaType.APPLICATION_STREAM_JSON)) .setBuiltin(true) + .setRuntimeType(runtimeType) .build()); } - - @BuildStep - public void registerVertxJsonSupport( - BuildProducer serializers, - BuildProducer deserializers) { - serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS)); - deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS)); - } } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/deployment/ResteasyReactiveJsonbProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/deployment/ResteasyReactiveJsonbProcessor.java index a674d8d89bdfa8..64046a86364c5a 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/deployment/ResteasyReactiveJsonbProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/main/java/io/quarkus/resteasy/reactive/jsonb/deployment/ResteasyReactiveJsonbProcessor.java @@ -1,10 +1,15 @@ package io.quarkus.resteasy.reactive.jsonb.deployment; +import javax.ws.rs.RuntimeType; + import io.quarkus.deployment.Feature; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.resteasy.reactive.common.deployment.ServerDefaultProducesHandlerBuildItem; +import io.quarkus.resteasy.reactive.jsonb.common.deployment.ResteasyReactiveJsonbCommonProcessor; +import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem; +import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem; public class ResteasyReactiveJsonbProcessor { @@ -17,4 +22,11 @@ void feature(BuildProducer feature) { ServerDefaultProducesHandlerBuildItem jsonDefault() { return ServerDefaultProducesHandlerBuildItem.json(); } + + @BuildStep + void additionalProviders(BuildProducer additionalReaders, + BuildProducer additionalWriters) { + ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters, + RuntimeType.SERVER); + } } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/test/java/io/quarkus/resteasy/reactive/jsonb/deployment/test/sse/SseTestCase.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/test/java/io/quarkus/resteasy/reactive/jsonb/deployment/test/sse/SseTestCase.java index 8930a47aa66228..2772c071fafd43 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/test/java/io/quarkus/resteasy/reactive/jsonb/deployment/test/sse/SseTestCase.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-jsonb/deployment/src/test/java/io/quarkus/resteasy/reactive/jsonb/deployment/test/sse/SseTestCase.java @@ -14,6 +14,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import javax.json.bind.JsonbBuilder; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; @@ -24,6 +25,7 @@ import org.apache.http.HttpStatus; import org.jboss.resteasy.reactive.client.impl.MultiInvoker; import org.jboss.resteasy.reactive.common.util.RestMediaType; +import org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -135,7 +137,7 @@ public void testStreamJsonMultiFromMulti() { } private void testJsonMulti(String path) { - Client client = ClientBuilder.newBuilder().build(); + Client client = ClientBuilder.newBuilder().register(new JsonbMessageBodyReader(JsonbBuilder.create())).build(); WebTarget target = client.target(uri.toString() + path); Multi multi = target.request().rx(MultiInvoker.class).get(Message.class); List list = multi.collect().asList().await().atMost(Duration.ofSeconds(30)); diff --git a/extensions/resteasy-reactive/rest-client-reactive-jsonb/deployment/src/main/java/io/quarkus/rest/client/reactive/jsonb/deployment/RestClientReactiveJsonbProcessor.java b/extensions/resteasy-reactive/rest-client-reactive-jsonb/deployment/src/main/java/io/quarkus/rest/client/reactive/jsonb/deployment/RestClientReactiveJsonbProcessor.java index 533c8f0cbc8120..adfcc62e06082a 100644 --- a/extensions/resteasy-reactive/rest-client-reactive-jsonb/deployment/src/main/java/io/quarkus/rest/client/reactive/jsonb/deployment/RestClientReactiveJsonbProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive-jsonb/deployment/src/main/java/io/quarkus/rest/client/reactive/jsonb/deployment/RestClientReactiveJsonbProcessor.java @@ -2,9 +2,20 @@ import static io.quarkus.deployment.Feature.REST_CLIENT_REACTIVE_JSONB; +import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.resteasy.reactive.jsonb.common.deployment.ResteasyReactiveJsonbCommonProcessor; +import io.quarkus.resteasy.reactive.spi.MessageBodyReaderBuildItem; +import io.quarkus.resteasy.reactive.spi.MessageBodyWriterBuildItem; +import java.util.Collections; +import java.util.List; +import javax.ws.rs.RuntimeType; +import javax.ws.rs.core.MediaType; +import org.jboss.resteasy.reactive.common.util.RestMediaType; +import org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyReader; +import org.jboss.resteasy.reactive.server.jsonb.JsonbMessageBodyWriter; public class RestClientReactiveJsonbProcessor { @@ -12,4 +23,11 @@ public class RestClientReactiveJsonbProcessor { void feature(BuildProducer features) { features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JSONB)); } + + @BuildStep + void additionalProviders(BuildProducer additionalReaders, + BuildProducer additionalWriters) { + ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters, + RuntimeType.CLIENT); + } }