From ad057b6b6b1e44275e3e79afbe21e59e73bc9ddd Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Sat, 16 Dec 2023 18:35:55 +0200 Subject: [PATCH] Take priority into account in ConfigurationImpl This is necessary for REST Client MessageBodyReader and MessageBodyWriter registration (cherry picked from commit e7fcd327371250b7551475a5e008b471d9ea5eb7) --- .../ContextProvidersPriorityTest.java | 26 +++++++++++++++++++ .../common/jaxrs/ConfigurationImpl.java | 6 +++++ 2 files changed, 32 insertions(+) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/ContextProvidersPriorityTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/ContextProvidersPriorityTest.java index c10b4923d2f1f..740d1782f26b9 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/ContextProvidersPriorityTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/provider/ContextProvidersPriorityTest.java @@ -4,6 +4,10 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; +import java.io.InputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; import java.net.URI; import java.util.List; import java.util.Map; @@ -13,17 +17,24 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +import jakarta.ws.rs.Priorities; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.ext.ContextResolver; +import org.eclipse.microprofile.rest.client.annotation.RegisterProvider; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; +import org.jboss.resteasy.reactive.server.jackson.JacksonBasicMessageBodyReader; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import com.fasterxml.jackson.databind.ObjectMapper; + import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder; import io.quarkus.rest.client.reactive.TestJacksonBasicMessageBodyReader; import io.quarkus.test.QuarkusUnitTest; @@ -78,6 +89,7 @@ public Map> callClient(String uri) { } } + @RegisterProvider(ErroneousJacksonBasicMessageBodyReader.class) public interface Client { @GET Map> get(); @@ -101,6 +113,20 @@ public ClientHeadersFactory getContext(Class aClass) { } } + @Priority(Priorities.USER + 100) + public static class ErroneousJacksonBasicMessageBodyReader extends JacksonBasicMessageBodyReader { + public ErroneousJacksonBasicMessageBodyReader() { + super(new ObjectMapper()); + } + + @Override + public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + throw new IllegalStateException("should never be called"); + } + } + public static class CustomClientHeadersFactory implements ClientHeadersFactory { private final String value; diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java index 72a269f62e419..26af7a3155e4e 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/ConfigurationImpl.java @@ -280,6 +280,9 @@ private void register(Object component, Integer priority) { resourceReader .setMediaTypeStrings( consumes != null ? Arrays.asList(consumes.value()) : WILDCARD_STRING_LIST); + if (priority != null) { + resourceReader.setPriority(priority); + } Type[] args = Types.findParameterizedTypes(componentClass, MessageBodyReader.class); resourceReaders.add(args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class, resourceReader); @@ -298,6 +301,9 @@ private void register(Object component, Integer priority) { resourceWriter .setMediaTypeStrings( produces != null ? Arrays.asList(produces.value()) : WILDCARD_STRING_LIST); + if (priority != null) { + resourceWriter.setPriority(priority); + } Type[] args = Types.findParameterizedTypes(componentClass, MessageBodyWriter.class); resourceWriters.add(args != null && args.length == 1 ? Types.getRawType(args[0]) : Object.class, resourceWriter);