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

Fix @BeanParam handling during hot reload #45707

Merged
merged 2 commits into from
Jan 20, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,19 +2,18 @@

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;

public class RecordBeanParamExtractor implements ParameterExtractor {

private MethodHandle factoryMethod;
private final MethodHandle factoryMethod;

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
Loading