public class MyAbstractVerticle extends AbstractVerticle {
public void initServer() throws IllegalAccessException, LambdaConversionException, Throwable {
Router router = Router.router(vertx);
Method[] methods = this.getClass().getMethods();
for(Method m : methods) {
Annotation[] annotations = m.getAnnotations();
if(annotations.length == 1) {
System.out.println(annotations[0].toString());
MethodHandles.Lookup lookup = MethodHandles.lookup();
Handler<RoutingContext> handler = (Handler<RoutingContext>)
LambdaMetafactory.metafactory(lookup, "handle",
MethodType.methodType(Handler.class, getClass()),
MethodType.methodType(void.class, Object.class), lookup.unreflect(m),
MethodType.methodType(void.class, RoutingContext.class))
.getTarget().invoke(this);
if(annotations[0] instanceof GET) {
GET get = (GET) annotations[0];
router.get(get.route()).handler(handler);
} else if(annotations[0] instanceof POST) {
POST post = (POST) annotations[0];
}
}
}
vertx.createHttpServer().requestHandler(router::accept).listen(8181);
}
}