Skip to content

Commit

Permalink
Merge pull request quarkusio#14400 from geoand/quarkusio#14397
Browse files Browse the repository at this point in the history
Properly handle @Blocking on an JAX-RS Application class
  • Loading branch information
geoand authored Jan 19, 2021
2 parents 7302112 + 006e15d commit be84d92
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
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

0 comments on commit be84d92

Please sign in to comment.