You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "allthingssecurity (via GitHub)" <gi...@apache.org> on 2026/10/12 00:05:40 UTC

[PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

allthingssecurity opened a new pull request, #27694:
URL: https://github.com/apache/camel/pull/27694

   # Description
   
   [CAMEL-25546](https://issues.apache.org/jira/browse/CAMEL-25546)
   
   `WhatsAppProducer.process` is asynchronous and returns `false`; the exchange is completed by `WhatsAppServiceRestAPIAdapter`, which sent the request with `HttpClient.sendAsync` and handled the result with `thenAccept(response -> { ... finally { callback.done(false); } })`. `thenAccept` only runs for a response. When the request failed without one (connection refused or reset, DNS failure, the 10 second connect timeout), the future completed exceptionally, the function was skipped and the callback was never called. The exchange was never completed: a caller waiting for it blocked forever, the exchange stayed in flight, and a graceful shutdown waited for its timeout.
   
   Now the result is handled with `whenComplete`: a failure without a response fails the exchange with that exception (for example `java.net.ConnectException`) and the callback is called. The handling of a response is unchanged; the two `throw` statements that followed `exchange.setException` are removed, since nothing observed them.
   
   The response handling also caught only `JsonProcessingException`; any other exception thrown there was lost in the future, and the exchange completed as a success. It now catches `Exception` and sets it on the exchange. The callback is called once, in the `finally` of the one `whenComplete` function. I found no way to make the response handling throw something other than a `JsonProcessingException` from a test, so this catch has no test of its own.
   
   Known follow-up, not fixed here: there is no request timeout. The `HttpClient` has a connect timeout of 10 seconds, but the `HttpRequest` has no `timeout(...)`, so a server that accepts the connection and never answers still leaves the exchange waiting forever. That needs a new option (or a default) and I can do it separately.
   
   There is no upgrade guide note, because the only change is that an exchange that waited forever now fails.
   
   Tests:
   - New `WhatsAppProducerFailureTest`: with `baseUri` pointing to a local port nothing listens on, an asynchronous send must complete within 30 seconds with an `IOException` on the exchange. Without the change the test fails with a `TimeoutException`.
   - Only `failsTheExchangeWhenTheConnectionFails` fails on main. The other two tests of the class, `failsTheExchangeForAnErrorResponse` (a 400 from a local HTTP server fails the exchange with the status and the body) and `returnsTheResponse` (a 200 returns a `MessageResponse`), pass on main too; they cover the response handling that the change restructures and do not show the bug.
   - With the change: camel-whatsapp 11 tests, 0 failures. `WhatsAppServiceIT` needs a WhatsApp account and was not run.
   
   Found by a review of producers that complete an exchange from a `CompletableFuture`, with a small TLA+ model (send, outcome, callback): on main TLC reports a deadlock when the request fails without a response; with the fix every behaviour completes the exchange. I then reproduced it with the producer.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
     (I built and tested camel-whatsapp, including the formatter and import-sort plugins. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on code in PR #27694:
URL: https://github.com/apache/camel/pull/27694#discussion_r4245775464


##########
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:
   Applied in e3219fe23c73. I checked the claim with a small program: a refused connection gives
   `java.net.ConnectException` with a null message. The failure is now
   `new RuntimeCamelException("Could not send message to " + URISupport.sanitizeUri(uri), cause)`. The access token is
   sent in the `Authorization` header and is not in the URI; the URI is sanitized anyway, as `baseUri` is a user
   option. The test asserts the message with the URI and `hasCauseInstanceOf(IOException.class)`.
   
   _Claude Code on behalf of allthingssecurity_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on PR #27694:
URL: https://github.com/apache/camel/pull/27694#issuecomment-6120111673

   - The optional wrap is applied in e3219fe23c73 (inline reply). camel-whatsapp: 11 tests, 0 failures.
   - The missing request timeout and the INFO log of every response body are not changed in this PR.
   
   _Claude Code on behalf of allthingssecurity_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27694:
URL: https://github.com/apache/camel/pull/27694#issuecomment-6119644813

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #27694:
URL: https://github.com/apache/camel/pull/27694#discussion_r4245841096


##########
components/camel-whatsapp/src/main/java/org/apache/camel/component/whatsapp/service/WhatsAppServiceRestAPIAdapter.java:
##########
@@ -208,14 +222,12 @@ public void sendMessage(Exchange exchange, AsyncCallback callback, T message, St
                         exchange.getMessage().setBody(result);
                     } else {
                         LOG.debug("Error response Headers {}", response.headers());
-                        RuntimeException exception = new RuntimeCamelException(
-                                uri + " responded: " + statusCode + " and body: " + response.body());
-                        exchange.setException(exception);
-                        throw exception;
+                        exchange.setException(new RuntimeCamelException(
+                                uri + " responded: " + statusCode + " and body: " + response.body()));

Review Comment:
   💡 **Nit — inconsistent URI sanitization:** The connection-failure path above uses `URISupport.sanitizeUri(uri)` to avoid leaking credentials from the URI in error messages. This error-response path uses the raw `uri`. If the endpoint URI can contain credentials (e.g. a token in the query string), they would be exposed here. Consider applying `URISupport.sanitizeUri(uri)` consistently:
   
   ```suggestion
                           exchange.setException(new RuntimeCamelException(
                                   URISupport.sanitizeUri(uri) + " responded: " + statusCode + " and body: " + response.body()));
   ```



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "allthingssecurity (via GitHub)" <gi...@apache.org>.
allthingssecurity commented on code in PR #27694:
URL: https://github.com/apache/camel/pull/27694#discussion_r4246365474


##########
components/camel-whatsapp/src/main/java/org/apache/camel/component/whatsapp/service/WhatsAppServiceRestAPIAdapter.java:
##########
@@ -208,14 +222,12 @@ public void sendMessage(Exchange exchange, AsyncCallback callback, T message, St
                         exchange.getMessage().setBody(result);
                     } else {
                         LOG.debug("Error response Headers {}", response.headers());
-                        RuntimeException exception = new RuntimeCamelException(
-                                uri + " responded: " + statusCode + " and body: " + response.body());
-                        exchange.setException(exception);
-                        throw exception;
+                        exchange.setException(new RuntimeCamelException(
+                                uri + " responded: " + statusCode + " and body: " + response.body()));

Review Comment:
   Done in 7507e86b6b38: the exception for an error response now uses `URISupport.sanitizeUri(uri)` as well. The URI is
   `<baseUri>/<apiVersion>/<phoneNumberId>/messages` (or `/media`); the access token goes in the `Authorization` header,
   so only a configured `baseUri` could carry credentials. `failsTheExchangeForAnErrorResponse` now also asserts that the
   message names the URI. camel-whatsapp: 11 tests, 0 failures.
   
   _Claude Code on behalf of allthingssecurity_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #27694:
URL: https://github.com/apache/camel/pull/27694#issuecomment-6120348462

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-whatsapp`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 9 of 704 tested, 27 compile-only — current: 9 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **9 affected modules** (current approach: 9).
   
   **Skip-tests mode would test 9 modules** (1 direct + 8 downstream), **skip tests for 27** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (9)</summary>
   
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-route-parser` ← downstream of org.apache.camel:camel-route-parser
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-catalog
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   - `camel-whatsapp` ← components/camel-whatsapp/src/main/java/org/apache/camel/component/whatsapp/service/WhatsAppServiceRestAPIAdapter.java, components/camel-whatsapp/src/test/java/org/apache/camel/component/whatsapp/WhatsAppProducerFailureTest.java
   - `camel-yaml-dsl-validator` ← downstream of org.apache.camel:camel-catalog
   - `camel-yaml-dsl-validator-maven-plugin` ← downstream of org.apache.camel:camel-yaml-dsl-validator
   
   </details>
   
   <details><summary>Modules with tests skipped (27)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (36 modules, 5m 23s total)</summary>
   
   **Total reactor time:** 5m 23s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Launcher | 49.6s | SUCCESS |
   | Camel :: JBang :: MCP | 41.8s | SUCCESS |
   | Camel :: Catalog :: Camel Catalog | 23.8s | SUCCESS |
   | Camel :: YAML DSL | 20.8s | SUCCESS |
   | Camel :: Component DSL | 20.2s | SUCCESS |
   | Camel :: YAML DSL :: Validator | 19.8s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 17.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 16.7s | SUCCESS |
   | Camel :: Docs | 15.2s | SUCCESS |
   | Camel :: Kamelet Main | 13.9s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 13.5s | SUCCESS |
   | Camel :: Whatsapp | 12.0s | SUCCESS |
   | Camel :: YAML DSL :: Deserializers | 9.6s | SUCCESS |
   | Camel :: Catalog :: Camel Route Parser | 9.2s | SUCCESS |
   | Camel :: Catalog :: Camel Report Maven Plugin | 8.0s | SUCCESS |
   | Camel :: All Components Sync point | 5.1s | SUCCESS |
   | Camel :: YAML DSL :: Validator Maven Plugin | 4.0s | SUCCESS |
   | Camel :: YAML DSL :: Maven Plugins | 3.8s | SUCCESS |
   | Camel :: Catalog :: Maven | 3.1s | SUCCESS |
   | Camel :: Catalog :: Suggest (deprecated) | 2.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 1.5s | SUCCESS |
   | Camel :: Coverage | 1.4s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 1.4s | SUCCESS |
   | Camel :: Assembly | 1.3s | SUCCESS |
   | Camel :: Catalog :: Dummy Component | 1.2s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 1.2s | SUCCESS |
   | Camel :: Catalog :: Console | 1.2s | SUCCESS |
   | Camel :: JBang :: Integration tests | 0.9s | SUCCESS |
   | Camel :: Launcher :: Container | 0.8s | SUCCESS |
   | Camel :: Endpoint DSL :: Support | 0.8s | SUCCESS |
   | Camel :: JBang :: Main | 0.7s | SUCCESS |
   | Camel :: JBang :: Plugin :: Route Parser | 0.5s | SUCCESS |
   | Camel :: Endpoint DSL | n/a |  |
   | Camel :: Integration Tests | n/a |  |
   | Camel :: JBang :: Core | n/a |  |
   | Camel :: JBang :: Plugin :: TUI | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Launcher` (49.6s)
   - `Camel :: JBang :: MCP` (41.8s)
   - `Camel :: Catalog :: Camel Catalog` (23.8s)
   - `Camel :: YAML DSL` (20.8s)
   - `Camel :: Component DSL` (20.2s)
   - `Camel :: YAML DSL :: Validator` (19.8s)
   - `Camel :: JBang :: Plugin :: Validate` (17.2s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (16.7s)
   - `Camel :: Docs` (15.2s)
   - `Camel :: Kamelet Main` (13.9s)
   - `Camel :: JBang :: Plugin :: Testing` (13.5s)
   - `Camel :: Whatsapp` (12.0s)
   - `Camel :: YAML DSL :: Deserializers` (9.6s)
   - `Camel :: Catalog :: Camel Route Parser` (9.2s)
   - `Camel :: Catalog :: Camel Report Maven Plugin` (8.0s)
   - `Camel :: All Components Sync point` (5.1s)
   - `Camel :: YAML DSL :: Validator Maven Plugin` (4.0s)
   - `Camel :: YAML DSL :: Maven Plugins` (3.8s)
   - `Camel :: Catalog :: Maven` (3.1s)
   - `Camel :: Catalog :: Suggest (deprecated)` (2.7s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/38186704170)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25546: camel-whatsapp - Complete the exchange when the HTTP request fails [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #27694:
URL: https://github.com/apache/camel/pull/27694


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org