Quarkus extension with resteasy reactive client

478 views Asked by At

I am writing a Quarkus extension that servers some endpoints. ı am using quarkus-resteasy-reactive-jsonb for my endpoints. But registering endpoints like regular beans is not working, yes I can inject the endpoint class and call the methods but calling the endpoint from postman, curl etc is not working and returning 404. I believe I need to change registration of my endpoints but how. current registration is ike this:

@BuildStep
    void registerBeans(BuildProducer<AdditionalBeanBuildItem> beans) {
        beans.produce(AdditionalBeanBuildItem.builder()
                .addBeanClasses(TestController.class)
                .build());
    }

following this document is working: https://quarkus.io/guides/building-my-first-extension

but I do not want to use servlets

edit: This is TestController.

@Path("/test")
public class TestController {  
    @GET
    public Response doGet() {
        return Response.ok().entity("OK").build();
    }
}
3

There are 3 answers

0
Sebastian Daschner On BEST ANSWER

You need to make sure that your dependencies in your Quarkus extension project match the used Quarkus extensions.

I've created a small demo that should do a similar thing that you're doing, here: https://github.com/sdaschner/blink-extension/tree/resteasy

@BuildStep
AdditionalBeanBuildItem createTestResource() {
    return new AdditionalBeanBuildItem(TestResource.class);
}

In the deployment project:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-resteasy-deployment</artifactId>
</dependency>

(for you this might be quarkus-resteasy-reactive-deployment)

In the runtime project:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-resteasy</artifactId>
</dependency>

Also usually Quarkus tells you when there are some unsatisfied dependencies, when you're trying to mvn clean install your extension project.

0
Herr Derb On

I did struggle with this too.

The solution was to add the controller as AdditionalBeanBuildItem AND AdditionalIndexedClassesBuildItem

This way, the controller is registered as expected and is reachable.

@BuildStep
public void addController(
        BuildProducer<AdditionalBeanBuildItem> additionalBeans,
        BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses) {
    additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(MyController.class));
    additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(MyController.class.getName()));
}
0
Dyutiman Chaudhuri On

The above solution works with 'quarkus-resteasy' artifactId, but not with 'quarkus-resteasy-reactive' or 'quarkus-resteasy-reactive-jackson'.

To make it work with other reasteasy artifacts we need to introduce 'AdditionalResourceClassBuildItem'.

First of all the artifact in pom.xml under deployment should have *-deployment (quarkus-resteasy-reactive-deployment or quarkus-resteasy-reactive-jackson-deployment).

Then a new BuildStep needs to be added as follow:

@BuildStep
void registerRestResource(CombinedIndexBuildItem index,
              BuildProducer<AdditionalResourceClassBuildItem> additionalResourceClassProducer) {
    DotName path = DotName.createSimple(Path.class.getName());
    for (AnnotationInstance restController : index.getIndex().getAnnotations(path)) {
        AnnotationTarget annotTarget  = restController.target();
        if(AnnotationTarget.Kind.CLASS.equals(annotTarget.kind())) {
            ClassInfo targetClass = restController.target().asClass();
            String singlePath = restController.value("value").value().toString();
            additionalResourceClassProducer.produce(new AdditionalResourceClassBuildItem(targetClass, singlePath));
        }
    }
}

And the jandex-maven-plugin needs to be added in the pom.xml of runtime module of the extension.

  <plugin>
    <groupId>io.smallrye</groupId>
    <artifactId>jandex-maven-plugin</artifactId>
    <version>3.1.3</version>
    <executions>
      <execution>
        <id>make-index</id>
        <goals>
          <goal>jandex</goal>
        </goals>
      </execution>
    </executions>
  </plugin>