[ 
https://issues.apache.org/jira/browse/CAMEL-26639?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Salvatore Mongiardo updated CAMEL-26639:
----------------------------------------
    Description: 
h2. Summary

On Windows, when a Camel {{file:}} URI contains an absolute path with 
backslashes (e.g. {{file:C:\Users\...\target}}), the file consumer starts 
successfully but never polls any files. No exceptions are logged, no files are 
processed - completely silent failure.

h2. Root Cause

On Windows, {{Paths.get("target").toAbsolutePath().toString()}} returns paths 
with backslashes. When interpolated into a Camel {{file:}} URI:

# {{UnsafeUriCharactersEncoder.encode()}} encodes backslash as {{%5C}}
# The route starts but the file poller silently fails to detect the directory
# Route log shows {{file://C:%5CUsers%5C...}} confirming the encoding issue

On Linux/macOS this never happens because {{toAbsolutePath()}} always uses 
forward slashes.

h2. Steps to Reproduce

{code:java}
String directory = Paths.get("target").toAbsolutePath().toString();
// On Windows: C:\Users\test\target

fromF("file:%s?fileName=%s", directory, "test.txt")
    .to("log:result");
{code}

h2. Fix

*Camel level (upstream):* Normalize backslashes to forward slashes in 
{{FileComponent.buildFileEndpoint()}} before creating the {{File}} object. 
Java's {{File}} class handles forward slashes on all platforms.

{code:java}
remaining = remaining.replace('\\', '/');
{code}

PR: https://github.com/smongiar/camel/tree/fix/file-component-windows-backslash

*Test level (tnb-tests workaround):* Added {{.replace('\\', '/')}} to path 
strings before constructing Camel file URIs in PGPITCase, FileWatchITCase, 
AzureStorageBlobITCase, and FhirExampleITCase. This matches the pattern already 
used in ~9 other tests in the codebase.

h2. Environment

* Windows Server 2019/2025
* JDK 21
* Camel 4.22.x (also affects main)

  was:
h2. Summary

On Windows, when a Camel file: URI contains an absolute path with backslashes 
(e.g. {{file:C:\\Users\\...\\target}}), the file consumer starts successfully 
but never polls any files. No exceptions are logged, no files are processed - 
completely silent failure.

h2. Root Cause

When {{Paths.get("target").toAbsolutePath().toString()}} is used on Windows, it 
returns a path with backslashes (e.g. {{C:\\Users\\...\\target}}). When this is 
interpolated into a Camel {{file:}} URI:

# {{UnsafeUriCharactersEncoder.encode()}} encodes backslash as %5C
# {{URI.getSchemeSpecificPart()}} decodes it back
# The route internal URI representation retains the encoded form
# The file consumer display name shows {{file://C:%5CUsers%5C...}}
# The file poller silently fails to detect files in the directory

On Linux/macOS this never happens because toAbsolutePath() always uses forward 
slashes.

h2. Steps to Reproduce

{code:java}
String directory = Paths.get("target").toAbsolutePath().toString();
// On Windows: C:\Users\test\target

fromF("file:%s?fileName=%s", directory, "test.txt")
    .to("log:result");
{code}

The route starts and logs:
{code}
Started route1 (file://C:%5CUsers%5Ctest%5Ctarget)
{code}

But no files are ever polled.

h2. Expected Behavior

The file consumer should normalize backslashes to forward slashes and poll the 
directory correctly.

h2. Proposed Fix

Normalize backslashes to forward slashes in 
{{FileComponent.buildFileEndpoint()}} before creating the File object:

{code:java}
remaining = remaining.replace('\\', '/');
{code}

This is safe because Java File class handles forward slashes on all platforms.

h2. Environment

* Windows Server 2019/2025
* JDK 21
* Camel 4.22.x (also affects main)


> camel-file silently fails to poll files on Windows when URI uses absolute 
> path with backslashes
> -----------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26639
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26639
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-file
>            Reporter: Salvatore Mongiardo
>            Assignee: Salvatore Mongiardo
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to