问题
If I defined my rest-easy Resource this this way:
@GET
@Path("/stuff")
@Produces(MediaType.APPLICATION_JSON)
public Response getStuff() {
final Single<Stuff> stuffSingle = stuffService.getStuffAsync();
return Response.ok().entity(stuffSingle.blockingGet()).build();
}
And exception happens somewhere at getStuffAsync() method.
I could go with ExceptionMapper to delegate it to handle exceptions.
@Provider
public class MyExceptionMapper implements ExceptionMapper<Exception> { ..
And it works - it is possible to handle exception and pass it to the user.
BUT if I go with Async Rest end-point:
@Path("/stuff")
@Produces(MediaType.APPLICATION_JSON)
public CompletionStage<Stuff>
stuffSingle = stuffService.getStufAsync();
final CompletableFuture<Stuff> stuffSignle = new CompletableFuture<>();
stuffSignle.subscribe(future::complete);
return future
}
In case if exception, the endpoint would hang forever. No response would be propagated to the user. No MyExceptionMapper involvement.
Q: What is the way to handle it with CompletionStage in rest easy in Quarkus
来源:https://stackoverflow.com/questions/59257978/quarkus-resteasy-ws-rs-resource-completionstage-exception-handling