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

   # Description
   
   [CAMEL-27614](https://issues.apache.org/jira/browse/CAMEL-27614)
   
   The ticket lists six problems of camel-printer that came up while the option 
descriptions were written for CAMEL-23832 (#30950). I checked each one against 
main. Five are fixed here, one is left as it is.
   
   Fixed:
   1. **sendToPrinter=false without mimeType failed with a 
NullPointerException.** The AUTOSENSE default went to a local variable only, so 
the mime type that the producer passes on for the file name stayed null. The 
`flavor` and `mimeType` fields now hold their defaults, and the URI parsing 
only overwrites them when the option is set.
   2. **An unknown flavor or mimeType printed as 
`DocFlavor.BYTE_ARRAY.AUTOSENSE`.** The endpoint now fails to be created with 
an `IllegalArgumentException` that lists the accepted values, as an unknown 
`mediaSize` already does. This covers a misspelled value and a pair that names 
no doc flavor, such as the default flavor `DocFlavor.BYTE_ARRAY` with 
`mimeType=TEXT_PLAIN`. While checking this I found that `TEXT_HTML_UTF_8` and 
`TEXT_HTML` compared the mime type with `TEXT_HTML_UTF_16BE` (copy and paste), 
so both selected the text/plain doc flavor. They now select text/html.
   3. **The SERVICE_FORMATTED doc flavors got an InputStream as print data.** 
With `mimeType` `PAGEABLE`, `PRINTABLE` or `RENDERABLE_IMAGE`, the producer now 
converts the body to `Pageable`, `Printable` or `RenderableImage` (the 
representation class of the doc flavor) and passes that object as the print 
data. With `sendToPrinter=false` the body is still written to a file as bytes, 
as before, so that mode does not change.
   4. **sendToPrinter=false failed when `./target` did not exist.** The 
directory is now created when it is missing. I did not add an option for it, to 
keep the change small.
   5. **flavor and mimeType had no defaultValue.** They now have 
`DocFlavor.BYTE_ARRAY` and `AUTOSENSE`.
   
   Not changed:
   6. **The port path parameter.** #30950 already says in the port description 
that the producer does not use it. Deprecating the path parameter would change 
the endpoint syntax for a value that only shows up in the service location, so 
I left it.
   
   Behaviour changes are in the 4.24 upgrade guide: an endpoint with an unknown 
flavor or mimeType, or a pair without a doc flavor, now fails at startup; 
`TEXT_HTML_UTF_8` and `TEXT_HTML` select text/html; the three SERVICE_FORMATTED 
mime types print the body object.
   
   This touches the same lines as #30950 (the `@UriParam` of `flavor` and 
`mimeType`, and the generated files). Whichever is merged second needs a small 
rebase. The description of `flavor` in #30950 says that an unknown combination 
selects `DocFlavor.BYTE_ARRAY.AUTOSENSE`; with this change it fails instead.
   
   Tests (new, unit tests with a mocked `PrintService`, no printer needed):
   - `PrinterDocFlavorOptionsTest`: sendToPrinter=false without mimeType writes 
the document and keeps the defaults; unknown mimeType, unknown flavor, and two 
pairs without a doc flavor fail the endpoint; TEXT_HTML_UTF_8 and TEXT_HTML 
select text/html (with two text/plain controls); a `Printable` body is the 
print data of the PRINTABLE doc flavor. Against the main sources 8 of the 10 
fail (NullPointerException, nothing thrown, text/plain selected, 
InvalidPayloadException); the 2 text/plain controls pass.
   - `PrinterOperationsOutputDirectoryTest`: a missing output directory is 
created. It uses a package-private setter for the directory, so it does not 
compile against main.
   
   Results (offline, module build of camel-printer, test phase): 41 tests run, 
0 failures, 0 errors, 5 skipped (the skipped ones are skipped on main too). The 
two new test classes pass 5 runs in a row.
   
   Generated files: `lpr.json` of the component and its catalog copy, and the 
javadoc of `flavor` and `mimeType` in `PrinterEndpointBuilderFactory` (the 
`Default:` lines).
   
   # 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): 
[CAMEL-27614](https://issues.apache.org/jira/browse/CAMEL-27614).
   
   # 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 camel-printer and ran its unit tests, and committed the 
regenerated component JSON. The catalog copy and the endpoint DSL lines were 
updated to match it, as an offline build of those modules was not possible 
here. 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: [email protected]

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

Reply via email to