Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest Client Reactive - support for sub-resources #16404

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public MaybeRestClientInterface createClientProxy(ClassInfo classInfo,
List<ResourceMethod> methods = createEndpoints(classInfo, classInfo, new HashSet<>(),
clazz.getPathParameters());
clazz.getMethods().addAll(methods);

return MaybeRestClientInterface.success(clazz);
} catch (Exception e) {
//kinda bogus, but we just ignore failed interfaces for now
Expand All @@ -78,6 +79,17 @@ public MaybeRestClientInterface createClientProxy(ClassInfo classInfo,
}
}

@Override
protected void handleClientSubResource(ResourceMethod resourceMethod, MethodInfo method, IndexView index) {
ClassInfo subResourceClass = index.getClassByName(method.returnType().name());
if (subResourceClass == null) {
throw new IllegalStateException("Subresource method returns an invalid type: " + method.returnType().name());
}

List<ResourceMethod> endpoints = createEndpoints(subResourceClass, subResourceClass, new HashSet<>(), new HashSet<>());
resourceMethod.setSubResourceMethods(endpoints);
}

@Override
protected ResourceMethod createResourceMethod(MethodInfo info, ClassInfo actualEndpointClass,
Map<String, Object> methodContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
public interface JaxrsClientReactiveEnricher {
/**
* Class-level alterations
*
* Used by MicroProfile Rest Client implementation (quarkus-rest-client-reactive) to support
* {@link javax.ws.rs.ext.Provider}, {@code @ClientHeadersFactory}, etc
*
* Please note that this won't be invoked for sub-resources
*
* @param ctor jaxrs client constructor
* @param globalTarget WebTarget field of the jaxrs client
Expand All @@ -33,15 +38,38 @@ void forClass(MethodCreator ctor, AssignableResultHandle globalTarget,
* @param methodCreator the method that is being generated, e.g. a method corresponding to `@GET Response get()`
* @param interfaceClass JAXRS-annotated interface for which the client is being generated
* @param method jandex method object corresponding to the method
* @param methodWebTarget method-level WebTarget
* @param invocationBuilder assignable reference for Invocation.Builder
* @param index jandex index
* @param generatedClasses build producer used to generate classes. Used e.g. to generate classes for header filling
* @param methodIndex 0-based index of the method in the class. Used to assure there is no clash in generating classes
* @return customizer for Invocation.Builder
* @param methodIndex 0-based index of the method in the interface. Used to assure there is no clash in generating classes
*/
void forMethod(ClassCreator classCreator, MethodCreator constructor, MethodCreator methodCreator,
ClassInfo interfaceClass, MethodInfo method,
AssignableResultHandle invocationBuilder, IndexView index,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
int methodIndex);
void forMethod(ClassCreator classCreator, MethodCreator constructor,
MethodCreator clinit,
MethodCreator methodCreator,
ClassInfo interfaceClass,
MethodInfo method, AssignableResultHandle invocationBuilder,
IndexView index, BuildProducer<GeneratedClassBuildItem> generatedClasses, int methodIndex);

/**
* Method-level alterations for methods of sub-resources
*
* @param subClassCreator creator of the sub-resource stub class
* @param subConstructor constructor of the sub-resource stub class
* @param subMethodCreator the method that is being generated
* @param rootInterfaceClass root JAX-RS interface for which the client is being generated
* @param subInterfaceClass sub-resource JAX-RS interface for which the client is being generated
* @param subMethod jandex method object corresponding to the current sub-resource method
* @param rootMethod jandex method object corresponding to the current root resource method
* @param invocationBuilder Invocation.Builder's assignable reference. Local for subMethod
* @param index jandex index
* @param generatedClasses build producer used to generate classes
* @param methodIndex 0-based index of method in the root interface
* @param subMethodIndex index of the method in the sub-resource interface
*/
void forSubResourceMethod(ClassCreator subClassCreator, MethodCreator subConstructor,
MethodCreator subClinit,
MethodCreator subMethodCreator, ClassInfo rootInterfaceClass, ClassInfo subInterfaceClass,
MethodInfo subMethod, MethodInfo rootMethod, AssignableResultHandle invocationBuilder, // sub-level
IndexView index, BuildProducer<GeneratedClassBuildItem> generatedClasses,
int methodIndex, int subMethodIndex);
}