Skip to content

Commit

Permalink
Add configuration option for resuming on 404
Browse files Browse the repository at this point in the history
This is a useful (albeit advanced) option for users
that want to use custom routes to handle
cases where RESTEasy Reactive does not match the
URL path.

Closes: #38840
  • Loading branch information
geoand committed Feb 19, 2024
1 parent b8ec810 commit fe3129c
Show file tree
Hide file tree
Showing 3 changed files with 84 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,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 fe3129c

Please sign in to comment.