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

Properly handle @Blocking on an JAX-RS Application class #14400

Merged
merged 1 commit into from
Jan 19, 2021
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
Expand Up @@ -291,7 +291,8 @@ public void setupEndpoints(Capabilities capabilities, BeanArchiveIndexBuildItem
config.inputBufferSize.asLongValue(), config.singleDefaultProduces, config.defaultProduces))
.setAdditionalReaders(additionalReaders)
.setHttpAnnotationToMethod(result.getHttpAnnotationToMethod())
.setInjectableBeans(injectableBeans).setAdditionalWriters(additionalWriters)
.setInjectableBeans(injectableBeans)
.setAdditionalWriters(additionalWriters)
.setDefaultBlocking(appResult.isBlocking())
.setHasRuntimeConverters(!paramConverterProviders.getParamConverterProviders().isEmpty())
.setClassLevelExceptionMappers(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.quarkus.resteasy.reactive.server.test.simple;

import java.util.function.Supplier;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;

import org.hamcrest.Matchers;
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.QuarkusUnitTest;
import io.restassured.RestAssured;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.common.annotation.NonBlocking;

public class ApplicationWithBlockingTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(BlockingApplication.class, ThreadNameResource.class);
}
});

@Test
public void test() {
RestAssured.get("/tname/blocking")
.then().body(Matchers.containsString("executor"), Matchers.not(Matchers.containsString("loop")));

RestAssured.get("/tname/nonblocking")
.then().body(Matchers.containsString("loop"), Matchers.not(Matchers.containsString("executor")));
}

@Blocking
public static class BlockingApplication extends Application {

}

@Path("tname")
public static class ThreadNameResource {

@Path("blocking")
@GET
public String threadName() {
return Thread.currentThread().getName();
}

@NonBlocking
@Path("nonblocking")
@GET
public String nonBlocking() {
return Thread.currentThread().getName();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LONG;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MATRIX_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.NON_BLOCKING;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH_SEGMENT;
Expand Down Expand Up @@ -438,11 +439,11 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
boolean blocking = defaultBlocking;
AnnotationInstance blockingAnnotation = getInheritableAnnotation(info, BLOCKING);
if (blockingAnnotation != null) {
AnnotationValue value = blockingAnnotation.value();
if (value != null) {
blocking = value.asBoolean();
} else {
blocking = true;
blocking = true;
} else {
AnnotationInstance nonBlockingAnnotation = getInheritableAnnotation(info, NON_BLOCKING);
if (nonBlockingAnnotation != null) {
blocking = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public static ApplicationScanningResult scanForApplicationClass(IndexView index)
| InvocationTargetException e) {
throw new RuntimeException("Unable to handle class: " + applicationClass, e);
}
if (applicationClassInfo.classAnnotation(ResteasyReactiveDotNames.NON_BLOCKING) != null) {
blocking = false;
} else if (applicationClassInfo.classAnnotation(ResteasyReactiveDotNames.NON_BLOCKING) != null) {
if (applicationClassInfo.classAnnotation(ResteasyReactiveDotNames.BLOCKING) != null) {
blocking = true;
} else if (applicationClassInfo.classAnnotation(ResteasyReactiveDotNames.NON_BLOCKING) != null) {
blocking = false;
}
}
if (selectedAppClass != null) {
Expand Down