reta opened a new pull request #526: CXF-7989: org.apache.cxf.jaxrs.JAXRSInvoker should handle CompletionException URL: https://github.com/apache/cxf/pull/526 The Problem === In case when CXF is used along with `CompletionStage` / `CompletableFuture`, in most cases the error handling is propagated back through `CompletionException` instance (http://cs.oswego.edu/pipermail/concurrency-interest/2014-August/012911.html). It works but it forces users to introduce own implementations of `ExceptionMapper`s and manually unwrap the `CompletionException` into something more meaningful. Use cases === There are 3 leading use cases which cover most typical usage of the `CompletionStage` / `CompletableFuture`. 1. `@Suspended AsyncResponse` ``` public void get(@PathParam("isbn") String isbn, @Suspended final AsyncResponse resp) { client.target("http://localhost:19092/services/catalog/" + isbn) .request() .rx() .get(Book.class) .whenComplete((r, ex) -> { if (ex != null) { resp.resume(ex); } else { resp.resume(r); } }); } ``` 2. Return `CompletableFuture<Book>` ``` public CompletableFuture<Book> get(@PathParam("isbn") String isbn) { return client .target("http://localhost:19092/services/catalog/" + isbn) .request() .rx() .get(Book.class) .toCompletableFuture(); } ``` 3. Return constructed instance of the `CompletableFuture<Book>` ``` public CompletableFuture<Book> get(@PathParam("isbn") String isbn) { final CompletableFuture<Book> future = new CompletableFuture<Book>(); future.completeExceptionally(...); return future; } ``` Suggested Solution === Instrument `JAXRSInvoker::handleAsyncResponse` to distinguish `CompletionException`, unwrap the cause and use it to select the appropriate `ExceptionMapper` (if any). @rmannibucau why `JAXRSInvoker::handleAsyncResponse` and not `JAXRSInvoker::checkFutureResponse`, the 1st use case which uses suspended async response does not flow through `JAXRSInvoker::checkFutureResponse` but all three use cases run through `JAXRSInvoker::handleAsyncResponse` @coheigea @dkulp guys would really appreciate if you could take a quick look, small change but may introduce undesired side effects, thanks a lot.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
