diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/ClientExceptionMapperHandler.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/ClientExceptionMapperHandler.java index cd2dcb8675ec0..d21ea09b4af02 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/ClientExceptionMapperHandler.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/ClientExceptionMapperHandler.java @@ -8,6 +8,7 @@ import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; +import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.Type; @@ -82,26 +83,34 @@ Result generateResponseExceptionMapper(AnnotationInstance instance) { for (Type i : targetMethod.parameters()) { sigBuilder.append(i.name().toString()); } + + int priority = Priorities.USER; + AnnotationValue priorityAnnotationValue = instance.value("priority"); + if (priorityAnnotationValue != null) { + priority = priorityAnnotationValue.asInt(); + } + ClassInfo restClientInterfaceClassInfo = targetMethod.declaringClass(); String generatedClassName = restClientInterfaceClassInfo.name().toString() + "_" + targetMethod.name() + "_" + "ResponseExceptionMapper" + "_" + HashUtil.sha1(sigBuilder.toString()); try (ClassCreator cc = ClassCreator.builder().classOutput(classOutput).className(generatedClassName) .interfaces(ResponseExceptionMapper.class).build()) { - MethodCreator mc = cc.getMethodCreator("toThrowable", Throwable.class, Response.class); - ResultHandle resultHandle = mc.invokeStaticInterfaceMethod( + MethodCreator toThrowable = cc.getMethodCreator("toThrowable", Throwable.class, Response.class); + ResultHandle resultHandle = toThrowable.invokeStaticInterfaceMethod( MethodDescriptor.ofMethod( restClientInterfaceClassInfo.name().toString(), targetMethod.name(), targetMethod.returnType().name().toString(), targetMethod.parameters().get(0).name().toString()), - mc.getMethodParam(0)); - mc.returnValue(resultHandle); - } + toThrowable.getMethodParam(0)); + toThrowable.returnValue(resultHandle); - int priority = Priorities.USER; - if (instance.value() != null) { - priority = instance.value().asInt(); + if (priority != Priorities.USER) { + MethodCreator getPriority = cc.getMethodCreator("getPriority", int.class); + getPriority.returnValue(getPriority.load(priority)); + } } + return new Result(restClientInterfaceClassInfo.name().toString(), generatedClassName, priority); } diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/error/clientexceptionmapper/RegisteredClientExceptionMapperTest.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/error/clientexceptionmapper/RegisteredClientExceptionMapperTest.java index 9ff77d94c1943..81fdcee50add0 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/error/clientexceptionmapper/RegisteredClientExceptionMapperTest.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/error/clientexceptionmapper/RegisteredClientExceptionMapperTest.java @@ -32,7 +32,8 @@ public class RegisteredClientExceptionMapperTest { .addAsResource( new StringAsset(setUrlForClass(ClientNoProviders.class) + setUrlForClass(ClientWithRegisteredLowPriorityMapper.class) - + setUrlForClass(ClientWithRegisteredHighPriorityMapper.class)), + + setUrlForClass(ClientWithRegisteredHighPriorityMapper.class) + + setUrlForClass(ClientWithRegisteredHighPriorityMapperAndSetPriority.class)), "application.properties")); @RestClient @@ -44,6 +45,9 @@ public class RegisteredClientExceptionMapperTest { @RestClient ClientWithRegisteredHighPriorityMapper clientWithRegisteredHighPriorityMapper; + @RestClient + ClientWithRegisteredHighPriorityMapperAndSetPriority clientWithRegisteredHighPriorityMapperAndSetPriority; + @BeforeEach void setUp() { DummyException.executionCount.set(0); @@ -77,8 +81,8 @@ void customExceptionMapperDotNotEngageWhenRegisteredExceptionMapperHasHigherPrio @Test void customExceptionMapperEngagesWhenRegisteredExceptionMapperHasHigherPriority() { - assertThrows(DummyException3.class, clientWithRegisteredHighPriorityMapper::get404); - assertThat(DummyException3.executionCount.get()).isEqualTo(1); + assertThrows(DummyException.class, clientWithRegisteredHighPriorityMapperAndSetPriority::get404); + assertThat(DummyException.executionCount.get()).isEqualTo(1); } @Path("/error")