Skip to content

Commit

Permalink
Fix misleading error message when REST Client interface has been indexed
Browse files Browse the repository at this point in the history
When a REST Client interface is part of a library or the runtime part
of an extension, it's not uncommon to forget to index the module.
When that happens, we now provide a proper error message.
  • Loading branch information
geoand committed Mar 14, 2024
1 parent 61aaf1f commit 573e595
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jboss.resteasy.reactive.client.impl;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -29,15 +31,45 @@ public <T> T get(Class<?> clazz, WebTarget webTarget, List<ParamConverterProvide
throw new InvalidRestClientDefinitionException(
"Failed to generate client for class " + clazz + " : " + failure);
} else {
throw new IllegalArgumentException("Not a REST client interface: " + clazz + ". No @Path annotation " +
"found on the class or any methods of the interface and no HTTP method annotations " +
"(@POST, @PUT, @GET, @HEAD, @DELETE, etc) found on any of the methods");
if (hasRestClientAnnotations(clazz)) {
throw new IllegalStateException("REST client interface: " + clazz
+ " was not indexed at build time. See https://quarkus.io/guides/cdi-reference#bean_discovery for information on how to index the module that contains it.");
} else {
throw new IllegalArgumentException("Not a REST client interface: " + clazz + ". No @Path annotation " +
"found on the class or any methods of the interface and no HTTP method annotations " +
"(@POST, @PUT, @GET, @HEAD, @DELETE, etc) found on any of the methods");
}
}
}
//noinspection unchecked
return (T) function.apply(webTarget, providers);
}

private boolean hasRestClientAnnotations(Class<?> clazz) {
for (Annotation annotation : clazz.getAnnotations()) {
if (isRestClientAnnotation(annotation)) {
return true;
}
}
for (Method method : clazz.getDeclaredMethods()) {
for (Annotation annotation : method.getDeclaredAnnotations()) {
if (isRestClientAnnotation(annotation)) {
return true;
}
}
}
return false;
}

private boolean isRestClientAnnotation(Annotation annotation) {
String annClassName = annotation.annotationType().getName();
if (annClassName.startsWith("jakarta.ws.rs") || annClassName.startsWith(
"org.eclipse.microprofile.rest.client")) {
return true;
}
return false;
}

// for dev console
public ClientData getClientData() {
return new ClientData(clientProxies.keySet(), failures);
Expand Down

0 comments on commit 573e595

Please sign in to comment.