Skip to content

Commit

Permalink
Take priority into account in ConfigurationImpl
Browse files Browse the repository at this point in the history
This is necessary for REST Client
MessageBodyReader and MessageBodyWriter
registration

(cherry picked from commit e7fcd32)
  • Loading branch information
geoand authored and gsmet committed Dec 18, 2023
1 parent aa99a21 commit ad057b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -78,6 +89,7 @@ public Map<String, List<String>> callClient(String uri) {
}
}

@RegisterProvider(ErroneousJacksonBasicMessageBodyReader.class)
public interface Client {
@GET
Map<String, List<String>> get();
Expand All @@ -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<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
throw new IllegalStateException("should never be called");
}
}

public static class CustomClientHeadersFactory implements ClientHeadersFactory {

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit ad057b6

Please sign in to comment.