As I understand if I have any blocking action on Undertow HTTP handlers I have to follow this pattern:
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
// Do any blocking action like normal http calls...
}
But I'm using awesome org.asynchttpclient
library for having async HTTP calls like this:
public void handleRequest(HttpServerExchange exchange) throws Exception {
new DefaultAsyncHttpClient().prepareGet("http://some/url").execute()
.toCompletableFuture()
.thenApply(r -> {
exchange.getResponseSender().send("OK");
return r;
});
}
The problem is exchange never sends 'OK' out ('OK' will not print out to the response), it seems it's already closed when I'm trying to write it.
Any way do handle this situation. Overall, does it have any advantage over solution one?