Skip to content

Commit

Permalink
Merge pull request #38852 from geoand/#38840
Browse files Browse the repository at this point in the history
Add configuration option for resuming on 404
  • Loading branch information
geoand authored Feb 19, 2024
2 parents a786faf + fe3129c commit 6e85aca
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ public interface ResteasyReactiveConfig {
*/
@WithDefault("true")
boolean failOnDuplicate();

/**
* An advanced option that can be set when they RESTEasy Reactive should NOT reply with 404 when it does not match the URL
* path
* and instead just pass control onto the next Vert.x handler (if any)
*/
@WithDefault("false")
boolean resumeOn404();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1281,10 +1281,12 @@ public void setupDeployment(BeanContainerBuildItem beanContainerBuildItem,
servletPresent = true;
}

boolean resumeOn404 = servletPresent || !resumeOn404Items.isEmpty() || config.resumeOn404();

RuntimeValue<Deployment> deployment = recorder.createDeployment(deploymentInfo,
beanContainerBuildItem.getValue(), shutdownContext, vertxConfig,
requestContextFactoryBuildItem.map(RequestContextFactoryBuildItem::getFactory).orElse(null),
initClassFactory, launchModeBuildItem.getLaunchMode(), servletPresent || !resumeOn404Items.isEmpty());
initClassFactory, launchModeBuildItem.getLaunchMode(), resumeOn404);

quarkusRestDeploymentBuildItemBuildProducer
.produce(new ResteasyReactiveDeploymentBuildItem(deployment, deploymentPath));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.quarkus.resteasy.reactive.server.test;

import static io.restassured.RestAssured.get;

import java.util.function.Consumer;
import java.util.function.Supplier;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Observes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

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.builder.BuildChainBuilder;
import io.quarkus.resteasy.reactive.server.spi.ResumeOn404BuildItem;
import io.quarkus.test.QuarkusUnitTest;
import io.vertx.ext.web.Router;

public class ResumeOn404BuildItemTest {

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

protected static Consumer<BuildChainBuilder> buildCustomizer() {
return new Consumer<>() {
// This represents the extension.
@Override
public void accept(BuildChainBuilder builder) {
builder.addBuildStep(context -> {
context.produce(new ResumeOn404BuildItem());
})
.produces(ResumeOn404BuildItem.class)
.build();
}
};
}

@Test
public void matchingFromResteasyReactive() {
get("/test")
.then()
.statusCode(200);
}

@Test
public void matchingFromCustomRoute() {
get("/main")
.then()
.statusCode(200);
}

@Test
public void missing() {
get("/dummy")
.then()
.statusCode(404);
}

@Path("/test")
@RequestScoped
public static class Resource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "test";
}

}

public static class CustomRoute {

public void initMain(@Observes Router router) {
router.get("/main").handler(rc -> rc.response().end("main"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.quarkus.resteasy.reactive.server.test;

import static io.restassured.RestAssured.get;

import java.util.function.Supplier;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.event.Observes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

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.vertx.ext.web.Router;

public class ResumeOn404ConfigTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Resource.class, CustomRoute.class);
}
})
.overrideRuntimeConfigKey("quarkus.resteasy-reactive.resume-on-404", "true");

@Test
public void matchingFromResteasyReactive() {
get("/test")
.then()
.statusCode(200);
}

@Test
public void matchingFromCustomRoute() {
get("/main")
.then()
.statusCode(200);
}

@Test
public void missing() {
get("/dummy")
.then()
.statusCode(404);
}

@Path("/test")
@RequestScoped
public static class Resource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "test";
}

}

public static class CustomRoute {

public void initMain(@Observes Router router) {
router.get("/main").handler(rc -> rc.response().end("main"));
}
}
}

0 comments on commit 6e85aca

Please sign in to comment.