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

Willem Jiang resolved CAMEL-5495.
---------------------------------

       Resolution: Fixed
    Fix Version/s: 2.11.0
                   2.10.1
                   2.9.3

Applied patch into trunk, camel-2.10.x and camel-2.9.x branches with thanks to 
Aki.
                
> file endpoints on windows without volume name in the path url not working in 
> some cases
> ---------------------------------------------------------------------------------------
>
>                 Key: CAMEL-5495
>                 URL: https://issues.apache.org/jira/browse/CAMEL-5495
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.9.2
>         Environment: windows
>            Reporter: Aki Yoshida
>            Assignee: Willem Jiang
>            Priority: Minor
>             Fix For: 2.9.3, 2.10.1, 2.11.0
>
>         Attachments: trunk-camel-5495.diff
>
>
> I am using file endpoints on Windows without the volume name just like the 
> normal unix based paths look.
> That means, I have something like  file:///tmp/file-in and 
> file:///tmp/file-out
> The funny thing that I noticed is that each endpoint itself works fine, but 
> when a route is set up from one to the other, it fails because there seems to 
> be an inconsistency in the way the windows path is handled in the 
> camel-core's file component.
> As mentioned, each file endpoint itself is working fine. For example, the 
> consumer file endpoint configured in a route
> from("file:///tmp/file-in").to("mock:test")
> works fine.
> Similarly, the produce file endpoint configured in a route
> from("direct:test").to("file:///tmp/file-out")
> works fine.
> But when a route is setup to connect these two file endpoints, the producer 
> endpoint fails to create the output file.
> Concretely, there is the following code in 
> GenericFileEndpoint.configureMessage that determines the file name.
>              String name = file.isAbsolute() ? file.getAbsoluteFilePath() : 
> file.getRelativeFilePath();
>             // skip leading endpoint configured directory
>             String endpointPath = getConfiguration().getDirectory() + 
> getFileSeparator();
> In this particular case, the name variable is set to 
> "C:\tmp\file-in\sample.xml" while the endpointPath variable is set to 
> "\tmp\file-in".
> So, the subsequent code to extract the file name part, shown below, fails to 
> match the path.
>             if (ObjectHelper.isNotEmpty(endpointPath) && 
> name.startsWith(endpointPath)) {
>                 name = ObjectHelper.after(name, endpointPath);
>             }
> As a result, the file name is not extracted as "sample.xml" but remain 
> unchanged as "C:\tmp\file-in\sample.xml".
> Consequently, when the file producer endpoint tries to write this file in the 
> file system, it tries to write a file as 
> "/tmp/file-out/C:\tmp\file-in\sample.xml", resulting in an error.
> I modified FileComponent and FileEndpoint so that the endpoint path is stored 
> correctly in this case to make the above extraction code find the file name 
> part correctly.
> Attached is this proposed patch and a test case which runs on windows and on 
> non-windows but this issue can only be demonstrated under windows.
> testRouteToFileOnly and testRouteFromFileOnly work without this patch while 
> testRouteFileToFile fails without this patch on windows.
> Thanks for looking into this issue.
> Regards, Aki

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to