Comments (9)
Not quite following what is the issue ... ?
You have registered MyObject.class as your API ... and It is not working? ...
Or are you trying to register and array as an API? ... this will not work ... as rest.vertx takes each registered object as an API endpoint ... so you are basically trying to register and ArrayList as an API endpoint? ....
from rest.vertx.
From the README.md, it is apparent you can register an instance of an object
RestRest rest = new TestRest();
Router router = RestRouter.register(vertx, rest);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(PORT);
I am trying to do such but via the Builder API. The instance is saved in the RestBuilder's apis instance variable which is an actual ArrayList. The apis instance variable is fed to the RestRouter.register call, which accepts an array of Objects (VarArgs). By doing so, the first object of the VarArgs becomes the ArrayList and not the elements of such List.
from rest.vertx.
Can you please provide the exact code ... I'm lost.
from rest.vertx.
Sure, I will work on a reproducer of the issue.
from rest.vertx.
More information. The RestBuilder.build() does build correctly, but the issue (and I am being picky here) is that the initial call by the build() method to getRouter() is not really doing anything because the passed parameter is an ArrayList. However down the build() code, there is an actual iteration of each of the elements of the apis variable which in that case is correctly registering the instance.
// register APIs
apis.forEach(api -> RestRouter.register(output, api));
I still think that this method is incorrect and not necessary (well, getting a Vert.x Router is necessary)
private Router getRouter() {
if (vertx == null) {
return RestRouter.register(router, apis);
}
return RestRouter.register(vertx, apis);
}
Oh,and thank you very much for creating this project, it is really helpful. I appreciate it.
from rest.vertx.
I see ... the getRouter() method is needed ... because you can build up you RESTs in two ways ...
- new RestBuilder(vertx). ... .build() OR
- new RestBuilder(router) ... build() in case you want to add new routes to an existing router
so this is in place to match all possible cases ..
from rest.vertx.
Correct, but the thing is that this call
return RestRouter.register(vertx, apis);
Does not register anything because the object passed (a List) is begin treated as a List itself which has no annotations so the iteration over
Map<RouteDefinition, Method> definitions = AnnotationProcessor.get(api.getClass());
Returns an empty Map (because the class of api at that point is java.util.ArrayList which has no REST annotations and neither its methods)
I agree that the RestBuilder either by vertx or router is needed.
I believe the solution is
private Router getRouter() {
Object[] apiObjects = apis.toList(new Object[apis.size()])
if (vertx == null) {
return RestRouter.register(router, apiObjects);
}
return RestRouter.register(vertx, apiObjects);
}
However, this would duplicate the "registration" because you still have
// register APIs
apis.forEach(api -> RestRouter.register(output, api));
so the correct solution would be
private Router getRouter() {
return vertx == null ? router : Router.router(vertx);
}
from rest.vertx.
O I see ... you want to register a list holding you APIs ... as:
List<Object> list = new ArrayList();
list.add(api1);
list.add(api2);
new RestBuilder(vertx).register(list).build();
This will not work ... the list is taken as the API (which in this case it is not) ...
Usage is intended to be:
new RestBuilder(vertx).register(api1, api2).build();
from rest.vertx.
Your RestBuilder api does provide a correct way to register things. The thing is that there is code that is not doing much besides creating the Vertx router. For example, try to debug
@Test
public void testCustomInput_WithBuilder(TestContext context) {
Router router = new RestBuilder(vertx)
.register(TestReaderRest.class)
.build();
and you will see that the call to
return RestRouter.register(vertx, apis);
does nothing besides creating the vertx router because when iterates over the api loop variable, the class for the api object is a List which is not REST annotated, so there are no RouteDefinitions created.
from rest.vertx.
Related Issues (20)
- IllegalArgumentException when register ExceptionHandler HOT 6
- Authentication does not work as in example HOT 8
- Multipart requests support? HOT 4
- Response head already sent HOT 9
- NoContentResponseWriter does not return response HOT 1
- version 1.0.5 RouteDefinition BODY_HANDLER_PARAMS not include context HOT 1
- java 17 compatibility (TypeVariableImpl) HOT 4
- RestBuilder violates Vert.x 4.3's handler ordering HOT 3
- Is this possible to print the cause of exception? HOT 5
- Registered ValueReader not used to decode query parameters unless explicitly stated
- Improve not found handling HOT 1
- Add suspendable function support to asynchronous response types HOT 3
- Cannot use null enum value in REST endpoint url HOT 2
- Support Swagger or Open API HOT 1
- Rewrite authorization/authentication flow
- HttpMethod problem in vertx4 HOT 1
- The detailed exception is hidden when fail to getInstance HOT 2
- Could you add Interceptor in path route like spring? HOT 6
- mountSubRouter HOT 2
- About Interceptor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.