Hello list!,
I am trying to use RxJava Observables to handle various asynchronous
operations
in Jersey 2 app.
Using async support from Jersey requires most resources to subscribe and
complete the AsyncResponse when an observable does:
@GET
public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
myService.getSomethingAsObservable()
.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
just
return an Observable in HTTP methods:
@GET
@SuspendedOnObservable
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.
Andrea