[
https://issues.apache.org/jira/browse/CAMEL-18039?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17531933#comment-17531933
]
Karen Lease edited comment on CAMEL-18039 at 5/4/22 8:41 PM:
-------------------------------------------------------------
[~yasserzamani] The problem is with the fileName() property on your
pollEnrich. You are trying to evaluate the exchangeProperty "MyCsvFileName"
which you set to contain the file name when the file is generated. But the
pollEnrich doesn't have access to this exchange. Here is the code to check if
the polled file name matches the specified one:
{code:java}
if (endpoint.getFileName() != null) {
// create a dummy exchange as Exchange is needed for expression evaluation
Exchange dummy = endpoint.createExchange(file);
String result = evaluateFileExpression(dummy);
if (result != null) {
if (!name.equals(result)) {
return false;
}
}
} {code}
The dummy exchange does not have the property MyCsvFileName so result is null.
Because of this, all the normal files in the folder will be shown as matching.
Instead of matching on the exact file name, you could use an include filter
like
{code:java}
include("MY_.*\\.csv"){code}
By the way, in your route above, the messageTimestamp is always 0 as well, but
presumably in your actual use case, this is not true.
was (Author: klease78):
[~yasserzamani] The problem is with the fileName() property on your
pollEnrich. You are trying to evaluate the exchangeProperty "MyCsvFileName"
which you set to contain the file name when the file is generated. But the
pollEnrich doesn't have access to this exchange. Here is the code to check if
the polled file name matches the specified one:
{code:java}
if (endpoint.getFileName() != null) {
// create a dummy exchange as Exchange is needed for expression evaluation
Exchange dummy = endpoint.createExchange(file);
String result = evaluateFileExpression(dummy);
if (result != null) {
if (!name.equals(result)) {
return false;
}
}
} {code}
The dummy exchange does not have he property MyCsvFileName so result is null.
Because of this, all the normal files in the folder will be shown as matching.
Instead of matching on the exact file name, you could use an include filter
like
{code:java}
include("MY_.*\\.csv"){code}
By the way, in your route above, the messageTimestamp is always 0 as well, but
presumably in your actual use case, this is not true.
> endpoint-dsl - pollEnrich or file consumer polls file alphabetically despite
> specified fileName
> -----------------------------------------------------------------------------------------------
>
> Key: CAMEL-18039
> URL: https://issues.apache.org/jira/browse/CAMEL-18039
> Project: Camel
> Issue Type: Bug
> Components: camel-core, camel-file
> Affects Versions: 3.16.0
> Reporter: Yasser Zamani
> Priority: Minor
> Fix For: 3.17.0
>
>
> I have following route
> {code:java}
> private static final String FILE_PROPERTY_NAME = "MyCsvFileName";
> private static final String FILE_NAME = "${exchangeProperty." +
> FILE_PROPERTY_NAME + "}";
> private static final String FOLDER_NAME = ".";
> from("direct:MY_CSV").routeId("MY_CSV").
> setBody(constant(FIRST_LINE)).
> transform(body().append("\r\n")).
>
> setProperty(FILE_PROPERTY_NAME).simple("MY_${messageTimestamp}.csv").
> to(file(FOLDER_NAME).fileName(FILE_NAME)).
> .
> .
> .
> pollEnrich(file(FOLDER_NAME).fileName(FILE_NAME)).
> log("The CSV file ${header." + FILE_NAME_ONLY + "} generated.
> Now uploading it...").
> {code}
> that logs following line
> {quote}The CSV file azurite-blob.sh generated. Now uploading it...
> {quote}
> We eventually realized that pollEnrich or file consumer polls file
> alphabetically despite specified fileName.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)