vignesh-manel opened a new pull request, #28766:
URL: https://github.com/apache/camel/pull/28766

   # Description
   
   Fixes [CAMEL-26167](https://issues.apache.org/jira/browse/CAMEL-26167).
   
   **1. The `from` of an `SMSMessage` was ignored.** `CMProducer` set the 
sender of the `CMMessage` only when `from` was empty (to `defaultFrom`). When 
`from` was set it was never copied, so the request had an empty `<FROM/>`. It 
has been like this since the component was added. Reproduced with a recording 
`CMSender`: a message with `from="MySender"` was sent with sender `null`. Now 
`from` is the sender, and `defaultFrom` is used when it is empty. `from` is 
still validated by `SMSMessage` (`@Size(min = 1, max = 11)`, alphanumeric) 
before it is used.
   
   **2. A validation failure did not say what was invalid.** The violations 
were built into a string, logged at DEBUG and dropped. The exception read `No 
body available of type: ...SMSMessage but has type: ...SMSMessage`. The 
exception type stays `InvalidPayloadRuntimeException`, so existing 
`onException` / `catch` code still matches. It now has a cause whose message 
lists the violations:
   
   ```
   No body available of type: org.apache.camel.component.cm.client.SMSMessage 
but has type: org.apache.camel.component.cm.client.SMSMessage on: Message. 
Caused by: Invalid SMSMessage: invalid value for from: size must be between 1 
and 11. Exchange[] on the exchange: Exchange[]
   ```
   
   The ticket proposes an `IllegalArgumentException` or a 
`ConstraintViolationException` in its place. I did not do that, so the 
exception type does not change for users. I first tried a 
`jakarta.validation.ConstraintViolationException` as the cause, but the 
existing `CMTest.testSendInvalidPayload` failed. It sends through a `@Produce` 
proxy, and `AbstractCamelInvocationHandler` rethrows the cause of a 
`RuntimeCamelException` when that cause is a `RuntimeException`. So proxy users 
would have received a different exception type. The cause is therefore the 
checked `org.apache.camel.ValidationException`, and the proxy still throws the 
`InvalidPayloadRuntimeException`.
   
   Tests, in `CMTest`:
   
   - `testTheSenderOfTheMessageIsUsed`: a message with `from` is sent with that 
sender, and one without is sent with `defaultFrom`;
   - `testInvalidPayloadNamesTheInvalidField`: a `from` of 12 characters gives 
an `InvalidPayloadRuntimeException` whose message names `from`, with a 
`ValidationException` cause.
   
   Both failed before the fix (`expected: <MySender> but was: <null>`, and the 
old message). The existing `testSendInvalidPayload` still passes.
   
   Upgrade guide: a short entry in 4.24, after the camel-oaipmh entry.
   
   Local: `mvn clean install -Psourcecheck` in `components/camel-cm-sms`, 56 
tests, 0 failures; no generated files changed.
   
   _Claude Code on behalf of vignesh-manel_
   
   # 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.
   
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes. (Run in the module with 
`-Psourcecheck`, not from the root; no generated files changed. CI checks the 
rest.)
   
   # 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.
   
   🤖 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: [email protected]

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

Reply via email to