[
https://issues.apache.org/jira/browse/CAMEL-24422?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andrea Cosentino updated CAMEL-24422:
-------------------------------------
Fix Version/s: 4.18.5
> camel-docling: make message body input-source interpretation explicit and
> configurable
> --------------------------------------------------------------------------------------
>
> Key: CAMEL-24422
> URL: https://issues.apache.org/jira/browse/CAMEL-24422
> Project: Camel
> Issue Type: Improvement
> Components: camel-docling
> Affects Versions: 4.22.0
> Reporter: Andrea Cosentino
> Assignee: Andrea Cosentino
> Priority: Major
> Fix For: 4.22.1, 4.23.0, 4.18.5
>
>
> {{DoclingProducer.getInputPath()}} decides what a {{String}} message body
> _means_ by
> inspecting its prefix:
> * starts with {{http://}} or {{https://}} -> treated as a remote URL and
> handed to the
> docling CLI or to {{HttpSource}}
> * starts with {{/}}, or contains {{\}} -> treated as a local filesystem path
> and read
> * otherwise -> treated as document content and written to a temp file
> The mode is chosen implicitly and the route author cannot influence it. A
> route that means
> "convert whatever text arrives in the body" silently switches to reading a
> file when that
> text happens to begin with {{/}}, and to fetching a remote resource when it
> happens to
> begin with {{http://}}. No endpoint option pins the component to a single
> interpretation.
> There are three things to address here.
> h2. 1. No way to express intent
> Add endpoint options so a route can state what the body is, instead of
> relying on prefix
> sniffing. Suggested shape: {{allowUrlSource}} and {{allowFilePathSource}}, or
> a single
> {{inputSourceMode}} enum ({{AUTO}} / {{CONTENT}} / {{PATH}}), plus an optional
> base-directory option that bounds the file-path mode to a configured root.
> h2. 2. Duplicated prefix logic
> The same {{startsWith("http://") || startsWith("https://")}} branch is
> implemented
> independently in four places:
> || Method || Declared at || Prefix check ||
> | {{DoclingProducer#getInputPath}} | 1711 | 1726 |
> | {{DoclingProducer#addSourceToRequest}} | 1523 | 1525 |
> | {{DoclingProducer#addSourceToChunkRequest}} | 625 | 628 |
> | {{DoclingProducer#extractMetadataUsingApi}} | 650 | 670 |
> Any new handling has to be added to every one of them, which is how they
> drift apart.
> The classification belongs in one place -- {{getInputPath()}} -- so that the
> downstream
> helpers receive an already-classified source rather than re-deriving it. Note
> that
> {{extractMetadataUsingApi}} spells the condition negatively, which makes the
> set harder
> to keep aligned by inspection.
> h2. 3. validateFileSize() does nothing for a path that does not exist
> {{validateFileSize()}} (line 1816) is wrapped in {{if (Files.exists(path))}},
> so a path
> that resolves to nothing, or to a pseudo-file that reports size 0, passes
> without a check
> while the call site reads as though one happened. Either make the outcome
> explicit (fail
> when a path cannot be sized) or rename the method so its partial nature is
> visible where
> it is called.
> h2. Batch operations have the same shape
> {{extractDocumentList()}} (line 1049) applies the same implicit rule for the
> batch
> operations: a {{String}} body is used either as a directory to scan via
> {{new File(path).listFiles()}} or as a single file path, again with no way
> for the route
> to say which was intended. Whatever mechanism is added should cover this path
> too.
> h2. Documentation and upgrade guide
> The component documentation currently describes the accepted body types as
> "{{String}} - File path or document content" and does not mention the URL
> mode at all, so
> {{docling-component.adoc}} needs to be updated to describe the resulting
> contract.
> If the defaults change as part of this, the change needs an entry in
> {{docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc}}.
> h2. Blast radius
> Tightening the {{String}} branch does not affect the documented
> {{from("file:...").to("docling:...")}} flow: camel-file delivers a
> {{GenericFile}}/{{WrappedFile}} body, which {{getInputPath()}} unwraps into
> the {{File}}
> branch rather than the {{String}} branch.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)