diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/MediaTypeSuffixTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/MediaTypeSuffixTest.java new file mode 100644 index 0000000000000..87eeae28e6a13 --- /dev/null +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/MediaTypeSuffixTest.java @@ -0,0 +1,69 @@ +package io.quarkus.rest.client.reactive; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.is; + +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class MediaTypeSuffixTest { + + private static final String CUSTOM_JSON_MEDIA_TYPE = "application/vnd.search.v1+json"; + + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(HelloResource.class, Client.class)) + .withConfigurationResource("media-type-suffix-application.properties"); + + @Test + public void test() { + when() + .get("/hello") + .then() + .statusCode(200) + .body("foo", is("bar")); + } + + @RegisterRestClient(configKey = "test") + @Path("/hello") + public interface Client { + + @GET + @Path("/custom") + @Produces(CUSTOM_JSON_MEDIA_TYPE) + Map test(); + } + + @Path("/hello") + public static class HelloResource { + + private final Client client; + + public HelloResource(@RestClient Client client) { + this.client = client; + } + + @GET + @Path("/custom") + @Produces(CUSTOM_JSON_MEDIA_TYPE) + public Map hello() { + return Map.of("foo", "bar"); + } + + @GET + public Map test() { + return client.test(); + } + } +} diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/media-type-suffix-application.properties b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/media-type-suffix-application.properties new file mode 100644 index 0000000000000..f37c300de6005 --- /dev/null +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/resources/media-type-suffix-application.properties @@ -0,0 +1 @@ +quarkus.rest-client.test.url=http://localhost:${quarkus.http.test-port:8081} diff --git a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientReaderInterceptorContextImpl.java b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientReaderInterceptorContextImpl.java index 55815186fa959..c73f288f0c87a 100644 --- a/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientReaderInterceptorContextImpl.java +++ b/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/ClientReaderInterceptorContextImpl.java @@ -17,6 +17,7 @@ import org.jboss.resteasy.reactive.common.core.Serialisers; import org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl; import org.jboss.resteasy.reactive.common.util.CaseInsensitiveMap; +import org.jboss.resteasy.reactive.common.util.MediaTypeHelper; public class ClientReaderInterceptorContextImpl extends AbstractClientInterceptorContextImpl implements ReaderInterceptorContext { @@ -34,7 +35,7 @@ public ClientReaderInterceptorContextImpl(Annotation[] annotations, Class ent Map properties, MultivaluedMap headers, ConfigurationImpl configuration, Serialisers serialisers, InputStream inputStream, ReaderInterceptor[] interceptors) { - super(annotations, entityClass, entityType, mediaType, properties); + super(annotations, entityClass, entityType, MediaTypeHelper.withSuffixAsSubtype(mediaType), properties); this.configuration = configuration; this.serialisers = serialisers; this.inputStream = inputStream; diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java index 422de499dd6e3..41b72877f9808 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java @@ -272,6 +272,9 @@ public static boolean isUnsupportedWildcardSubtype(MediaType mediaType) { * that uses the suffix as the subtype */ public static MediaType withSuffixAsSubtype(MediaType mediaType) { + if (mediaType == null) { + return null; + } int plusIndex = mediaType.getSubtype().indexOf('+'); if ((plusIndex > -1) && (plusIndex < mediaType.getSubtype().length() - 1)) { mediaType = new MediaType(mediaType.getType(),