[Jersey] R: Re: Observable resources

From: Andrea Ratto <>
Date: Tue, 26 Aug 2014 08:48:56 +0100

Hi Libor,

ManagedAsync is not the helpful here: the resource method call is very quick, since it just returns the Obsevable and its chain of subscribers.
Any long operation is already run in different threads-.

My problem is adding piece of code that has access to the return of the resource method, like a wrapper.

Something like this:

AsyncResponse ar = fromSomewhere.getAsyncResponse();
Observable<?> o = resourceMethod.invoke(); // or or what is it?
o.subscribe(s -> ar.resume(s)); // error handling omitted
A facility for doing this, I cannot find in the code base. Any more pointers? Thanks

Lun 25/8/14, Libor Kramolis <> ha scritto:

 Oggetto: [Jersey] Re: Observable resources
 Data: Lunedì 25 agosto 2014, 21:29
 That’s great
 you are trying that. Reative is future. ;-)
 Quick answer. Try to look at Jersey
 Managed Async support. It is Jersey specific more
 straightforward JAX-RS Async support.
 Jersey API:
 start point:
 And let us know how successful you
 are. I guess this is good area for contribution at least to
 On 25 Aug 2014, at
 14:46, Andrea Ratto <>
 Hello list!,
 am trying to use RxJava Observables to handle various
 Jersey 2 app.
 Using async
 support from Jersey requires most resources to subscribe
 complete the AsyncResponse when an
 observable does:
     public void
 asyncGet(@Suspended final AsyncResponse asyncResponse) {
                  .map(s ->
                 .subscribe(s ->
 asyncResponse.resume(s)); // simplified
 To do it elegantly,
 without boilerplate code, would require some magic
 annotation or something else to factor out this
 behaviour and basically
 return an Observable in HTTP methods:
 Observable<Object> asyncGet() {
                         .map(s ->
 Doesn't it look great?
 Doing it requires solving two problems:
 1. ensuring that the resource is handled
 asynchronously by Jersey.
 2. running some
 code after the method to get the AsyncResponse and
 subscribe it
    the to the
 returned Observable.
 1 I think I can solve inspecting the model.
 For the second problem, I am
 in need of some pointers.
 Thank you.