Skip to content

Commit

Permalink
Merge pull request quarkusio#40040 from mkouba/issue-39971
Browse files Browse the repository at this point in the history
Qute: do not register TemplateInstance as non-blocking type by default
  • Loading branch information
geoand authored Apr 12, 2024
2 parents 744caa4 + dcb586e commit c7748a5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.resteasy.reactive.qute.deployment;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.rest.qute")
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public interface RestQuteConfig {

/**
* If set to {@code true} then the {@link io.quarkus.qute.TemplateInstance} is registered as a non-blocking return type for
* JAX-RS resource methods.
*
* @deprecated This config item will be removed at some time after Quarkus 3.16
*/
@Deprecated(forRemoval = true, since = "3.10")
@WithDefault("false")
boolean templateInstanceNonBlockingType();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jboss.resteasy.reactive.server.processor.scanning.MethodScanner;

import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyIgnoreWarningBuildItem;
Expand Down Expand Up @@ -49,8 +50,10 @@ ReflectiveHierarchyIgnoreWarningBuildItem ignoreReflectiveWarning() {
}

@BuildStep
NonBlockingReturnTypeBuildItem nonBlockingTemplateInstance() {
return new NonBlockingReturnTypeBuildItem(TEMPLATE_INSTANCE);
void nonBlockingTemplateInstance(RestQuteConfig config, BuildProducer<NonBlockingReturnTypeBuildItem> nonBlockingType) {
if (config.templateInstanceNonBlockingType()) {
nonBlockingType.produce(new NonBlockingReturnTypeBuildItem(TEMPLATE_INSTANCE));
}
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.resteasy.reactive.qute.deployment;

import static io.restassured.RestAssured.when;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.runtime.BlockingOperationControl;
import io.quarkus.test.QuarkusUnitTest;

public class TemplateInstanceNonBlockingEnabledTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestResource.class)
.addAsResource(new StringAsset("quarkus.rest.qute.template-instance-non-blocking-type=true"),
"application.properties")
.addAsResource(new StringAsset("Blocking allowed: {blockingAllowed}"), "templates/item.txt"));

@Test
public void test() {
when().get("/test").then().statusCode(200).body(Matchers.is("Blocking allowed: false"));
}

@Path("test")
public static class TestResource {

@Inject
Template item;

@GET
@Produces(MediaType.TEXT_PLAIN)
public TemplateInstance get() {
return item.data("blockingAllowed", BlockingOperationControl.isBlockingAllowed());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.resteasy.reactive.qute.deployment;

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

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand Down Expand Up @@ -29,7 +28,7 @@ public class TemplateInstanceNonBlockingTest {

@Test
public void test() {
when().get("/test").then().statusCode(200).body(Matchers.is("Blocking allowed: false"));
when().get("/test").then().statusCode(200).body(Matchers.is("Blocking allowed: true"));
}

@Path("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

/**
* Register a type as non-blocking by default when used as a return type of JAX-RS Resource
*
* @deprecated This build item will be removed at some time after Quarkus 3.16
*/
@Deprecated(forRemoval = true, since = "3.10")
public final class NonBlockingReturnTypeBuildItem extends MultiBuildItem {

private final DotName type;
Expand Down

0 comments on commit c7748a5

Please sign in to comment.