Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
2.9.2
-
None
-
windows
-
Patch Available
-
Unknown
Description
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