davsclaus commented on code in PR #27694:
URL: https://github.com/apache/camel/pull/27694#discussion_r4245539948


##########
components/camel-whatsapp/src/main/java/org/apache/camel/component/whatsapp/service/WhatsAppServiceRestAPIAdapter.java:
##########
@@ -197,8 +198,17 @@ public void sendMessage(Exchange exchange, AsyncCallback 
callback, T message, St
             CompletableFuture<HttpResponse<String>> asyncResponse
                     = httpClient.sendAsync(httpRequestBuilder.build(), 
HttpResponse.BodyHandlers.ofString());
 
-            asyncResponse.thenAccept(response -> {
+            // whenComplete (and not thenAccept), so that the exchange is also 
completed when there is no response,
+            // for example when the connection failed or the connect timeout 
expired. The request itself has no
+            // timeout, so a server that accepts the connection and never 
answers is not covered here.
+            asyncResponse.whenComplete((response, failure) -> {
                 try {
+                    if (failure != null) {
+                        exchange.setException(
+                                failure instanceof CompletionException && 
failure.getCause() != null

Review Comment:
   Optional: the JDK `HttpClient` often throws `ConnectException` with a null 
message, so the exchange fails without saying where it tried to connect. 
Wrapping it, e.g. `new RuntimeCamelException("Could not send message to " + 
uri, cause)`, would make it easier to diagnose (the test would then assert 
`hasRootCauseInstanceOf(IOException.class)`).



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to