From ede25f81f9a8e0577cbe6a589b26c22f034eb25f Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 24 Feb 2022 09:42:29 +0200 Subject: [PATCH] Make sure @ClientExceptionMapper works properly in native mode Fixes: #23766 --- .../deployment/RestClientReactiveProcessor.java | 2 ++ .../io/quarkus/it/rest/client/main/HelloClient.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java index d89ff314009a4..f3d03f6d60f68 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java @@ -224,6 +224,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, BuildProducer generatedBeans, BuildProducer generatedClasses, BuildProducer unremovableBeans, + BuildProducer reflectiveClasses, RestClientReactiveConfig clientConfig) { String annotationRegisteredProvidersImpl = AnnotationRegisteredProviders.class.getName() + "Implementation"; IndexView index = indexBuildItem.getIndex(); @@ -292,6 +293,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, + "' is allowed per REST Client interface. Offending class is '" + result.interfaceName + "'"); } ifaceToGeneratedMapper.put(result.interfaceName, result); + reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, false, false, result.generatedClassName)); } for (Map.Entry> annotationsForClass : annotationsByClassName.entrySet()) { diff --git a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/HelloClient.java b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/HelloClient.java index 63be74430fa58..bc09e13d357ac 100644 --- a/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/HelloClient.java +++ b/integration-tests/rest-client-reactive/src/main/java/io/quarkus/it/rest/client/main/HelloClient.java @@ -1,11 +1,15 @@ package io.quarkus.it.rest.client.main; import javax.ws.rs.Consumes; +import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import io.quarkus.rest.client.reactive.ClientExceptionMapper; @Path("") public interface HelloClient { @@ -13,4 +17,13 @@ public interface HelloClient { @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.TEXT_PLAIN) String greeting(String name, @QueryParam("count") int count); + + // this isn't used, but it makes sure that the generated provider can be properly instantiated in native mode + @ClientExceptionMapper + static RuntimeException toException(Response response) { + if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { + return new NotFoundException("not found"); + } + return null; + } }