Set file path by Path.getFileName() for camel-file causes NoSuchFileException

Solution Verified - Updated -

Issue

This code works with RHBAC 4.4 but does not work with RHBAC 4.8.

    @Override
    public void configure() {
        from("timer:hello?repeatCount=1").routeId("hello")
        .setBody(constant("Hello World"))
        .process(exchange -> {
            Path path = Paths.get("/tmp/sample.txt");
            exchange.setProperty("fileName", path.getFileName());
        })
        .toD("file:/tmp/?fileName=${exchangeProperty.fileName}}&noop=true&idempotent=false")
        .log("done");
    }
Caused by: java.nio.file.NoSuchFileException: sample.txt
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92) ~[na:na]
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) ~[na:na]
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[na:na]
        at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218) ~[na:na]
        at java.base/java.nio.file.Files.newByteChannel(Files.java:380) ~[na:na]
        at java.base/java.nio.file.Files.newByteChannel(Files.java:432) ~[na:na]
        at java.base/java.nio.file.Files.readAllBytes(Files.java:3288) ~[na:na]
        at java.base/java.nio.file.Files.readString(Files.java:3366) ~[na:na]
        at org.apache.camel.converter.IOConverter.toString(IOConverter.java:180) ~[camel-base-4.8.0.redhat-00017.jar:4.8.0.redhat-00017]

Environment

  • Red Hat Build of Apache Camel
    • 4.8

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content