Adding a regression test
@@ -14,8 +14,7 @@ import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
-import io.vertx.ext.web.handler.BodyHandler;
-import io.vertx.ext.web.handler.StaticHandler;
+import io.vertx.ext.web.handler.*;
import io.vertx.ext.web.multipart.MultipartForm;
import io.vertx.ext.web.validation.BodyProcessorException;
import io.vertx.ext.web.validation.ParameterProcessorException;
@@ -1546,4 +1545,44 @@ public class RouterBuilderIntegrationTest extends BaseRouterBuilderTest {
});
}
+ @Test
+ public void testProperOrderOfHandlers(Vertx vertx, VertxTestContext testContext) {
+ loadBuilderAndStartServer(vertx, VALIDATION_SPEC, testContext, routerBuilder -> {
+
+ routerBuilder.rootHandler(LoggerHandler.create(true, LoggerHandler.DEFAULT_FORMAT));
+ routerBuilder.rootHandler(TimeoutHandler.create(180000));
+ routerBuilder.rootHandler(CorsHandler.create("*"));
+ routerBuilder.rootHandler(BodyHandler.create().setBodyLimit(40000000).setDeleteUploadedFilesOnEnd(true).setHandleFileUploads(true));
+
+ routerBuilder
+ .operation("listPets")
+ .handler(routingContext -> routingContext.response().setStatusMessage("ok").end());
+ }).onComplete(h ->
+ testRequest(client, HttpMethod.GET, "/pets")
+ .expect(statusCode(200), statusMessage("ok"))
+ .send(testContext)
+ );
+ }
+
+ @Test
+ public void testIncorrectOrderOfHandlers(Vertx vertx, VertxTestContext testContext) {
+
+ RouterBuilder.create(vertx, VALIDATION_SPEC, testContext.succeeding(routerBuilder -> {
+ routerBuilder.rootHandler(BodyHandler.create().setBodyLimit(40000000).setDeleteUploadedFilesOnEnd(true).setHandleFileUploads(true));
+ routerBuilder.rootHandler(LoggerHandler.create(true, LoggerHandler.DEFAULT_FORMAT));
+ routerBuilder.rootHandler(TimeoutHandler.create(180000));
+ routerBuilder.rootHandler(CorsHandler.create("*"));
+
+ routerBuilder
+ .operation("listPets")
+ .handler(routingContext -> routingContext.response().setStatusMessage("ok").end());
+
+ try {
+ routerBuilder.createRouter();
+ testContext.failNow("Should not reach here");
+ } catch (IllegalStateException ise) {
+ testContext.completeNow();
+ }
+ }));
+ }
}
