[
https://issues.apache.org/jira/browse/CAMEL-27112?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27112:
--------------------------------
Description:
FileIdempotentRepository and FileStateRepository keep their data in a file, but
they take that file only as a java.io.File (setFileStore(File), and the static
factory methods). When the repository is declared as a bean in YAML, in
properties or in a low-code tool, the user has a file name, and wants to give
it as a plain string. That does not work today.
*Reproducer* (Camel JBang 4.24.0-SNAPSHOT):
{code:yaml}
- beans:
- name: readFiles
type:
"#class:org.apache.camel.support.processor.idempotent.FileIdempotentRepository"
properties:
fileStore: "/var/data/read-files.dat"
- route:
from:
uri:
"file:/var/data/in?noop=true&idempotent=true&idempotentRepository=#bean:readFiles"
steps:
- log: "${header.CamelFileName}"
{code}
fails with:
{noformat}
Error binding property (fileStore=/var/data/read-files.dat) ...
NoTypeConversionAvailableException: No type converter available to convert from
type: java.lang.String to the required type: java.io.File
{noformat}
The same happens with camel.beans.readFiles.fileStore =
/var/data/read-files.dat.
Today the only working form is fileStore:
"#class:java.io.File('/var/data/read-files.dat')". With it, the files are not
read again after a restart, and a new file is. That form asks the user to know
the java.io.File API, which people do not expect when they only want to name a
file.
*Suggestion:* let both repositories take the file name as a plain String:
* a String setter (for example an overloaded setFileStore(String), or
setFileName(String));
* String variants of the static factory methods, such as
fileIdempotentRepository(String fileName).
A general String to File type converter is not wanted. It would also apply to
message bodies, where a String is the content of a file, not its name, and
people would confuse the two.
*Use case:* the FTP, FTPS and SFTP source Kamelets of camel-kamelets read every
file again after a restart, unless the files are moved or deleted
(apache/camel-kamelets#3170, #3178). With this change, a user could declare the
repository in YAML with a plain file name, and pass the bean name to the
Kamelet.
_Claude Code on behalf of Claus Ibsen_
was:
FileIdempotentRepository keeps the keys in a file, which makes it the usual
choice for a file or FTP consumer that must not read the same files again after
a restart. It cannot be configured as a bean from properties or from YAML
beans, because its only file setter is setFileStore(java.io.File) and Camel has
no conversion from String to File (IOConverter converts a Path to a File, not a
String):
{noformat}
camel.beans.readFiles =
#class:org.apache.camel.support.processor.idempotent.FileIdempotentRepository
camel.beans.readFiles.fileStore = /var/data/read-files.dat
{noformat}
fails with:
{noformat}
No type converter available to convert from type: java.lang.String to the
required type: java.io.File
{noformat}
The same happens with a YAML bean with properties: fileStore:
/var/data/read-files.dat. The only working form is
camel.beans.readFiles.fileStore =
#class:java.io.File('/var/data/read-files.dat').
Two more paths do not help either:
* Inline in an endpoint parameter,
idempotentRepository=#class:...FileIdempotentRepository#fileIdempotentRepository('/path')
loses the factory method, apparently cut at the #, so the no-argument
constructor runs.
* That constructor leaves fileStore null, and doStart then fails with
"fileStore must be specified" instead of falling back to memory.
Suggestion: add a String setter, such as setFilePath(String) or
setFileStoreName(String), so that the repository can be configured from plain
values. A String to File type converter is not wanted: it would apply to
message bodies as well.
Use case: the FTP and SFTP Kamelets of camel-kamelets could then offer a
persistent idempotent repository bound by the user, instead of re-reading all
files after a restart (apache/camel-kamelets#3170, where "move after read" was
added for now, apache/camel-kamelets#3178).
_Claude Code on behalf of Claus Ibsen_
Summary: FileIdempotentRepository and FileStateRepository: accept the
file name as a plain String, for YAML and low-code beans (was:
FileIdempotentRepository cannot be configured from properties or YAML beans:
fileStore is a File and there is no String setter)
> FileIdempotentRepository and FileStateRepository: accept the file name as a
> plain String, for YAML and low-code beans
> ---------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27112
> URL: https://issues.apache.org/jira/browse/CAMEL-27112
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Reporter: Claus Ibsen
> Priority: Major
>
> FileIdempotentRepository and FileStateRepository keep their data in a file,
> but they take that file only as a java.io.File (setFileStore(File), and the
> static factory methods). When the repository is declared as a bean in YAML,
> in properties or in a low-code tool, the user has a file name, and wants to
> give it as a plain string. That does not work today.
> *Reproducer* (Camel JBang 4.24.0-SNAPSHOT):
> {code:yaml}
> - beans:
> - name: readFiles
> type:
> "#class:org.apache.camel.support.processor.idempotent.FileIdempotentRepository"
> properties:
> fileStore: "/var/data/read-files.dat"
> - route:
> from:
> uri:
> "file:/var/data/in?noop=true&idempotent=true&idempotentRepository=#bean:readFiles"
> steps:
> - log: "${header.CamelFileName}"
> {code}
> fails with:
> {noformat}
> Error binding property (fileStore=/var/data/read-files.dat) ...
> NoTypeConversionAvailableException: No type converter available to convert
> from type: java.lang.String to the required type: java.io.File
> {noformat}
> The same happens with camel.beans.readFiles.fileStore =
> /var/data/read-files.dat.
> Today the only working form is fileStore:
> "#class:java.io.File('/var/data/read-files.dat')". With it, the files are not
> read again after a restart, and a new file is. That form asks the user to
> know the java.io.File API, which people do not expect when they only want to
> name a file.
> *Suggestion:* let both repositories take the file name as a plain String:
> * a String setter (for example an overloaded setFileStore(String), or
> setFileName(String));
> * String variants of the static factory methods, such as
> fileIdempotentRepository(String fileName).
> A general String to File type converter is not wanted. It would also apply to
> message bodies, where a String is the content of a file, not its name, and
> people would confuse the two.
> *Use case:* the FTP, FTPS and SFTP source Kamelets of camel-kamelets read
> every file again after a restart, unless the files are moved or deleted
> (apache/camel-kamelets#3170, #3178). With this change, a user could declare
> the repository in YAML with a plain file name, and pass the bean name to the
> Kamelet.
> _Claude Code on behalf of Claus Ibsen_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)