stinger
stinger

Reputation: 4136

Apache Camel set file extension

I'm getting xml listings from HTTP POST body and then try to save it as XML document on filesystem. Unfortunately, Camel do not automatically provide file extension, and file is saved without it, so I cannot open it in my XML-viewer. Also, I want to preserve auto-generated file names (like ID-my_PC_name-some_strange_numbers) to avoid file overriding or data loss. After reading articles about Camel Simple language still no luck. Any help appreciated. This is my configuration:

.from("jetty:http://localhost:4422/input")
      .to("direct:fileCopy");

 .from("direct:fileCopy")
       //here I want to set file extension to .xml
       .to("file:D:/inprogress")
       .log("Incoming file saved to Inprogress directory");

Upvotes: 1

Views: 2880

Answers (1)

Akash Yadav
Akash Yadav

Reputation: 2421

You can use the option filename to set the pattern of the file that you want to generate.

.from("direct:fileCopy")
       .to("file:D:/inprogress?filename=mydata-${date:now:yyyyMMdd}.xml
")

will generate a file mydata-20150303.xml

if you want to use the message id , which is the unique id on exchange you can

.from("direct:fileCopy")
           .to("file:D:/inprogress?filename=mydata-${id}.xml
    ") 

will generate a file mydata-SOME_RANDOM_ALPHANUMERIC_ID.xml

Apache Camel File Copy

Upvotes: 4

Related Questions