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

Take priority into account in ConfigurationImpl #37787

Merged
merged 1 commit into from
Dec 18, 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 @@ -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
Loading