Skip to content

Commit

Permalink
Properly take @ClientExceptionMapper priority into account
Browse files Browse the repository at this point in the history
Fixes: #23396
  • Loading branch information
geoand committed Feb 3, 2022
1 parent 047180b commit 058a3e1
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 058a3e1

Please sign in to comment.