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

Allow to register JAX-RS endpoints generated by extensions #36151

Closed
dyutiman opened this issue Sep 26, 2023 · 8 comments
Closed

Allow to register JAX-RS endpoints generated by extensions #36151

dyutiman opened this issue Sep 26, 2023 · 8 comments
Labels
kind/question Further information is requested

Comments

@dyutiman
Copy link

Description

The JAX-RS resource produced by a Quarkus extension is not registered when using quarkus-resteasy-reactive or quarkus-resteasy-reactive-jackson.

The same is working with just quarkus-resteasy.

Implementation ideas

No response

@dyutiman dyutiman added the kind/enhancement New feature or request label Sep 26, 2023
@geoand
Copy link
Contributor

geoand commented Sep 26, 2023

Can you elaborate a little more on this please?

@geoand geoand added kind/question Further information is requested and removed kind/enhancement New feature or request triage/needs-triage labels Sep 26, 2023
@dyutiman
Copy link
Author

dyutiman commented Sep 26, 2023

I created a very simple extension to expose one JAX-RS enpoint

package com.dyutiman.rest.extension.runtime;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/dummy")
public class DummyResource {

    @GET
    public String get() {
        return "My resource called";
    }
}

And I have used 'quarkus-resteasy' artifactId in my pom.xml under runtime and 'quarkus-resteasy-deployment' in deployment. I created the BuildStep to include this class.

@BuildStep
  AdditionalBeanBuildItem resource() {
      return new AdditionalBeanBuildItem(DummyResource.class);
  }

This is exposed perfectly when I use the extension in my project.

But, instead of 'quarkus-resteasy' and 'quarkus-resteasy-deployment', if I use 'quarkus-resteasy-reactive' and 'quarkus-resteasy-reactive-deployment' or 'quarkus-resteasy-reactive-jackson' and 'quarkus-resteasy-reactive-jackson-deployment', the endpoint does not work anymore.

Do I have to use a different BuildItem for this?

@geoand
Copy link
Contributor

geoand commented Sep 26, 2023

Try using AdditionalResourceClassBuildItem

@dyutiman
Copy link
Author

dyutiman commented Sep 26, 2023

Thanks for the reply. I tried the below BuildStep, but my class is not recognised.

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

Do I have to make anything for my class to be included in CombinedIndexBuildItem?

@geoand
Copy link
Contributor

geoand commented Sep 26, 2023

Do I have to make anything for my class to be included in CombinedIndexBuildItem?

Nope. We use AdditionalResourceClassBuildItem in our code base and it works as expected

@dyutiman
Copy link
Author

Just to confirm my @path class belongs to the runtime module of my extension. I hope this is fine.

@dyutiman
Copy link
Author

dyutiman commented Sep 26, 2023

Well, it started working after I added the jandex-maven-plugin to my runtime pom.xml.

<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>

Thanks @geoand for your help on AdditionalResourceClassBuildItem!

@geoand
Copy link
Contributor

geoand commented Sep 26, 2023

👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants