Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly segregate Json MessageBodyReader/Writer classes for server and client #30146

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,33 +30,37 @@ public class ResteasyReactiveJsonbCommonProcessor {
VertxJson.JsonArrayDeserializer.class.getName());

@BuildStep
void additionalProviders(BuildProducer<AdditionalBeanBuildItem> additionalBean,
BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
public void registerVertxJsonSupport(
BuildProducer<JsonbSerializerBuildItem> serializers,
BuildProducer<JsonbDeserializerBuildItem> deserializers) {
serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS));
deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS));
}

@BuildStep
public void beans(BuildProducer<AdditionalBeanBuildItem> 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<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> 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<JsonbSerializerBuildItem> serializers,
BuildProducer<JsonbDeserializerBuildItem> deserializers) {
serializers.produce(new JsonbSerializerBuildItem(VERTX_SERIALIZERS));
deserializers.produce(new JsonbDeserializerBuildItem(VERTX_DESERIALIZERS));
}
}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -17,4 +22,11 @@ void feature(BuildProducer<FeatureBuildItem> feature) {
ServerDefaultProducesHandlerBuildItem jsonDefault() {
return ServerDefaultProducesHandlerBuildItem.json();
}

@BuildStep
void additionalProviders(BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters,
RuntimeType.SERVER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -135,7 +137,9 @@ public void testStreamJsonMultiFromMulti() {
}

private void testJsonMulti(String path) {
Client client = ClientBuilder.newBuilder().build();
Client client = ClientBuilder.newBuilder()
.register(new JsonbMessageBodyReader(JsonbBuilder.create())) // we need this because registering Jsonb for the server part does not affect the client
.build();
WebTarget target = client.target(uri.toString() + path);
Multi<Message> multi = target.request().rx(MultiInvoker.class).get(Message.class);
List<Message> list = multi.collect().asList().await().atMost(Duration.ofSeconds(30));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@

import static io.quarkus.deployment.Feature.REST_CLIENT_REACTIVE_JSONB;

import javax.ws.rs.RuntimeType;

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;

public class RestClientReactiveJsonbProcessor {

@BuildStep
void feature(BuildProducer<FeatureBuildItem> features) {
features.produce(new FeatureBuildItem(REST_CLIENT_REACTIVE_JSONB));
}

@BuildStep
void additionalProviders(BuildProducer<MessageBodyReaderBuildItem> additionalReaders,
BuildProducer<MessageBodyWriterBuildItem> additionalWriters) {
ResteasyReactiveJsonbCommonProcessor.additionalProviders(additionalReaders, additionalWriters,
RuntimeType.CLIENT);
}
}
4 changes: 2 additions & 2 deletions integration-tests/resteasy-mutiny/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive</artifactId>
<artifactId>quarkus-rest-client-reactive-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -46,7 +46,7 @@
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-deployment</artifactId>
<artifactId>quarkus-rest-client-reactive-jsonb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand Down