[Jersey] Observable resources

From: Andrea Ratto <>
Date: Mon, 25 Aug 2014 14:46:23 +0200

Hello list!,

I am trying to use RxJava Observables to handle various asynchronous
in Jersey 2 app.

Using async support from Jersey requires most resources to subscribe and
complete the AsyncResponse when an observable does:

    public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
                 .map(s -> s.doSomethingMore()
                 .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:

    public Observable<Object> asyncGet() {
         return myService.getSomethingAsObservable()
                         .map(s -> s.doSomethingMore();

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.

Number 1 I think I can solve inspecting the model.

For the second problem, I am in need of some pointers.
Thank you.