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 usage fails with native when e.g. ContainerResponseFilter is used #42537

Closed
alesj opened this issue Aug 14, 2024 · 9 comments · Fixed by #42754
Closed

REST usage fails with native when e.g. ContainerResponseFilter is used #42537

alesj opened this issue Aug 14, 2024 · 9 comments · Fixed by #42754
Labels
area/native-image kind/bug Something isn't working
Milestone

Comments

@alesj
Copy link
Contributor

alesj commented Aug 14, 2024

Describe the bug

ClassLoader cannot find the REST endpoint class

Caused by: java.lang.NoSuchMethodException: com.alesj.qcl.app.HelloService.dto()
	at java.base@21.0.1/java.lang.Class.checkMethod(DynamicHub.java:1065)
	at java.base@21.0.1/java.lang.Class.getMethod(DynamicHub.java:1050)
	at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:79)

Expected behavior

Endpoint class should be found.

Actual behavior

See description.

How to Reproduce?

Use this repo / branch, see README

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.13.2

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

https://gist.github.com/alesj/7bc3f4737a2f32c4dcaa98bf3c5543cd

If you add @RegisterForReflection to REST endpoint class, it works.

@alesj alesj added the kind/bug Something isn't working label Aug 14, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 14, 2024

/cc @zakkak (native-image)

@alesj
Copy link
Contributor Author

alesj commented Aug 14, 2024

@FroMage @geoand ^^

@krisgerhard
Copy link

I'm seeing the same, only in native, 3.12.3 is working fine, 3.13.0 (and CR) onwards results in NoSuchMethodException

@geoand
Copy link
Contributor

geoand commented Aug 16, 2024 via email

@krisgerhard
Copy link

krisgerhard commented Aug 16, 2024

@geoand
The sample that @alesj provided indeed does not work with 3.12.

My usecase was a little different.

  • 3.12.3 works
  • 3.13.0+ works in JVM mode
  • 3.13.0+ does not work in native
  • 3.13.0+ works in native when adding @RegisterForReflection on rest endpoint class

My filter:

package com.xyz

import jakarta.annotation.Priority
import jakarta.ws.rs.Priorities.AUTHENTICATION
import jakarta.ws.rs.container.ContainerRequestContext
import jakarta.ws.rs.container.ContainerRequestFilter
import jakarta.ws.rs.container.ResourceInfo
import jakarta.ws.rs.core.Context
import jakarta.ws.rs.core.Response
import jakarta.ws.rs.core.Response.Status.UNAVAILABLE_FOR_LEGAL_REASONS
import jakarta.ws.rs.ext.Provider

@Provider
@Priority(AUTHENTICATION)
@AllowNoProfile
class ProfileFilter : ContainerRequestFilter {

  @Context
  lateinit var resourceInfo: ResourceInfo

  override fun filter(context: ContainerRequestContext) {
    val userUid = context.securityContext.userPrincipal?.name ?: return
    if (resourceInfo.resourceClass.getAnnotation(AllowNoProfile::class.java) != null ||
      resourceInfo.resourceMethod.getAnnotation(AllowNoProfile::class.java) != null
    ) return

    if (userUid === "foobar") {
      context.abortWith(Response.status(UNAVAILABLE_FOR_LEGAL_REASONS).build())
    }
  }
}

Stacktrace (removed sensitive parts, ProfileFilter line references are wrong - exception is thrown when accessing resourceMethod):

at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:84)
--
at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getResourceMethod(ResteasyReactiveResourceInfo.java:115)
at jakarta.ws.rs.container.ContextProducers_ProducerMethod_resourceInfo_O6EVLN_c9nIaKY9TO6cnD-zx-3c_ClientProxy.getResourceMethod(Unknown Source)
at com.xyz.ProfileFilter.hasAnnotation(ProfileFilter.kt:43)
at com.xyz.ProfileFilter.filter(ProfileFilter.kt:33)
at org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler.handle(ResourceRequestFilterHandler.java:48)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:131)
at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:635)
at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base@21.0.4/java.lang.Thread.runWith(Thread.java:1596)
at java.base@21.0.4/java.lang.Thread.run(Thread.java:1583)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:896)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:872)

Caused by: java.lang.NoSuchMethodException: com.xyz.MyResource.getXyz(jakarta.ws.rs.core.SecurityContext, int)
at java.base@21.0.4/java.lang.Class.checkMethod(DynamicHub.java:1078)
at java.base@21.0.4/java.lang.Class.getMethod(DynamicHub.java:1063)
at org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo.getMethod(ResteasyReactiveResourceInfo.java:79)
... 18 more

@gsmet
Copy link
Member

gsmet commented Aug 17, 2024

@geoand shouldn't we register the resource methods for reflection when we have ResourceInfo injected somewhere?

@FroMage
Copy link
Member

FroMage commented Aug 22, 2024

Probably, but that would mean every resource class/method, since we can't know which one is affected.

Reminds me that we had custom MessageBodyWriter/Reader classes to avoid registering reflection just to get annotations, but I don't think we have any support for filters to obtain annotations without reflection.

@geoand
Copy link
Contributor

geoand commented Aug 22, 2024

We need to see what changed and caused this.

We have tried hard to avoid registering everything for reflection unconditionally, so I would only go down that route if there is no other way

@geoand
Copy link
Contributor

geoand commented Aug 26, 2024

@krisgerhard your case is indeed different than the one @alesj mentions. Can you please open a new issue and also attach a sample application I can use to quickly reproduce the problem?

Thanks.

geoand added a commit to geoand/quarkus that referenced this issue Aug 26, 2024
… exists

This is needed because those filters can call
setEntityStream which then forces the use of the
slow path for calling writers

Closes: quarkusio#42537
geoand added a commit to geoand/quarkus that referenced this issue Aug 27, 2024
… exists

This is needed because those filters can call
setEntityStream which then forces the use of the
slow path for calling writers

Closes: quarkusio#42537
geoand added a commit that referenced this issue Aug 27, 2024
Register resource classes for reflection when ContainerResponseFilter exists
@quarkus-bot quarkus-bot bot added this to the 3.16 - main milestone Aug 27, 2024
@gsmet gsmet modified the milestones: 3.16 - main, 3.14.1 Aug 27, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 27, 2024
… exists

This is needed because those filters can call
setEntityStream which then forces the use of the
slow path for calling writers

Closes: quarkusio#42537
(cherry picked from commit 2a050f7)
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
… exists

This is needed because those filters can call
setEntityStream which then forces the use of the
slow path for calling writers

Closes: quarkusio#42537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/native-image kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants