Skip to content

Commit

Permalink
Fix @BeanParam handling during hot reload
Browse files Browse the repository at this point in the history
Fixes: #45625
  • Loading branch information
geoand committed Jan 20, 2025
1 parent da144fe commit 3a60175
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.resteasy.reactive.server.test.beanparam;

import static io.restassured.RestAssured.when;
import static org.hamcrest.CoreMatchers.is;

import java.util.function.Supplier;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

public class BeanParamRecordDevModeTest {

@RegisterExtension
static QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClasses(FirstAndSecondResource.class,
FirstAndSecondResource.Param.class);
}
});

@Test
void test() {
when().get("fs/foo/bar")
.then()
.statusCode(200)
.body(is("foo-bar"));

TEST.modifySourceFile(FirstAndSecondResource.class, (orig) -> orig.replace("-", "#"));

when().get("fs/foo/bar")
.then()
.statusCode(200)
.body(is("foo#bar"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.resteasy.reactive.server.test.beanparam;

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

import org.jboss.resteasy.reactive.RestPath;

@Path("fs")
public class FirstAndSecondResource {

@Path("{first}/{second}")
@GET
public String firstAndSecond(Param param) {
return param.first() + "-" + param.second();
}

public record Param(@RestPath String first, @RestPath String second) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
import org.jboss.resteasy.reactive.server.injection.ResteasyReactiveInjectionContext;
Expand All @@ -13,8 +12,8 @@ public class RecordBeanParamExtractor implements ParameterExtractor {

public RecordBeanParamExtractor(Class<?> target) {
try {
factoryMethod = MethodHandles.lookup().findStatic(target, "__quarkus_rest_inject",
MethodType.methodType(target, ResteasyReactiveInjectionContext.class));
factoryMethod = MethodHandles.lookup()
.unreflect(target.getMethod("__quarkus_rest_inject", ResteasyReactiveInjectionContext.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException("Failed to find target generated factory method on record @BeanParam type", e);
}
Expand All @@ -27,7 +26,6 @@ public Object extractParameter(ResteasyReactiveRequestContext context) {
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException("Failed to invoke generated factory method on record @BeanParam type", e);
}
}
Expand Down

0 comments on commit 3a60175

Please sign in to comment.