Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ public void validate(ValidationContext validationContext) {
if (params.size() > 1
|| (params.size() == 1 && !params.get(0).equals(SCHEDULED_EXECUTION_TYPE))) {
throw new IllegalStateException(String.format(
"Invalid scheduled business method parameters %s [method: %s, bean:%s", params,
"Invalid scheduled business method parameters %s [method: %s, bean: %s]", params,
method, bean));
}
if (!method.returnType().kind().equals(Type.Kind.VOID)) {
throw new IllegalStateException(
String.format("Scheduled business method must return void [method: %s, bean:%s",
method.returnType(), method, bean));
String.format("Scheduled business method must return void [method: %s, bean: %s]",
method, bean));
}
// Validate cron() and every() expressions
for (AnnotationInstance scheduled : schedules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class VertxWebProcessor {
private static final DotName ROUTE = DotName.createSimple(Route.class.getName());
private static final DotName ROUTES = DotName.createSimple(Route.Routes.class.getName());
private static final DotName ROUTING_CONTEXT = DotName.createSimple(RoutingContext.class.getName());
private static final DotName RX_ROUTING_CONTEXT = DotName
.createSimple(io.vertx.reactivex.ext.web.RoutingContext.class.getName());
private static final DotName ROUTING_EXCHANGE = DotName.createSimple(RoutingExchange.class.getName());
private static final String HANDLER_SUFFIX = "_RouteHandler";

Expand Down Expand Up @@ -93,13 +95,13 @@ public void validate(ValidationContext validationContext) {
List<AnnotationInstance> routes = new LinkedList<>();
AnnotationInstance routeAnnotation = annotationStore.getAnnotation(method, ROUTE);
if (routeAnnotation != null) {
validateMethodParameters(bean, method);
validateMethod(bean, method);
routes.add(routeAnnotation);
}
if (routes.isEmpty()) {
AnnotationInstance routesAnnotation = annotationStore.getAnnotation(method, ROUTES);
if (routesAnnotation != null) {
validateMethodParameters(bean, method);
validateMethod(bean, method);
Collections.addAll(routes, routesAnnotation.value().asNestedArray());
}
}
Expand Down Expand Up @@ -169,12 +171,23 @@ public void transform(TransformationContext context) {
});
}

private void validateMethodParameters(BeanInfo bean, MethodInfo method) {
private void validateMethod(BeanInfo bean, MethodInfo method) {
if (!method.returnType().kind().equals(Type.Kind.VOID)) {
throw new IllegalStateException(
String.format("Route handler business method must return void [method: %s, bean: %s]", method, bean));
}
List<Type> params = method.parameters();
if (params.size() != 1
|| !(params.get(0).name().equals(ROUTING_CONTEXT) || params.get(0).name().equals(ROUTING_EXCHANGE))) {
boolean hasInvalidParam = true;
if (params.size() == 1) {
DotName paramTypeName = params.get(0).name();
if (ROUTING_CONTEXT.equals(paramTypeName) || RX_ROUTING_CONTEXT.equals(paramTypeName)
|| ROUTING_EXCHANGE.equals(paramTypeName)) {
hasInvalidParam = false;
}
}
if (hasInvalidParam) {
throw new IllegalStateException(String.format(
"Route handler business method must accept exactly one parameter of type RoutingContext/RoutingExchange: %s [method: %s, bean:%s",
"Route handler business method must accept exactly one parameter of type RoutingContext/RoutingExchange: %s [method: %s, bean: %s]",
params, method, bean));
}
}
Expand Down Expand Up @@ -223,6 +236,12 @@ private String generateHandler(BeanInfo bean, MethodInfo method, ClassOutput cla
paramHandle = invoke.getMethodParam(0);
methodDescriptor = MethodDescriptor.ofMethod(bean.getImplClazz().name().toString(), method.name(), void.class,
RoutingContext.class);
} else if (method.parameters().get(0).name().equals(RX_ROUTING_CONTEXT)) {
paramHandle = invoke.newInstance(
MethodDescriptor.ofConstructor(io.vertx.reactivex.ext.web.RoutingContext.class, RoutingContext.class),
invoke.getMethodParam(0));
methodDescriptor = MethodDescriptor.ofMethod(bean.getImplClazz().name().toString(), method.name(), void.class,
io.vertx.reactivex.ext.web.RoutingContext.class);
} else {
paramHandle = invoke.newInstance(MethodDescriptor.ofConstructor(RoutingExchangeImpl.class, RoutingContext.class),
invoke.getMethodParam(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SimpleRouteTest {
@Test
public void testSimpleRoute() {
RestAssured.when().get("/hello").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/rx-hello").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/bzuk").then().statusCode(200).body(is("Hello world!"));
RestAssured.when().get("/hello-event-bus?name=ping").then().statusCode(200).body(is("Hello PING!"));
RestAssured.when().get("/foo?name=foo").then().statusCode(200).body(is("Hello foo!"));
Expand All @@ -52,6 +53,12 @@ void hello(RoutingContext context) {
context.response().setStatusCode(200).end("Hello " + (name != null ? name : "world") + "!");
}

@Route(path = "/rx-hello")
void rxHello(io.vertx.reactivex.ext.web.RoutingContext context) {
String name = context.request().getParam("name");
context.response().setStatusCode(200).end("Hello " + (name != null ? name : "world") + "!");
}

@Route(path = "/bzuk")
void bzuk(RoutingExchange exchange) {
exchange.ok("Hello " + exchange.getParam("name").orElse("world") + "!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

/**
* Annotation used to configure a {@link io.quarkus.vertx.web.Route} in a declarative way.
*
* The target business method must accept exacly one argument of type {@link RoutingContext}.
* <p>
* The target business method must return {@code void} and accept exacly one argument of type {@link RoutingContext}.
*/
@Repeatable(Routes.class)
@Retention(RetentionPolicy.RUNTIME)
Expand Down