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

   # Description
   
   [CAMEL-25218](https://issues.apache.org/jira/browse/CAMEL-25218)
   
   `JsonPathEngine.doRead` has a special case for a `GenericFile` with a 
charset (CAMEL-8905):
   
   ```java
   if (genericFile.getCharset() != null) {
       // special treatment for generic file with charset
       InputStream inputStream = new FileInputStream((File) 
genericFile.getFile());
       return JsonPath.using(configuration).parse(inputStream, 
genericFile.getCharset()).read(path);
   }
   ```
   
   The cast assumes the file consumer. The ftp and ftps consumers also set the 
endpoint `charset` on the `RemoteFile` they create 
(`FtpConsumer.asRemoteFile`), but its file is an `FTPFile` and the content is 
in the body, so every jsonpath expression on such a message fails with 
`ClassCastException: class org.apache.commons.net.ftp.FTPFile cannot be cast to 
class java.io.File`, for example 
`from("ftp://host/inbox?charset=ISO-8859-1";).split().jsonpath("$.orders[*]")`. 
Without the charset option the same route works, but then a file in a charset 
other than UTF-8/16/32 is decoded wrongly.
   
   This change: a `java.io.File` is still opened with a `FileInputStream`; any 
other generic file is read through the `GenericFile` type converter (the 
downloaded content, loaded through the binding if needed). Both are parsed in 
the file charset as before. Local files behave exactly as before.
   
   Tests:
   - `JsonPathRemoteGenericFileCharsetTest` (new): a `GenericFile` whose file 
is not a `java.io.File` (a stand-in for `FTPFile`, camel-jsonpath does not 
depend on camel-ftp), with the JSON in the body, charset UTF-8 and ISO-8859-1; 
control: the same without a charset.
   - Without the change, the two tests with a charset fail with 
`ClassCastException`; the control passes.
   - With the change, all camel-jsonpath tests pass: 133 tests, 0 failures.
   
   # 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 the affected module, 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: [email protected]

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

Reply via email to