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

   Fixes [CAMEL-26193](https://issues.apache.org/jira/browse/CAMEL-26193).
   
   ### A body that does not convert to InputStream was printed as null data
   
   **What was wrong:** `PrinterProducer.process` converted the body with the 
non-mandatory
   `getTypeConverter().convertTo(InputStream.class, body)`. For a `Map`, a 
POJO, a number or a null body the stream was
   null, and the producer still submitted a print job with that null data. 
Camel raised no error.
   
   **What changed:** the producer reads the body with 
`exchange.getIn().getMandatoryBody(InputStream.class)`. Such a body
   now fails the exchange with an `InvalidPayloadException`, and no print job 
is created. Text, bytes, a stream and a file
   print as before.
   
   Side effect of the same line: the conversion now gets the exchange, so a 
text body is encoded in the charset of the
   exchange (`Exchange.CHARSET_NAME`). Before, the exchange was not passed and 
the JVM default charset was always used.
   
   ### Tests
   
   New `PrinterProducerBodyTest` runs the producer on a mocked `PrintService` 
(no print service lookup, so nothing reaches
   a real printer):
   - a `Map`, a POJO, a number and a null body fail with 
`InvalidPayloadException` and create no print job;
   - text, bytes and a stream are printed with the right bytes;
   - a text body uses the charset of the exchange.
   
   Without the fix, the 4 unsupported-body cases and the charset test fail (5 
of 8). With the fix, the module passes:
   19 tests, 0 failures, 5 skipped (the existing `@Disabled` tests).
   
   ### Docs and generated files
   
   - The `@BodyTypes` text of the endpoint said the print job gets no data; it 
now says such a body fails with an
     `InvalidPayloadException`. Regenerated `lpr.json` in the component and in 
`camel-catalog`.
   - Upgrade guide 4.24: new `camel-printer` entry, since a route that sent 
such a body now fails instead of continuing.
   
   ### Not changed
   
   - `PrinterProducer.print` still skips the job without an error when the 
print service reports that the doc flavor is
     not supported. That is a separate behaviour change, left for its own issue.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 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