ef-labs / vertx-jersey

Run jersey in vert.x
MIT License
150 stars 47 forks source link

Concrete gradle/maven exemple with specific configuration #42

Closed guedouarj closed 8 years ago

guedouarj commented 8 years ago

Hello,

I am currently struggling to get the vertx-jersey (v3) working, I would like to have this:

Here you can find a representation of my needs:

@Inject private TestDependency testDependency

@GET
@Path("async")
@Produces(MediaType.APPLICATION_JSON)
public Response getJsonAsync(@Suspended final AsyncResponse asyncResponse, @Context Vertx vertx) {
    vertx.runOnContext(aVoid -> {
        MyObject o = new MyObject();
        o.setName("Andy");
        System.out.println(testDependency.getMessage());
        // some RxJava stuffs with Observable
        // some Postgresql client query with HSQLDB ( for test )
        asyncResponse.resume(o);
    });
   return response;
}

I got a lot of problems with HK2 like: vertx org.glassfish.hk2.api.UnsatisfiedDependencyException..

If someone can make a quick example with all of this working, it will be just great and useful.

Thank you !

adrianluisgonzalez commented 8 years ago

Take a look at this: https://github.com/englishtown/vertx-examples/tree/master/vertx-jersey-simple

The rx and sql functionality is not there, but it covers HK2, Jersey, Jackson, and Swagger. You should be able to add rx and sql by looking at those projects.

Hope this helps.

guedouarj commented 8 years ago

It works thank you !

Is it possible to return an Response object ( containing code 200, 401, .. ) instead of void ?

Also I wanted to know if its possible to use JPA with the sql client ? I heard it has to be done on a worker aka blocking verticle ?

Thank you again for your quick help !

adrianluisgonzalez commented 8 years ago

You can return a Response object instead of void, but then your method is not async. If you are writing an async method, then you can pass a Response object to asyncResponse.resume(response).

If you are using a blocking sql API, then it should run in a worker verticle.

guedouarj commented 8 years ago

OK that makes sense.

Thx for your answers !