Skip to content

Commit

Permalink
Merge pull request #5294 from famartinrh/fix-bug-resuming-router
Browse files Browse the repository at this point in the history
Fix delegation usage in ResumingRouter
  • Loading branch information
stuartwdouglas authored Nov 7, 2019
2 parents 76b515a + 6bf9fac commit 5b12ae9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void testRoute() {

RestAssured.given()
.body("An example body")
.contentType("text/plain")
.post("/post")
.then()
.body(is("An example body"));
Expand All @@ -50,6 +51,7 @@ void observeRouter(@Observes Router router) {
counter++;
router.get("/boom").handler(ctx -> ctx.response().setStatusCode(200).end("ok"));
Route post = router.post("/post");
post.consumes("text/plain");
post.handler(BodyHandler.create());
post.handler(ctx -> ctx.response().end(ctx.getBody()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.quarkus.vertx.http.runtime;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
Expand Down Expand Up @@ -181,33 +184,41 @@ public Route patch(String path) {

@Override
public Route patchWithRegex(String regex) {
return delegate.patchWithRegex(regex);
return new ResumingRoute(delegate.patchWithRegex(regex));
}

@Override
public List<Route> getRoutes() {
return delegate.getRoutes();
return Optional.ofNullable(delegate.getRoutes())
.map(List::stream)
.orElseGet(Stream::empty)
.map(ResumingRoute::new)
.collect(Collectors.toList());
}

@Override
public Router clear() {
return delegate.clear();
delegate.clear();
return this;
}

@Override
public Router mountSubRouter(String mountPoint, Router subRouter) {
return delegate.mountSubRouter(mountPoint, subRouter);
delegate.mountSubRouter(mountPoint, subRouter);
return this;
}

@Override
@Deprecated
public Router exceptionHandler(Handler<Throwable> exceptionHandler) {
return delegate.exceptionHandler(exceptionHandler);
delegate.exceptionHandler(exceptionHandler);
return this;
}

@Override
public Router errorHandler(int statusCode, Handler<RoutingContext> errorHandler) {
return delegate.errorHandler(statusCode, errorHandler);
delegate.errorHandler(statusCode, errorHandler);
return this;
}

@Override
Expand All @@ -221,9 +232,9 @@ public void handleFailure(RoutingContext context) {
}

@Override

public Router modifiedHandler(Handler<Router> handler) {
return delegate.modifiedHandler(handler);
delegate.modifiedHandler(handler);
return this;
}

@Override
Expand All @@ -240,82 +251,98 @@ private ResumingRoute(Route route) {

@Override
public Route method(HttpMethod method) {
return route.method(method);
route.method(method);
return this;
}

@Override
public Route path(String path) {
return route.path(path);
route.path(path);
return this;
}

@Override
public Route pathRegex(String path) {
return route.pathRegex(path);
route.pathRegex(path);
return this;
}

@Override
public Route produces(String contentType) {
return route.produces(contentType);
route.produces(contentType);
return this;
}

@Override
public Route consumes(String contentType) {
return route.consumes(contentType);
route.consumes(contentType);
return this;
}

@Override
public Route order(int order) {
return route.order(order);
route.order(order);
return this;
}

@Override
public Route last() {
return route.last();
route.last();
return this;
}

@Override
public Route handler(Handler<RoutingContext> requestHandler) {
return route.handler(new ResumeHandler(requestHandler));
route.handler(new ResumeHandler(requestHandler));
return this;
}

@Override
public Route blockingHandler(Handler<RoutingContext> requestHandler) {
return route.blockingHandler(new ResumeHandler(requestHandler));
route.blockingHandler(new ResumeHandler(requestHandler));
return this;
}

@Override
public Route subRouter(Router subRouter) {
return route.subRouter(subRouter);
route.subRouter(subRouter);
return this;
}

@Override
public Route blockingHandler(Handler<RoutingContext> requestHandler, boolean ordered) {
return route.blockingHandler(new ResumeHandler(requestHandler), ordered);
route.blockingHandler(new ResumeHandler(requestHandler), ordered);
return this;
}

@Override
public Route failureHandler(Handler<RoutingContext> failureHandler) {
return route.failureHandler(new ResumeHandler(failureHandler));
route.failureHandler(new ResumeHandler(failureHandler));
return this;
}

@Override
public Route remove() {
return route.remove();
route.remove();
return this;
}

@Override
public Route disable() {
return route.disable();
route.disable();
return this;
}

@Override
public Route enable() {
return route.enable();
route.enable();
return this;
}

@Override
public Route useNormalisedPath(boolean useNormalisedPath) {
return route.useNormalisedPath(useNormalisedPath);
route.useNormalisedPath(useNormalisedPath);
return this;
}

@Override
Expand All @@ -335,7 +362,8 @@ public Set<HttpMethod> methods() {

@Override
public Route setRegexGroupsNames(List<String> groups) {
return route.setRegexGroupsNames(groups);
route.setRegexGroupsNames(groups);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.quarkus.vertx.ConsumeEvent;
import io.restassured.RestAssured;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

Expand All @@ -43,6 +44,8 @@ public void testSimpleRoute() {
RestAssured.when().delete("/delete").then().statusCode(200).body(is("deleted"));
RestAssured.when().get("/routes").then().statusCode(200)
.body(Matchers.containsString("/hello-event-bus"));
RestAssured.given().contentType("text/plain").body("world")
.post("/body").then().body(is("Hello world!"));
}

static class SimpleBean {
Expand Down Expand Up @@ -71,6 +74,11 @@ void deleteHttpMethod(RoutingExchange exchange) {
exchange.ok("deleted");
}

@Route(path = "/body", methods = HttpMethod.POST, consumes = "text/plain")
void post(RoutingContext context) {
context.response().setStatusCode(200).end("Hello " + context.getBodyAsString() + "!");
}

}

static class SimpleRoutesBean {
Expand Down

0 comments on commit 5b12ae9

Please sign in to comment.