Skip to content

Commit 3aee9de

Browse files
committed
Fixes #4520
1 parent d171c19 commit 3aee9de

File tree

14 files changed

+321
-255
lines changed

14 files changed

+321
-255
lines changed

bom/runtime/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<microprofile-context-propagation.version>1.0.1</microprofile-context-propagation.version>
3131
<microprofile-opentracing-api.version>1.3.1</microprofile-opentracing-api.version>
3232
<microprofile-reactive-streams-operators.version>1.0</microprofile-reactive-streams-operators.version>
33-
<microprofile-rest-client.version>1.3.3</microprofile-rest-client.version>
33+
<microprofile-rest-client.version>1.3.4</microprofile-rest-client.version>
3434
<smallrye-config.version>1.3.9</smallrye-config.version>
3535
<smallrye-health.version>2.1.0</smallrye-health.version>
3636
<smallrye-metrics.version>2.2.0</smallrye-metrics.version>

build-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<microprofile-metrics-api.version>2.1.0</microprofile-metrics-api.version>
6262
<microprofile-fault-tolerance-api.version>2.0.2</microprofile-fault-tolerance-api.version>
6363
<microprofile-reactive-messaging-api.version>1.0</microprofile-reactive-messaging-api.version>
64-
<microprofile-rest-client-api.version>1.2.1</microprofile-rest-client-api.version>
64+
<microprofile-rest-client-api.version>1.3.4</microprofile-rest-client-api.version>
6565
<microprofile-open-api.version>1.1.2</microprofile-open-api.version>
6666
<microprofile-opentracing-api.version>1.3.1</microprofile-opentracing-api.version>
6767
<microprofile-context-propagation.version>1.0.1</microprofile-context-propagation.version>

extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,9 @@ void processInterfaces(CombinedIndexBuildItem combinedIndexBuildItem,
138138
Set<Type> returnTypes = new HashSet<>();
139139

140140
IndexView index = combinedIndexBuildItem.getIndex();
141-
for (AnnotationInstance annotation : index.getAnnotations(PATH)) {
142-
AnnotationTarget target = annotation.target();
143-
ClassInfo theInfo;
144-
if (target.kind() == AnnotationTarget.Kind.CLASS) {
145-
theInfo = target.asClass();
146-
} else if (target.kind() == AnnotationTarget.Kind.METHOD) {
147-
theInfo = target.asMethod().declaringClass();
148-
} else {
149-
continue;
150-
}
151-
152-
if (!isRestClientInterface(index, theInfo)) {
153-
continue;
154-
}
155141

156-
interfaces.put(theInfo.name(), theInfo);
157-
158-
// Find Return types
159-
for (MethodInfo method : theInfo.methods()) {
160-
Type type = method.returnType();
161-
if (!type.name().toString().contains("java.lang")) {
162-
if (!returnTypes.contains(type)) {
163-
returnTypes.add(type);
164-
}
165-
}
166-
}
167-
}
142+
findInterfaces(index, interfaces, returnTypes, REGISTER_REST_CLIENT);
143+
findInterfaces(index, interfaces, returnTypes, PATH);
168144

169145
if (interfaces.isEmpty()) {
170146
return;
@@ -207,16 +183,17 @@ public void register(RegistrationContext registrationContext) {
207183
// The spec is not clear whether we should add superinterfaces too - let's keep aligned with SmallRye for now
208184
configurator.addType(restClientName);
209185
configurator.addQualifier(REST_CLIENT);
210-
final ScopeInfo scope = computeDefaultScope(config, entry);
186+
final String configPrefix = computeConfigPrefix(restClientName.toString(), entry.getValue());
187+
final ScopeInfo scope = computeDefaultScope(config, entry, configPrefix);
211188
configurator.scope(scope);
212189
configurator.creator(m -> {
213190
// return new RestClientBase(proxyType, baseUri).create();
214191
ResultHandle interfaceHandle = m.loadClass(restClientName.toString());
215192
ResultHandle baseUriHandle = m.load(getAnnotationParameter(entry.getValue(), "baseUri"));
216-
ResultHandle configKeyHandle = m.load(getAnnotationParameter(entry.getValue(), "configKey"));
193+
ResultHandle configPrefixHandle = m.load(configPrefix);
217194
ResultHandle baseHandle = m.newInstance(
218195
MethodDescriptor.ofConstructor(RestClientBase.class, Class.class, String.class, String.class),
219-
interfaceHandle, baseUriHandle, configKeyHandle);
196+
interfaceHandle, baseUriHandle, configPrefixHandle);
220197
ResultHandle ret = m.invokeVirtualMethod(
221198
MethodDescriptor.ofMethod(RestClientBase.class, "create", Object.class), baseHandle);
222199
m.returnValue(ret);
@@ -232,13 +209,62 @@ public void register(RegistrationContext registrationContext) {
232209
restClientRecorder.setSslEnabled(sslNativeConfig.isEnabled());
233210
}
234211

235-
private ScopeInfo computeDefaultScope(Config config, Map.Entry<DotName, ClassInfo> entry) {
236-
DotName restClientName = entry.getKey();
212+
private void findInterfaces(IndexView index, Map<DotName, ClassInfo> interfaces, Set<Type> returnTypes,
213+
DotName annotationToFind) {
214+
for (AnnotationInstance annotation : index.getAnnotations(annotationToFind)) {
215+
AnnotationTarget target = annotation.target();
216+
ClassInfo theInfo;
217+
if (target.kind() == AnnotationTarget.Kind.CLASS) {
218+
theInfo = target.asClass();
219+
} else if (target.kind() == AnnotationTarget.Kind.METHOD) {
220+
theInfo = target.asMethod().declaringClass();
221+
} else {
222+
continue;
223+
}
224+
225+
if (!isRestClientInterface(index, theInfo)) {
226+
continue;
227+
}
228+
229+
interfaces.put(theInfo.name(), theInfo);
230+
231+
// Find Return types
232+
processInterfaceReturnTypes(theInfo, returnTypes);
233+
for (Type interfaceType : theInfo.interfaceTypes()) {
234+
ClassInfo interfaceClassInfo = index.getClassByName(interfaceType.name());
235+
if (interfaceClassInfo != null) {
236+
processInterfaceReturnTypes(interfaceClassInfo, returnTypes);
237+
}
238+
}
239+
}
240+
}
241+
242+
private void processInterfaceReturnTypes(ClassInfo classInfo, Set<Type> returnTypes) {
243+
for (MethodInfo method : classInfo.methods()) {
244+
Type type = method.returnType();
245+
if (!type.name().toString().contains("java.lang")) {
246+
if (!returnTypes.contains(type)) {
247+
returnTypes.add(type);
248+
}
249+
}
250+
}
251+
}
252+
253+
private String computeConfigPrefix(String interfaceName, ClassInfo classInfo) {
254+
String propertyPrefixFromAnnotation = getAnnotationParameter(classInfo, "configKey");
255+
256+
if (propertyPrefixFromAnnotation != null && !propertyPrefixFromAnnotation.isEmpty()) {
257+
return propertyPrefixFromAnnotation;
258+
}
259+
260+
return interfaceName;
261+
}
262+
263+
private ScopeInfo computeDefaultScope(Config config, Map.Entry<DotName, ClassInfo> entry, String configPrefix) {
237264
// Initialize a default @Dependent scope as per the spec
238265
ScopeInfo scopeInfo = BuiltinScope.DEPENDENT.getInfo();
239-
final String REST_SCOPE_FORMAT = "%s/" + RestClientBase.MP_REST + "/scope";
240266
final Optional<String> scopeConfig = config
241-
.getOptionalValue(String.format(REST_SCOPE_FORMAT, restClientName.toString()), String.class);
267+
.getOptionalValue(String.format(RestClientBase.REST_SCOPE_FORMAT, configPrefix), String.class);
242268
if (scopeConfig.isPresent()) {
243269
final DotName scope = DotName.createSimple(scopeConfig.get());
244270
final BuiltinScope builtinScope = BuiltinScope.from(scope);
@@ -247,7 +273,7 @@ private ScopeInfo computeDefaultScope(Config config, Map.Entry<DotName, ClassInf
247273
} else {
248274
log.warn(String.format(
249275
"Unsupported default scope %s provided for rest client %s. Defaulting to @Dependent.",
250-
scope, restClientName));
276+
scope, entry.getKey()));
251277
}
252278
} else {
253279
final Set<DotName> annotations = entry.getValue().annotations().keySet();

0 commit comments

Comments
 (0)